[sgen] Remove some redundancy with nursery section
[mono-project.git] / support / sys-uio.c
blob53e162f9fdada02a7a334006b116f749a1475ac6
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 <sys/uio.h>
18 #include "map.h"
19 #include "mph.h"
21 G_BEGIN_DECLS
23 struct iovec*
24 _mph_from_iovec_array (struct Mono_Posix_Iovec *iov, gint32 iovcnt)
26 struct iovec* v;
27 gint32 i;
29 if (iovcnt < 0) {
30 errno = EINVAL;
31 return NULL;
34 v = malloc (iovcnt * sizeof (struct iovec));
35 if (!v) {
36 return NULL;
39 for (i = 0; i < iovcnt; i++) {
40 if (Mono_Posix_FromIovec (&iov[i], &v[i]) != 0) {
41 free (v);
42 return NULL;
46 return v;
49 #ifdef HAVE_READV
50 gint64
51 Mono_Posix_Syscall_readv (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovcnt)
53 struct iovec* v;
54 gint64 res;
56 v = _mph_from_iovec_array (iov, iovcnt);
57 if (!v) {
58 return -1;
61 res = readv(dirfd, v, iovcnt);
62 free (v);
63 return res;
65 #endif /* def HAVE_READV */
67 #ifdef HAVE_WRITEV
68 gint64
69 Mono_Posix_Syscall_writev (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovcnt)
71 struct iovec* v;
72 gint64 res;
74 v = _mph_from_iovec_array (iov, iovcnt);
75 if (!v) {
76 return -1;
79 res = writev (dirfd, v, iovcnt);
80 free (v);
81 return res;
83 #endif /* def HAVE_WRITEV */
85 #ifdef HAVE_PREADV
86 gint64
87 Mono_Posix_Syscall_preadv (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovcnt, gint64 off)
89 struct iovec* v;
90 gint64 res;
92 mph_return_if_off_t_overflow (off);
94 v = _mph_from_iovec_array (iov, iovcnt);
95 if (!v) {
96 return -1;
99 res = preadv (dirfd, v, iovcnt, (off_t) off);
100 free (v);
101 return res;
103 #endif /* def HAVE_PREADV */
105 #ifdef HAVE_PWRITEV
106 gint64
107 Mono_Posix_Syscall_pwritev (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovcnt, gint64 off)
109 struct iovec* v;
110 gint64 res;
112 mph_return_if_off_t_overflow (off);
114 v = _mph_from_iovec_array (iov, iovcnt);
115 if (!v) {
116 return -1;
119 res = pwritev (dirfd, v, iovcnt, (off_t) off);
120 free (v);
121 return res;
123 #endif /* def HAVE_PWRITEV */
127 * vim: noexpandtab