2 * <unistd.h> wrapper functions.
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004-2006 Jonathan Pryor
14 #endif /* ndef _GNU_SOURCE */
16 #include <sys/types.h>
22 #include <string.h> /* for swab(3) on Mac OS X */
24 #include <netdb.h> /* for get/setdomainname */
26 * Yet more stuff in libc that isn't in headers.
27 * Python does the same thing we do here.
28 * see: bugs.python.org/issue18259
30 extern int sethostname(const char *, size_t);
31 extern int sethostid(long);
34 #include "mph.h" /* Don't remove or move after map.h! Works around issues with Android SDK unified headers */
40 Mono_Posix_Syscall_lseek (gint32 fd
, mph_off_t offset
, gint32 whence
)
42 mph_return_if_off_t_overflow (offset
);
44 return lseek (fd
, offset
, whence
);
48 Mono_Posix_Syscall_read (gint32 fd
, void *buf
, mph_size_t count
)
50 mph_return_if_size_t_overflow (count
);
51 return read (fd
, buf
, (size_t) count
);
55 Mono_Posix_Syscall_write (gint32 fd
, void *buf
, mph_size_t count
)
57 mph_return_if_size_t_overflow (count
);
58 return write (fd
, buf
, (size_t) count
);
62 Mono_Posix_Syscall_pread (gint32 fd
, void *buf
, mph_size_t count
, mph_off_t offset
)
64 mph_return_if_size_t_overflow (count
);
65 mph_return_if_off_t_overflow (offset
);
67 return pread (fd
, buf
, (size_t) count
, (off_t
) offset
);
71 Mono_Posix_Syscall_pwrite (gint32 fd
, void *buf
, mph_size_t count
, mph_off_t offset
)
73 mph_return_if_size_t_overflow (count
);
74 mph_return_if_off_t_overflow (offset
);
76 return pwrite (fd
, buf
, (size_t) count
, (off_t
) offset
);
80 Mono_Posix_Syscall_pipe (gint32
*reading
, gint32
*writing
)
82 int filedes
[2] = {-1, -1};
85 if (reading
== NULL
|| writing
== NULL
) {
92 *reading
= filedes
[0];
93 *writing
= filedes
[1];
98 Mono_Posix_Syscall_getcwd (char *buf
, mph_size_t size
)
100 mph_return_val_if_size_t_overflow (size
, NULL
);
101 return getcwd (buf
, (size_t) size
);
105 Mono_Posix_Syscall_fpathconf (int filedes
, int name
, int defaultError
)
107 errno
= defaultError
;
108 if (Mono_Posix_FromPathconfName (name
, &name
) == -1)
110 return fpathconf (filedes
, name
);
114 Mono_Posix_Syscall_pathconf (const char *path
, int name
, int defaultError
)
116 errno
= defaultError
;
117 if (Mono_Posix_FromPathconfName (name
, &name
) == -1)
119 return pathconf (path
, name
);
123 Mono_Posix_Syscall_sysconf (int name
, int defaultError
)
125 errno
= defaultError
;
126 if (Mono_Posix_FromSysconfName (name
, &name
) == -1)
128 return sysconf (name
);
133 Mono_Posix_Syscall_confstr (int name
, char *buf
, mph_size_t len
)
135 mph_return_if_size_t_overflow (len
);
136 if (Mono_Posix_FromConfstrName (name
, &name
) == -1)
138 return confstr (name
, buf
, (size_t) len
);
140 #endif /* def HAVE_CONFSTR */
142 #ifdef HAVE_TTYNAME_R
144 Mono_Posix_Syscall_ttyname_r (int fd
, char *buf
, mph_size_t len
)
146 mph_return_if_size_t_overflow (len
);
147 return ttyname_r (fd
, buf
, (size_t) len
);
149 #endif /* ndef HAVE_TTYNAME_R */
152 Mono_Posix_Syscall_readlink (const char *path
, unsigned char *buf
, mph_size_t len
)
155 mph_return_if_size_t_overflow (len
);
156 r
= readlink (path
, (char*) buf
, (size_t) len
);
157 if (r
>= 0 && r
< len
)
162 #ifdef HAVE_READLINKAT
164 Mono_Posix_Syscall_readlinkat (int dirfd
, const char *path
, unsigned char *buf
, mph_size_t len
)
167 mph_return_if_size_t_overflow (len
);
168 r
= readlinkat (dirfd
, path
, (char*) buf
, (size_t) len
);
169 if (r
>= 0 && r
< len
)
173 #endif /* def HAVE_READLINKAT */
177 Mono_Posix_Syscall_getlogin_r (char *buf
, mph_size_t len
)
179 mph_return_if_size_t_overflow (len
);
180 return getlogin_r (buf
, (size_t) len
);
182 #endif /* def HAVE_GETLOGIN_R */
185 Mono_Posix_Syscall_gethostname (char *buf
, mph_size_t len
)
187 mph_return_if_size_t_overflow (len
);
188 return gethostname (buf
, (size_t) len
);
193 Mono_Posix_Syscall_sethostname (const char *name
, mph_size_t len
)
195 mph_return_if_size_t_overflow (len
);
196 return sethostname (name
, (size_t) len
);
198 #endif /* def HAVE_SETHOSTNAME */
202 Mono_Posix_Syscall_gethostid (void)
206 #endif /* def HAVE_GETHOSTID */
208 #ifdef HAVE_SETHOSTID
210 Mono_Posix_Syscall_sethostid (gint64 hostid
)
212 mph_return_if_long_overflow (hostid
);
214 sethostid ((long) hostid
);
217 return sethostid ((long) hostid
);
220 #endif /* def HAVE_SETHOSTID */
222 #ifdef HAVE_GETDOMAINNAME
224 Mono_Posix_Syscall_getdomainname (char *name
, mph_size_t len
)
226 mph_return_if_size_t_overflow (len
);
227 return getdomainname (name
, (size_t) len
);
229 #endif /* def HAVE_GETDOMAINNAME */
231 #ifdef HAVE_SETDOMAINNAME
233 Mono_Posix_Syscall_setdomainname (const char *name
, mph_size_t len
)
235 mph_return_if_size_t_overflow (len
);
236 return setdomainname (name
, (size_t) len
);
238 #endif /* def HAVE_SETDOMAINNAME */
240 /* Android implements truncate, but doesn't declare it.
241 * Result is a warning during compilation, so skip it.
245 Mono_Posix_Syscall_truncate (const char *path
, mph_off_t length
)
247 mph_return_if_off_t_overflow (length
);
248 return truncate (path
, (off_t
) length
);
253 Mono_Posix_Syscall_ftruncate (int fd
, mph_off_t length
)
255 mph_return_if_off_t_overflow (length
);
256 return ftruncate (fd
, (off_t
) length
);
261 Mono_Posix_Syscall_lockf (int fd
, int cmd
, mph_off_t len
)
263 mph_return_if_off_t_overflow (len
);
264 if (Mono_Posix_FromLockfCommand (cmd
, &cmd
) == -1)
266 return lockf (fd
, cmd
, (off_t
) len
);
268 #endif /* def HAVE_LOCKF */
272 Mono_Posix_Syscall_swab (void *from
, void *to
, mph_ssize_t n
)
274 if (mph_have_long_overflow (n
))
276 swab (from
, to
, (ssize_t
) n
);
279 #endif /* def HAVE_SWAB */
281 #if HAVE_SETUSERSHELL
283 Mono_Posix_Syscall_setusershell (void)
288 #endif /* def HAVE_SETUSERSHELL */
290 #if HAVE_ENDUSERSHELL
292 Mono_Posix_Syscall_endusershell (void)
297 #endif /* def HAVE_ENDUSERSHELL */
300 Mono_Posix_Syscall_sync (void)