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>
20 #include <string.h> /* for swab(3) on Mac OS X */
28 Mono_Posix_Syscall_lseek (gint32 fd
, mph_off_t offset
, gint32 whence
)
31 mph_return_if_off_t_overflow (offset
);
32 if (Mono_Posix_FromSeekFlags (whence
, &_whence
) == -1)
36 return lseek (fd
, offset
, whence
);
40 Mono_Posix_Syscall_read (gint32 fd
, void *buf
, mph_size_t count
)
42 mph_return_if_size_t_overflow (count
);
43 return read (fd
, buf
, (size_t) count
);
47 Mono_Posix_Syscall_write (gint32 fd
, const void *buf
, mph_size_t count
)
49 mph_return_if_size_t_overflow (count
);
50 return write (fd
, buf
, (size_t) count
);
54 Mono_Posix_Syscall_pread (gint32 fd
, void *buf
, mph_size_t count
, mph_off_t offset
)
56 mph_return_if_size_t_overflow (count
);
57 mph_return_if_off_t_overflow (offset
);
59 return pread (fd
, buf
, (size_t) count
, (off_t
) offset
);
63 Mono_Posix_Syscall_pwrite (gint32 fd
, const void *buf
, mph_size_t count
, mph_off_t offset
)
65 mph_return_if_size_t_overflow (count
);
66 mph_return_if_off_t_overflow (offset
);
68 return pwrite (fd
, buf
, (size_t) count
, (off_t
) offset
);
72 Mono_Posix_Syscall_pipe (gint32
*reading
, gint32
*writing
)
74 int filedes
[2] = {-1, -1};
77 if (reading
== NULL
|| writing
== NULL
) {
84 *reading
= filedes
[0];
85 *writing
= filedes
[1];
90 Mono_Posix_Syscall_getcwd (char *buf
, mph_size_t size
)
92 mph_return_val_if_size_t_overflow (size
, NULL
);
93 return getcwd (buf
, (size_t) size
);
97 Mono_Posix_Syscall_fpathconf (int filedes
, int name
)
99 if (Mono_Posix_FromPathConf (name
, &name
) == -1)
101 return fpathconf (filedes
, name
);
105 Mono_Posix_Syscall_pathconf (char *path
, int name
)
107 if (Mono_Posix_FromPathConf (name
, &name
) == -1)
109 return pathconf (path
, name
);
113 Mono_Posix_Syscall_sysconf (int name
)
115 if (Mono_Posix_FromSysConf (name
, &name
) == -1)
117 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_FromConfStr (name
, &name
) == -1)
126 return confstr (name
, buf
, (size_t) len
);
129 #ifdef HAVE_TTYNAME_R
131 Mono_Posix_Syscall_ttyname_r (int fd
, char *buf
, mph_size_t len
)
133 mph_return_if_size_t_overflow (len
);
134 return ttyname_r (fd
, buf
, (size_t) len
);
136 #endif /* ndef HAVE_TTYNAME_R */
139 Mono_Posix_Syscall_readlink (const char *path
, char *buf
, mph_size_t len
)
141 mph_return_if_size_t_overflow (len
);
142 return readlink (path
, buf
, (size_t) len
);
146 Mono_Posix_Syscall_getlogin_r (char *buf
, mph_size_t len
)
148 mph_return_if_size_t_overflow (len
);
149 return getlogin_r (buf
, (size_t) len
);
153 Mono_Posix_Syscall_gethostname (char *buf
, mph_size_t len
)
155 mph_return_if_size_t_overflow (len
);
156 return gethostname (buf
, (size_t) len
);
160 Mono_Posix_Syscall_sethostname (const char *name
, mph_size_t len
)
162 mph_return_if_size_t_overflow (len
);
163 return sethostname (name
, (size_t) len
);
167 Mono_Posix_Syscall_gethostid (void)
172 #ifdef HAVE_SETHOSTID
174 Mono_Posix_Syscall_sethostid (gint64 hostid
)
176 mph_return_if_long_overflow (hostid
);
178 sethostid ((long) hostid
);
181 return sethostid ((long) hostid
);
184 #endif /* def HAVE_SETHOSTID */
187 Mono_Posix_Syscall_getdomainname (char *name
, mph_size_t len
)
189 mph_return_if_size_t_overflow (len
);
190 return getdomainname (name
, (size_t) len
);
194 Mono_Posix_Syscall_setdomainname (const char *name
, mph_size_t len
)
196 mph_return_if_size_t_overflow (len
);
197 return setdomainname (name
, (size_t) len
);
201 Mono_Posix_Syscall_truncate (const char *path
, mph_off_t length
)
203 mph_return_if_off_t_overflow (length
);
204 return truncate (path
, (off_t
) length
);
208 Mono_Posix_Syscall_ftruncate (int fd
, mph_off_t length
)
210 mph_return_if_off_t_overflow (length
);
211 return ftruncate (fd
, (off_t
) length
);
215 Mono_Posix_Syscall_lockf (int fd
, int cmd
, mph_off_t len
)
217 mph_return_if_off_t_overflow (len
);
218 if (Mono_Posix_FromLockFlags (cmd
, &cmd
) == -1)
220 return lockf (fd
, cmd
, (off_t
) len
);
224 Mono_Posix_Syscall_swab (void *from
, void *to
, mph_ssize_t n
)
226 if (mph_have_long_overflow (n
))
228 swab (from
, to
, (ssize_t
) n
);