2 * <unistd.h> wrapper functions.
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004 Jonathan Pryor
12 #endif /* ndef _GNU_SOURCE */
14 #include <sys/types.h>
21 #include <glib/gtypes.h>
29 Mono_Posix_Syscall_lseek (gint32 fd, mph_off_t offset, gint32 whence)
32 mph_return_if_off_t_overflow (offset);
33 if (Mono_Posix_FromSeekFlags (whence, &_whence) == -1)
37 return lseek64 (fd, offset, whence);
39 return lseek (fd, offset, whence);
44 Mono_Posix_Syscall_read (gint32 fd, void *buf, mph_size_t count)
46 mph_return_if_size_t_overflow (count);
47 return read (fd, buf, (size_t) count);
51 Mono_Posix_Syscall_write (gint32 fd, const void *buf, mph_size_t count)
53 mph_return_if_size_t_overflow (count);
54 return write (fd, buf, (size_t) count);
58 Mono_Posix_Syscall_pread (gint32 fd, void *buf, mph_size_t count, mph_off_t offset)
60 mph_return_if_size_t_overflow (count);
61 mph_return_if_off_t_overflow (offset);
63 return pread64 (fd, buf, (size_t) count, offset);
65 return pread (fd, buf, (size_t) count, (off_t) offset);
70 Mono_Posix_Syscall_pwrite (gint32 fd, const void *buf, mph_size_t count, mph_off_t offset)
72 mph_return_if_size_t_overflow (count);
73 mph_return_if_off_t_overflow (offset);
75 return pwrite64 (fd, buf, (size_t) count, offset);
77 return pwrite (fd, buf, (size_t) count, (off_t) offset);
82 Mono_Posix_Syscall_pipe (gint32 *reading, gint32 *writing)
84 int filedes[2] = {-1, -1};
87 if (reading == NULL || writing == NULL) {
94 *reading = filedes[0];
95 *writing = filedes[1];
100 Mono_Posix_Syscall_getcwd (char *buf, mph_size_t size)
102 mph_return_val_if_size_t_overflow (size, NULL);
103 return getcwd (buf, (size_t) size);
107 Mono_Posix_Syscall_fpathconf (int filedes, int name)
109 if (Mono_Posix_FromPathConf (name, &name) == -1)
111 return fpathconf (filedes, name);
115 Mono_Posix_Syscall_pathconf (char *path, int name)
117 if (Mono_Posix_FromPathConf (name, &name) == -1)
119 return pathconf (path, name);
123 Mono_Posix_Syscall_sysconf (int name)
125 if (Mono_Posix_FromSysConf (name, &name) == -1)
127 return sysconf (name);
131 Mono_Posix_Syscall_confstr (int name, char *buf, mph_size_t len)
133 mph_return_if_size_t_overflow (len);
134 if (Mono_Posix_FromConfStr (name, &name) == -1)
136 return confstr (name, buf, (size_t) len);
140 Mono_Posix_Syscall_ttyname_r (int fd, char *buf, mph_size_t len)
142 mph_return_if_size_t_overflow (len);
143 return ttyname_r (fd, buf, (size_t) len);
147 Mono_Posix_Syscall_readlink (const char *path, char *buf, mph_size_t len)
149 mph_return_if_size_t_overflow (len);
150 return readlink (path, buf, (size_t) len);
154 Mono_Posix_Syscall_getlogin_r (char *buf, mph_size_t len)
156 mph_return_if_size_t_overflow (len);
157 return getlogin_r (buf, (size_t) len);
161 Mono_Posix_Syscall_gethostname (char *buf, mph_size_t len)
163 mph_return_if_size_t_overflow (len);
164 return gethostname (buf, (size_t) len);
168 Mono_Posix_Syscall_sethostname (const char *name, mph_size_t len)
170 mph_return_if_size_t_overflow (len);
171 return sethostname (name, (size_t) len);
175 Mono_Posix_Syscall_gethostid (void)
181 Mono_Posix_Syscall_sethostid (gint64 hostid)
183 mph_return_if_long_overflow (hostid);
184 return sethostid ((long) hostid);
188 Mono_Posix_Syscall_getdomainname (char *name, mph_size_t len)
190 mph_return_if_size_t_overflow (len);
191 return getdomainname (name, (size_t) len);
195 Mono_Posix_Syscall_setdomainname (const char *name, mph_size_t len)
197 mph_return_if_size_t_overflow (len);
198 return setdomainname (name, (size_t) len);
202 Mono_Posix_Syscall_truncate (const char *path, mph_off_t length)
204 mph_return_if_off_t_overflow (length);
205 #ifdef MPH_USE_64_API
206 return truncate64 (path, length);
208 return truncate (path, (off_t) length);
213 Mono_Posix_Syscall_ftruncate (int fd, mph_off_t length)
215 mph_return_if_off_t_overflow (length);
216 #ifdef MPH_USE_64_API
217 return ftruncate64 (fd, length);
219 return ftruncate (fd, (off_t) length);
224 Mono_Posix_Syscall_lockf (int fd, int cmd, mph_off_t len)
226 mph_return_if_off_t_overflow (len);
227 if (Mono_Posix_FromLockFlags (cmd, &cmd) == -1)
229 #ifdef MPH_USE_64_API
230 return lockf64 (fd, cmd, len);
232 return lockf (fd, cmd, (off_t) len);
237 Mono_Posix_Syscall_swab (void *from, void *to, mph_ssize_t n)
239 if (n > LONG_MAX || n < LONG_MAX)
241 swab (from, to, (ssize_t) n);