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 */
30 Mono_Posix_Syscall_lseek (gint32 fd
, mph_off_t offset
, gint32 whence
)
32 mph_return_if_off_t_overflow (offset
);
34 return lseek (fd
, offset
, whence
);
38 Mono_Posix_Syscall_read (gint32 fd
, void *buf
, mph_size_t count
)
40 mph_return_if_size_t_overflow (count
);
41 return read (fd
, buf
, (size_t) count
);
45 Mono_Posix_Syscall_write (gint32 fd
, void *buf
, mph_size_t count
)
47 mph_return_if_size_t_overflow (count
);
48 return write (fd
, buf
, (size_t) count
);
52 Mono_Posix_Syscall_pread (gint32 fd
, void *buf
, mph_size_t count
, mph_off_t offset
)
54 mph_return_if_size_t_overflow (count
);
55 mph_return_if_off_t_overflow (offset
);
57 return pread (fd
, buf
, (size_t) count
, (off_t
) offset
);
61 Mono_Posix_Syscall_pwrite (gint32 fd
, void *buf
, mph_size_t count
, mph_off_t offset
)
63 mph_return_if_size_t_overflow (count
);
64 mph_return_if_off_t_overflow (offset
);
66 return pwrite (fd
, buf
, (size_t) count
, (off_t
) offset
);
70 Mono_Posix_Syscall_pipe (gint32
*reading
, gint32
*writing
)
72 int filedes
[2] = {-1, -1};
75 if (reading
== NULL
|| writing
== NULL
) {
82 *reading
= filedes
[0];
83 *writing
= filedes
[1];
88 Mono_Posix_Syscall_getcwd (char *buf
, mph_size_t size
)
90 mph_return_val_if_size_t_overflow (size
, NULL
);
91 return getcwd (buf
, (size_t) size
);
95 Mono_Posix_Syscall_fpathconf (int filedes
, int name
, int defaultError
)
98 if (Mono_Posix_FromPathconfName (name
, &name
) == -1)
100 return fpathconf (filedes
, name
);
104 Mono_Posix_Syscall_pathconf (const char *path
, int name
, int defaultError
)
106 errno
= defaultError
;
107 if (Mono_Posix_FromPathconfName (name
, &name
) == -1)
109 return pathconf (path
, name
);
113 Mono_Posix_Syscall_sysconf (int name
, int defaultError
)
115 errno
= defaultError
;
116 if (Mono_Posix_FromSysconfName (name
, &name
) == -1)
118 return sysconf (name
);
123 Mono_Posix_Syscall_confstr (int name
, char *buf
, mph_size_t len
)
125 mph_return_if_size_t_overflow (len
);
126 if (Mono_Posix_FromConfstrName (name
, &name
) == -1)
128 return confstr (name
, buf
, (size_t) len
);
130 #endif /* def HAVE_CONFSTR */
132 #ifdef HAVE_TTYNAME_R
134 Mono_Posix_Syscall_ttyname_r (int fd
, char *buf
, mph_size_t len
)
136 mph_return_if_size_t_overflow (len
);
137 return ttyname_r (fd
, buf
, (size_t) len
);
139 #endif /* ndef HAVE_TTYNAME_R */
142 Mono_Posix_Syscall_readlink (const char *path
, unsigned char *buf
, mph_size_t len
)
145 mph_return_if_size_t_overflow (len
);
146 r
= readlink (path
, (char*) buf
, (size_t) len
);
147 if (r
>= 0 && r
< len
)
152 #ifdef HAVE_READLINKAT
154 Mono_Posix_Syscall_readlinkat (int dirfd
, const char *path
, unsigned char *buf
, mph_size_t len
)
157 mph_return_if_size_t_overflow (len
);
158 r
= readlinkat (dirfd
, path
, (char*) buf
, (size_t) len
);
159 if (r
>= 0 && r
< len
)
163 #endif /* def HAVE_READLINKAT */
167 Mono_Posix_Syscall_getlogin_r (char *buf
, mph_size_t len
)
169 mph_return_if_size_t_overflow (len
);
170 return getlogin_r (buf
, (size_t) len
);
172 #endif /* def HAVE_GETLOGIN_R */
175 Mono_Posix_Syscall_gethostname (char *buf
, mph_size_t len
)
177 mph_return_if_size_t_overflow (len
);
178 return gethostname (buf
, (size_t) len
);
183 Mono_Posix_Syscall_sethostname (const char *name
, mph_size_t len
)
185 mph_return_if_size_t_overflow (len
);
186 return sethostname (name
, (size_t) len
);
188 #endif /* def HAVE_SETHOSTNAME */
192 Mono_Posix_Syscall_gethostid (void)
196 #endif /* def HAVE_GETHOSTID */
198 #ifdef HAVE_SETHOSTID
200 Mono_Posix_Syscall_sethostid (gint64 hostid
)
202 mph_return_if_long_overflow (hostid
);
204 sethostid ((long) hostid
);
207 return sethostid ((long) hostid
);
210 #endif /* def HAVE_SETHOSTID */
212 #ifdef HAVE_GETDOMAINNAME
214 Mono_Posix_Syscall_getdomainname (char *name
, mph_size_t len
)
216 mph_return_if_size_t_overflow (len
);
217 return getdomainname (name
, (size_t) len
);
219 #endif /* def HAVE_GETDOMAINNAME */
221 #ifdef HAVE_SETDOMAINNAME
223 Mono_Posix_Syscall_setdomainname (const char *name
, mph_size_t len
)
225 mph_return_if_size_t_overflow (len
);
226 return setdomainname (name
, (size_t) len
);
228 #endif /* def HAVE_SETDOMAINNAME */
230 /* Android implements truncate, but doesn't declare it.
231 * Result is a warning during compilation, so skip it.
235 Mono_Posix_Syscall_truncate (const char *path
, mph_off_t length
)
237 mph_return_if_off_t_overflow (length
);
238 return truncate (path
, (off_t
) length
);
243 Mono_Posix_Syscall_ftruncate (int fd
, mph_off_t length
)
245 mph_return_if_off_t_overflow (length
);
246 return ftruncate (fd
, (off_t
) length
);
251 Mono_Posix_Syscall_lockf (int fd
, int cmd
, mph_off_t len
)
253 mph_return_if_off_t_overflow (len
);
254 if (Mono_Posix_FromLockfCommand (cmd
, &cmd
) == -1)
256 return lockf (fd
, cmd
, (off_t
) len
);
258 #endif /* def HAVE_LOCKF */
262 Mono_Posix_Syscall_swab (void *from
, void *to
, mph_ssize_t n
)
264 if (mph_have_long_overflow (n
))
266 swab (from
, to
, (ssize_t
) n
);
269 #endif /* def HAVE_SWAB */
271 #if HAVE_SETUSERSHELL
273 Mono_Posix_Syscall_setusershell (void)
278 #endif /* def HAVE_SETUSERSHELL */
280 #if HAVE_ENDUSERSHELL
282 Mono_Posix_Syscall_endusershell (void)
287 #endif /* def HAVE_ENDUSERSHELL */
290 Mono_Posix_Syscall_sync (void)