2 * <unistd.h> wrapper functions.
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004-2006 Jonathan Pryor
12 #endif /* ndef _GNU_SOURCE */
14 #include <sys/types.h>
20 #include <string.h> /* for swab(3) on Mac OS X */
28 Mono_Posix_Syscall_lseek (gint32 fd
, mph_off_t offset
, gint32 whence
)
30 mph_return_if_off_t_overflow (offset
);
32 return lseek (fd
, offset
, whence
);
36 Mono_Posix_Syscall_read (gint32 fd
, void *buf
, mph_size_t count
)
38 mph_return_if_size_t_overflow (count
);
39 return read (fd
, buf
, (size_t) count
);
43 Mono_Posix_Syscall_write (gint32 fd
, void *buf
, mph_size_t count
)
45 mph_return_if_size_t_overflow (count
);
46 return write (fd
, buf
, (size_t) count
);
50 Mono_Posix_Syscall_pread (gint32 fd
, void *buf
, mph_size_t count
, mph_off_t offset
)
52 mph_return_if_size_t_overflow (count
);
53 mph_return_if_off_t_overflow (offset
);
55 return pread (fd
, buf
, (size_t) count
, (off_t
) offset
);
59 Mono_Posix_Syscall_pwrite (gint32 fd
, void *buf
, mph_size_t count
, mph_off_t offset
)
61 mph_return_if_size_t_overflow (count
);
62 mph_return_if_off_t_overflow (offset
);
64 return pwrite (fd
, buf
, (size_t) count
, (off_t
) offset
);
68 Mono_Posix_Syscall_pipe (gint32
*reading
, gint32
*writing
)
70 int filedes
[2] = {-1, -1};
73 if (reading
== NULL
|| writing
== NULL
) {
80 *reading
= filedes
[0];
81 *writing
= filedes
[1];
86 Mono_Posix_Syscall_getcwd (char *buf
, mph_size_t size
)
88 mph_return_val_if_size_t_overflow (size
, NULL
);
89 return getcwd (buf
, (size_t) size
);
93 Mono_Posix_Syscall_fpathconf (int filedes
, int name
, int defaultError
)
96 if (Mono_Posix_FromPathconfName (name
, &name
) == -1)
98 return fpathconf (filedes
, name
);
102 Mono_Posix_Syscall_pathconf (const char *path
, int name
, int defaultError
)
104 errno
= defaultError
;
105 if (Mono_Posix_FromPathconfName (name
, &name
) == -1)
107 return pathconf (path
, name
);
111 Mono_Posix_Syscall_sysconf (int name
, int defaultError
)
113 errno
= defaultError
;
114 if (Mono_Posix_FromSysconfName (name
, &name
) == -1)
116 return sysconf (name
);
121 Mono_Posix_Syscall_confstr (int name
, char *buf
, mph_size_t len
)
123 mph_return_if_size_t_overflow (len
);
124 if (Mono_Posix_FromConfstrName (name
, &name
) == -1)
126 return confstr (name
, buf
, (size_t) len
);
128 #endif /* def HAVE_CONFSTR */
130 #ifdef HAVE_TTYNAME_R
132 Mono_Posix_Syscall_ttyname_r (int fd
, char *buf
, mph_size_t len
)
134 mph_return_if_size_t_overflow (len
);
135 return ttyname_r (fd
, buf
, (size_t) len
);
137 #endif /* ndef HAVE_TTYNAME_R */
140 Mono_Posix_Syscall_readlink (const char *path
, char *buf
, mph_size_t len
)
143 mph_return_if_size_t_overflow (len
);
144 r
= readlink (path
, buf
, (size_t) len
);
145 if (r
>= 0 && r
< len
)
152 Mono_Posix_Syscall_getlogin_r (char *buf
, mph_size_t len
)
154 mph_return_if_size_t_overflow (len
);
155 return getlogin_r (buf
, (size_t) len
);
157 #endif /* def HAVE_GETLOGIN_R */
160 Mono_Posix_Syscall_gethostname (char *buf
, mph_size_t len
)
162 mph_return_if_size_t_overflow (len
);
163 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
);
173 #endif /* def HAVE_SETHOSTNAME */
177 Mono_Posix_Syscall_gethostid (void)
181 #endif /* def HAVE_GETHOSTID */
183 #ifdef HAVE_SETHOSTID
185 Mono_Posix_Syscall_sethostid (gint64 hostid
)
187 mph_return_if_long_overflow (hostid
);
189 sethostid ((long) hostid
);
192 return sethostid ((long) hostid
);
195 #endif /* def HAVE_SETHOSTID */
197 #ifdef HAVE_GETDOMAINNAME
199 Mono_Posix_Syscall_getdomainname (char *name
, mph_size_t len
)
201 mph_return_if_size_t_overflow (len
);
202 return getdomainname (name
, (size_t) len
);
204 #endif /* def HAVE_GETDOMAINNAME */
206 #ifdef HAVE_SETDOMAINNAME
208 Mono_Posix_Syscall_setdomainname (const char *name
, mph_size_t len
)
210 mph_return_if_size_t_overflow (len
);
211 return setdomainname (name
, (size_t) len
);
213 #endif /* def HAVE_SETDOMAINNAME */
215 /* Android implements truncate, but doesn't declare it.
216 * Result is a warning during compilation, so skip it.
218 #ifndef PLATFORM_ANDROID
220 Mono_Posix_Syscall_truncate (const char *path
, mph_off_t length
)
222 mph_return_if_off_t_overflow (length
);
223 return truncate (path
, (off_t
) length
);
228 Mono_Posix_Syscall_ftruncate (int fd
, mph_off_t length
)
230 mph_return_if_off_t_overflow (length
);
231 return ftruncate (fd
, (off_t
) length
);
236 Mono_Posix_Syscall_lockf (int fd
, int cmd
, mph_off_t len
)
238 mph_return_if_off_t_overflow (len
);
239 if (Mono_Posix_FromLockfCommand (cmd
, &cmd
) == -1)
241 return lockf (fd
, cmd
, (off_t
) len
);
243 #endif /* def HAVE_LOCKF */
247 Mono_Posix_Syscall_swab (void *from
, void *to
, mph_ssize_t n
)
249 if (mph_have_long_overflow (n
))
251 swab (from
, to
, (ssize_t
) n
);
254 #endif /* def HAVE_SWAB */
256 #if HAVE_SETUSERSHELL
258 Mono_Posix_Syscall_setusershell (void)
263 #endif /* def HAVE_SETUSERSHELL */
265 #if HAVE_ENDUSERSHELL
267 Mono_Posix_Syscall_endusershell (void)
272 #endif /* def HAVE_ENDUSERSHELL */
275 Mono_Posix_Syscall_sync (void)