Revert "[aot] Improve error checking when setting up class vtable."
[mono-project.git] / support / sys-uio.c
blobf6b80e0d740ad70b0c2d6b937ed634fb3835718d
1 /*
2 * <sys/uio.h> wrapper functions.
4 * Authors:
5 * Steffen Kiess (s-kiess@web.de)
7 * Copyright (C) 2012 Steffen Kiess
8 */
10 #ifndef _GNU_SOURCE
11 #define _GNU_SOURCE
12 #endif /* ndef _GNU_SOURCE */
14 #include <sys/uio.h>
16 #include "map.h"
17 #include "mph.h"
19 G_BEGIN_DECLS
21 static struct iovec*
22 from_iovec (struct Mono_Posix_Iovec *iov, gint32 iovcnt)
24 struct iovec* v;
25 gint32 i;
27 if (iovcnt < 0) {
28 errno = EINVAL;
29 return NULL;
32 v = malloc (iovcnt * sizeof (struct iovec));
33 if (!v) {
34 return NULL;
37 for (i = 0; i < iovcnt; i++) {
38 if (Mono_Posix_FromIovec (&iov[i], &v[i]) != 0) {
39 free (v);
40 return NULL;
44 return v;
47 #ifdef HAVE_READV
48 gint64
49 Mono_Posix_Syscall_readv (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovcnt)
51 struct iovec* v;
52 gint64 res;
54 v = from_iovec (iov, iovcnt);
55 if (!v) {
56 return -1;
59 res = readv(dirfd, v, iovcnt);
60 free (v);
61 return res;
63 #endif /* def HAVE_READV */
65 #ifdef HAVE_WRITEV
66 gint64
67 Mono_Posix_Syscall_writev (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovcnt)
69 struct iovec* v;
70 gint64 res;
72 v = from_iovec (iov, iovcnt);
73 if (!v) {
74 return -1;
77 res = writev (dirfd, v, iovcnt);
78 free (v);
79 return res;
81 #endif /* def HAVE_WRITEV */
83 #ifdef HAVE_PREADV
84 gint64
85 Mono_Posix_Syscall_preadv (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovcnt, gint64 off)
87 struct iovec* v;
88 gint64 res;
90 mph_return_if_off_t_overflow (off);
92 v = from_iovec (iov, iovcnt);
93 if (!v) {
94 return -1;
97 res = preadv (dirfd, v, iovcnt, (off_t) off);
98 free (v);
99 return res;
101 #endif /* def HAVE_PREADV */
103 #ifdef HAVE_PWRITEV
104 gint64
105 Mono_Posix_Syscall_pwritev (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovcnt, gint64 off)
107 struct iovec* v;
108 gint64 res;
110 mph_return_if_off_t_overflow (off);
112 v = from_iovec (iov, iovcnt);
113 if (!v) {
114 return -1;
117 res = pwritev (dirfd, v, iovcnt, (off_t) off);
118 free (v);
119 return res;
121 #endif /* def HAVE_PWRITEV */
125 * vim: noexpandtab