[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / support / sys-uio.c
blobdbbb54ed821557fcb93e57859e365715aefeaa3c
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 <config.h>
15 #if defined(TARGET_MACH)
16 /* So we can use the declaration of preadv () */
17 #define _DARWIN_C_SOURCE
18 #endif
20 #include "sys-uio.h"
22 #include <sys/uio.h>
24 #include "map.h"
25 #include "mph.h"
27 G_BEGIN_DECLS
29 struct iovec*
30 _mph_from_iovec_array (struct Mono_Posix_Iovec *iov, gint32 iovcnt)
32 struct iovec* v;
33 gint32 i;
35 if (iovcnt < 0) {
36 errno = EINVAL;
37 return NULL;
40 v = malloc (iovcnt * sizeof (struct iovec));
41 if (!v) {
42 return NULL;
45 for (i = 0; i < iovcnt; i++) {
46 if (Mono_Posix_FromIovec (&iov[i], &v[i]) != 0) {
47 free (v);
48 return NULL;
52 return v;
55 #ifdef HAVE_READV
56 gint64
57 Mono_Posix_Syscall_readv (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovcnt)
59 struct iovec* v;
60 gint64 res;
62 v = _mph_from_iovec_array (iov, iovcnt);
63 if (!v) {
64 return -1;
67 res = readv(dirfd, v, iovcnt);
68 free (v);
69 return res;
71 #endif /* def HAVE_READV */
73 #ifdef HAVE_WRITEV
74 gint64
75 Mono_Posix_Syscall_writev (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovcnt)
77 struct iovec* v;
78 gint64 res;
80 v = _mph_from_iovec_array (iov, iovcnt);
81 if (!v) {
82 return -1;
85 res = writev (dirfd, v, iovcnt);
86 free (v);
87 return res;
89 #endif /* def HAVE_WRITEV */
91 #ifdef HAVE_PREADV
92 gint64
93 Mono_Posix_Syscall_preadv (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovcnt, gint64 off)
95 struct iovec* v;
96 gint64 res;
98 mph_return_if_off_t_overflow (off);
100 v = _mph_from_iovec_array (iov, iovcnt);
101 if (!v) {
102 return -1;
105 res = preadv (dirfd, v, iovcnt, (off_t) off);
106 free (v);
107 return res;
109 #endif /* def HAVE_PREADV */
111 #ifdef HAVE_PWRITEV
112 gint64
113 Mono_Posix_Syscall_pwritev (int dirfd, struct Mono_Posix_Iovec *iov, gint32 iovcnt, gint64 off)
115 struct iovec* v;
116 gint64 res;
118 mph_return_if_off_t_overflow (off);
120 v = _mph_from_iovec_array (iov, iovcnt);
121 if (!v) {
122 return -1;
125 res = pwritev (dirfd, v, iovcnt, (off_t) off);
126 free (v);
127 return res;
129 #endif /* def HAVE_PWRITEV */
133 * vim: noexpandtab