xref: /rust-libc-0.2.174/src/unix/mod.rs (revision b9fdcf94)
1 //! Definitions found commonly among almost all Unix derivatives
2 //!
3 //! More functions and definitions can be found in the more specific modules
4 //! according to the platform in question.
5 
6 use dox::Option;
7 
8 pub type pid_t = i32;
9 pub type uid_t = u32;
10 pub type gid_t = u32;
11 pub type in_addr_t = u32;
12 pub type in_port_t = u16;
13 pub type sighandler_t = ::size_t;
14 pub type cc_t = ::c_uchar;
15 
16 pub enum DIR {}
17 pub enum locale_t {}
18 
19 s! {
20     pub struct group {
21         pub gr_name: *mut ::c_char,
22         pub gr_passwd: *mut ::c_char,
23         pub gr_gid: ::gid_t,
24         pub gr_mem: *mut *mut ::c_char,
25     }
26 
27     pub struct utimbuf {
28         pub actime: time_t,
29         pub modtime: time_t,
30     }
31 
32     pub struct timeval {
33         pub tv_sec: time_t,
34         pub tv_usec: suseconds_t,
35     }
36 
37     pub struct timespec {
38         pub tv_sec: time_t,
39         pub tv_nsec: c_long,
40     }
41 
42     pub struct rlimit {
43         pub rlim_cur: rlim_t,
44         pub rlim_max: rlim_t,
45     }
46 
47     pub struct rusage {
48         pub ru_utime: timeval,
49         pub ru_stime: timeval,
50         pub ru_maxrss: c_long,
51         pub ru_ixrss: c_long,
52         pub ru_idrss: c_long,
53         pub ru_isrss: c_long,
54         pub ru_minflt: c_long,
55         pub ru_majflt: c_long,
56         pub ru_nswap: c_long,
57         pub ru_inblock: c_long,
58         pub ru_oublock: c_long,
59         pub ru_msgsnd: c_long,
60         pub ru_msgrcv: c_long,
61         pub ru_nsignals: c_long,
62         pub ru_nvcsw: c_long,
63         pub ru_nivcsw: c_long,
64 
65         #[cfg(any(target_env = "musl", target_os = "emscripten"))]
66         __reserved: [c_long; 16],
67     }
68 
69     #[cfg_attr(target_os = "netbsd", repr(packed))]
70     pub struct in_addr {
71         pub s_addr: in_addr_t,
72     }
73 
74     pub struct in6_addr {
75         pub s6_addr: [u8; 16],
76         __align: [u32; 0],
77     }
78 
79     pub struct ip_mreq {
80         pub imr_multiaddr: in_addr,
81         pub imr_interface: in_addr,
82     }
83 
84     pub struct ipv6_mreq {
85         pub ipv6mr_multiaddr: in6_addr,
86         #[cfg(target_os = "android")]
87         pub ipv6mr_interface: ::c_int,
88         #[cfg(not(target_os = "android"))]
89         pub ipv6mr_interface: ::c_uint,
90     }
91 
92     pub struct hostent {
93         pub h_name: *mut ::c_char,
94         pub h_aliases: *mut *mut ::c_char,
95         pub h_addrtype: ::c_int,
96         pub h_length: ::c_int,
97         pub h_addr_list: *mut *mut ::c_char,
98     }
99 
100     pub struct iovec {
101         pub iov_base: *mut ::c_void,
102         pub iov_len: ::size_t,
103     }
104 
105     pub struct pollfd {
106         pub fd: ::c_int,
107         pub events: ::c_short,
108         pub revents: ::c_short,
109     }
110 
111     pub struct winsize {
112         pub ws_row: ::c_ushort,
113         pub ws_col: ::c_ushort,
114         pub ws_xpixel: ::c_ushort,
115         pub ws_ypixel: ::c_ushort,
116     }
117 
118     pub struct linger {
119         pub l_onoff: ::c_int,
120         pub l_linger: ::c_int,
121     }
122 
123     pub struct sigval {
124         // Actually a union of an int and a void*
125         pub sival_ptr: *mut ::c_void
126     }
127 
128     // <sys/time.h>
129     pub struct itimerval {
130         pub it_interval: ::timeval,
131         pub it_value: ::timeval,
132     }
133 
134     // <sys/times.h>
135     pub struct tms {
136         pub tms_utime: ::clock_t,
137         pub tms_stime: ::clock_t,
138         pub tms_cutime: ::clock_t,
139         pub tms_cstime: ::clock_t,
140     }
141 }
142 
143 pub const SIG_DFL: sighandler_t = 0 as sighandler_t;
144 pub const SIG_IGN: sighandler_t = 1 as sighandler_t;
145 pub const SIG_ERR: sighandler_t = !0 as sighandler_t;
146 
147 pub const DT_FIFO: u8 = 1;
148 pub const DT_CHR: u8 = 2;
149 pub const DT_DIR: u8 = 4;
150 pub const DT_BLK: u8 = 6;
151 pub const DT_REG: u8 = 8;
152 pub const DT_LNK: u8 = 10;
153 pub const DT_SOCK: u8 = 12;
154 
155 pub const FD_CLOEXEC: ::c_int = 0x1;
156 
157 pub const USRQUOTA: ::c_int = 0;
158 pub const GRPQUOTA: ::c_int = 1;
159 
160 pub const SIGIOT: ::c_int = 6;
161 
162 pub const S_ISUID: ::c_int = 0x800;
163 pub const S_ISGID: ::c_int = 0x400;
164 pub const S_ISVTX: ::c_int = 0x200;
165 
166 pub const POLLIN: ::c_short = 0x1;
167 pub const POLLPRI: ::c_short = 0x2;
168 pub const POLLOUT: ::c_short = 0x4;
169 pub const POLLERR: ::c_short = 0x8;
170 pub const POLLHUP: ::c_short = 0x10;
171 pub const POLLNVAL: ::c_short = 0x20;
172 
173 pub const IF_NAMESIZE: ::size_t = 16;
174 
175 pub const RTLD_LAZY: ::c_int = 0x1;
176 
177 pub const LOG_EMERG: ::c_int = 0;
178 pub const LOG_ALERT: ::c_int = 1;
179 pub const LOG_CRIT: ::c_int = 2;
180 pub const LOG_ERR: ::c_int = 3;
181 pub const LOG_WARNING: ::c_int = 4;
182 pub const LOG_NOTICE: ::c_int = 5;
183 pub const LOG_INFO: ::c_int = 6;
184 pub const LOG_DEBUG: ::c_int = 7;
185 
186 pub const LOG_KERN: ::c_int = 0;
187 pub const LOG_USER: ::c_int = 1 << 3;
188 pub const LOG_MAIL: ::c_int = 2 << 3;
189 pub const LOG_DAEMON: ::c_int = 3 << 3;
190 pub const LOG_AUTH: ::c_int = 4 << 3;
191 pub const LOG_SYSLOG: ::c_int = 5 << 3;
192 pub const LOG_LPR: ::c_int = 6 << 3;
193 pub const LOG_NEWS: ::c_int = 7 << 3;
194 pub const LOG_UUCP: ::c_int = 8 << 3;
195 pub const LOG_LOCAL0: ::c_int = 16 << 3;
196 pub const LOG_LOCAL1: ::c_int = 17 << 3;
197 pub const LOG_LOCAL2: ::c_int = 18 << 3;
198 pub const LOG_LOCAL3: ::c_int = 19 << 3;
199 pub const LOG_LOCAL4: ::c_int = 20 << 3;
200 pub const LOG_LOCAL5: ::c_int = 21 << 3;
201 pub const LOG_LOCAL6: ::c_int = 22 << 3;
202 pub const LOG_LOCAL7: ::c_int = 23 << 3;
203 
204 pub const LOG_PID: ::c_int = 0x01;
205 pub const LOG_CONS: ::c_int = 0x02;
206 pub const LOG_ODELAY: ::c_int = 0x04;
207 pub const LOG_NDELAY: ::c_int = 0x08;
208 pub const LOG_NOWAIT: ::c_int = 0x10;
209 
210 pub const LOG_PRIMASK: ::c_int = 7;
211 pub const LOG_FACMASK: ::c_int = 0x3f8;
212 
213 pub const PRIO_PROCESS: ::c_int = 0;
214 pub const PRIO_PGRP: ::c_int = 1;
215 pub const PRIO_USER: ::c_int = 2;
216 
217 pub const PRIO_MIN: ::c_int = -20;
218 pub const PRIO_MAX: ::c_int = 20;
219 
220 pub const IPPROTO_ICMP: ::c_int = 1;
221 pub const IPPROTO_ICMPV6: ::c_int = 58;
222 pub const IPPROTO_TCP: ::c_int = 6;
223 pub const IPPROTO_UDP: ::c_int = 17;
224 pub const IPPROTO_IP: ::c_int = 0;
225 pub const IPPROTO_IPV6: ::c_int = 41;
226 
227 pub const INADDR_LOOPBACK: in_addr_t = 2130706433;
228 pub const INADDR_ANY: in_addr_t = 0;
229 pub const INADDR_BROADCAST: in_addr_t = 4294967295;
230 pub const INADDR_NONE: in_addr_t = 4294967295;
231 
232 cfg_if! {
233     if #[cfg(dox)] {
234         // on dox builds don't pull in anything
235     } else if #[cfg(target_os = "l4re")] {
236         // required libraries for L4Re are linked externally, ATM
237     } else if #[cfg(feature = "use_std")] {
238         // cargo build, don't pull in anything extra as the libstd dep
239         // already pulls in all libs.
240     } else if #[cfg(any(all(target_env = "musl", not(target_arch = "mips"))))] {
241         #[link(name = "c", kind = "static", cfg(target_feature = "crt-static"))]
242         #[link(name = "c", cfg(not(target_feature = "crt-static")))]
243         extern {}
244     } else if #[cfg(target_os = "emscripten")] {
245         #[link(name = "c")]
246         extern {}
247     } else if #[cfg(all(target_os = "netbsd", target_vendor = "rumprun"))] {
248         // Since we don't use -nodefaultlibs on Rumprun, libc is always pulled
249         // in automatically by the linker. We avoid passing it explicitly, as it
250         // causes some versions of binutils to crash with an assertion failure.
251         #[link(name = "m")]
252         extern {}
253     } else if #[cfg(any(target_os = "macos",
254                         target_os = "ios",
255                         target_os = "android",
256                         target_os = "openbsd",
257                         target_os = "bitrig"))] {
258         #[link(name = "c")]
259         #[link(name = "m")]
260         extern {}
261     } else if #[cfg(target_os = "haiku")] {
262         #[link(name = "root")]
263         #[link(name = "network")]
264         extern {}
265     } else if #[cfg(target_os = "fuchsia")] {
266         #[link(name = "c")]
267         #[link(name = "fdio")]
268         extern {}
269     } else if #[cfg(target_env = "newlib")] {
270         #[link(name = "c")]
271         #[link(name = "m")]
272         extern {}
273     } else {
274         #[link(name = "c")]
275         #[link(name = "m")]
276         #[link(name = "rt")]
277         #[link(name = "pthread")]
278         extern {}
279     }
280 }
281 
282 extern {
283     #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam50")]
284     pub fn getpwnam(name: *const ::c_char) -> *mut passwd;
285     #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid50")]
286     pub fn getpwuid(uid: ::uid_t) -> *mut passwd;
287 
288     pub fn fprintf(stream: *mut ::FILE,
289                    format: *const ::c_char, ...) -> ::c_int;
290     pub fn printf(format: *const ::c_char, ...) -> ::c_int;
291     pub fn snprintf(s: *mut ::c_char, n: ::size_t,
292                     format: *const ::c_char, ...) -> ::c_int;
293     pub fn sprintf(s: *mut ::c_char, format: *const ::c_char, ...) -> ::c_int;
294     pub fn fscanf(stream: *mut ::FILE, format: *const ::c_char, ...) -> ::c_int;
295     pub fn scanf(format: *const ::c_char, ...) -> ::c_int;
296     pub fn sscanf(s: *const ::c_char, format: *const ::c_char, ...) -> ::c_int;
297     pub fn getchar_unlocked() -> ::c_int;
298     pub fn putchar_unlocked(c: ::c_int) -> ::c_int;
299 
300     #[cfg_attr(target_os = "netbsd", link_name = "__socket30")]
301     pub fn socket(domain: ::c_int, ty: ::c_int, protocol: ::c_int) -> ::c_int;
302     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
303                link_name = "connect$UNIX2003")]
304     pub fn connect(socket: ::c_int, address: *const sockaddr,
305                    len: socklen_t) -> ::c_int;
306     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
307                link_name = "listen$UNIX2003")]
308     pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int;
309     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
310                link_name = "accept$UNIX2003")]
311     pub fn accept(socket: ::c_int, address: *mut sockaddr,
312                   address_len: *mut socklen_t) -> ::c_int;
313     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
314                link_name = "getpeername$UNIX2003")]
315     pub fn getpeername(socket: ::c_int, address: *mut sockaddr,
316                        address_len: *mut socklen_t) -> ::c_int;
317     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
318                link_name = "getsockname$UNIX2003")]
319     pub fn getsockname(socket: ::c_int, address: *mut sockaddr,
320                        address_len: *mut socklen_t) -> ::c_int;
321     pub fn setsockopt(socket: ::c_int, level: ::c_int, name: ::c_int,
322                       value: *const ::c_void,
323                       option_len: socklen_t) -> ::c_int;
324     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
325                link_name = "socketpair$UNIX2003")]
326     pub fn socketpair(domain: ::c_int, type_: ::c_int, protocol: ::c_int,
327                       socket_vector: *mut ::c_int) -> ::c_int;
328     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
329                link_name = "sendto$UNIX2003")]
330     pub fn sendto(socket: ::c_int, buf: *const ::c_void, len: ::size_t,
331                   flags: ::c_int, addr: *const sockaddr,
332                   addrlen: socklen_t) -> ::ssize_t;
333     pub fn shutdown(socket: ::c_int, how: ::c_int) -> ::c_int;
334 
335     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
336                link_name = "chmod$UNIX2003")]
337     pub fn chmod(path: *const c_char, mode: mode_t) -> ::c_int;
338     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
339                link_name = "fchmod$UNIX2003")]
340     pub fn fchmod(fd: ::c_int, mode: mode_t) -> ::c_int;
341 
342     #[cfg_attr(target_os = "macos", link_name = "fstat$INODE64")]
343     #[cfg_attr(target_os = "netbsd", link_name = "__fstat50")]
344     pub fn fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int;
345 
346     pub fn mkdir(path: *const c_char, mode: mode_t) -> ::c_int;
347 
348     #[cfg_attr(target_os = "macos", link_name = "stat$INODE64")]
349     #[cfg_attr(target_os = "netbsd", link_name = "__stat50")]
350     pub fn stat(path: *const c_char, buf: *mut stat) -> ::c_int;
351 
352     pub fn pclose(stream: *mut ::FILE) -> ::c_int;
353     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
354                link_name = "fdopen$UNIX2003")]
355     pub fn fdopen(fd: ::c_int, mode: *const c_char) -> *mut ::FILE;
356     pub fn fileno(stream: *mut ::FILE) -> ::c_int;
357 
358     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
359                link_name = "open$UNIX2003")]
360     pub fn open(path: *const c_char, oflag: ::c_int, ...) -> ::c_int;
361     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
362                link_name = "creat$UNIX2003")]
363     pub fn creat(path: *const c_char, mode: mode_t) -> ::c_int;
364     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
365                link_name = "fcntl$UNIX2003")]
366     pub fn fcntl(fd: ::c_int, cmd: ::c_int, ...) -> ::c_int;
367 
368     #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
369                link_name = "opendir$INODE64")]
370     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
371                link_name = "opendir$INODE64$UNIX2003")]
372     #[cfg_attr(target_os = "netbsd", link_name = "__opendir30")]
373     pub fn opendir(dirname: *const c_char) -> *mut ::DIR;
374     #[cfg_attr(target_os = "macos", link_name = "readdir$INODE64")]
375     #[cfg_attr(target_os = "netbsd", link_name = "__readdir30")]
376     pub fn readdir(dirp: *mut ::DIR) -> *mut ::dirent;
377     #[cfg_attr(target_os = "macos", link_name = "readdir_r$INODE64")]
378     #[cfg_attr(target_os = "netbsd", link_name = "__readdir_r30")]
379     #[cfg_attr(target_os = "solaris", link_name = "__posix_readdir_r")]
380     pub fn readdir_r(dirp: *mut ::DIR, entry: *mut ::dirent,
381                      result: *mut *mut ::dirent) -> ::c_int;
382     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
383                link_name = "closedir$UNIX2003")]
384     pub fn closedir(dirp: *mut ::DIR) -> ::c_int;
385     #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
386                link_name = "rewinddir$INODE64")]
387     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
388                link_name = "rewinddir$INODE64$UNIX2003")]
389     pub fn rewinddir(dirp: *mut ::DIR);
390 
391     pub fn openat(dirfd: ::c_int, pathname: *const ::c_char,
392                   flags: ::c_int, ...) -> ::c_int;
393     pub fn fchmodat(dirfd: ::c_int, pathname: *const ::c_char,
394                     mode: ::mode_t, flags: ::c_int) -> ::c_int;
395     pub fn fchown(fd: ::c_int,
396                   owner: ::uid_t,
397                   group: ::gid_t) -> ::c_int;
398     pub fn fchownat(dirfd: ::c_int, pathname: *const ::c_char,
399                     owner: ::uid_t, group: ::gid_t,
400                     flags: ::c_int) -> ::c_int;
401     #[cfg_attr(target_os = "macos", link_name = "fstatat$INODE64")]
402     pub fn fstatat(dirfd: ::c_int, pathname: *const ::c_char,
403                    buf: *mut stat, flags: ::c_int) -> ::c_int;
404     pub fn linkat(olddirfd: ::c_int, oldpath: *const ::c_char,
405                   newdirfd: ::c_int, newpath: *const ::c_char,
406                   flags: ::c_int) -> ::c_int;
407     pub fn mkdirat(dirfd: ::c_int, pathname: *const ::c_char,
408                    mode: ::mode_t) -> ::c_int;
409     pub fn readlinkat(dirfd: ::c_int, pathname: *const ::c_char,
410                       buf: *mut ::c_char, bufsiz: ::size_t) -> ::ssize_t;
411     pub fn renameat(olddirfd: ::c_int, oldpath: *const ::c_char,
412                     newdirfd: ::c_int, newpath: *const ::c_char)
413                     -> ::c_int;
414     pub fn symlinkat(target: *const ::c_char, newdirfd: ::c_int,
415                      linkpath: *const ::c_char) -> ::c_int;
416     pub fn unlinkat(dirfd: ::c_int, pathname: *const ::c_char,
417                     flags: ::c_int) -> ::c_int;
418 
419     pub fn access(path: *const c_char, amode: ::c_int) -> ::c_int;
420     pub fn alarm(seconds: ::c_uint) -> ::c_uint;
421     pub fn chdir(dir: *const c_char) -> ::c_int;
422     pub fn fchdir(dirfd: ::c_int) -> ::c_int;
423     pub fn chown(path: *const c_char, uid: uid_t,
424                  gid: gid_t) -> ::c_int;
425     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
426                link_name = "lchown$UNIX2003")]
427     pub fn lchown(path: *const c_char, uid: uid_t,
428                   gid: gid_t) -> ::c_int;
429     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
430                link_name = "close$NOCANCEL$UNIX2003")]
431     #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
432                link_name = "close$NOCANCEL")]
433     pub fn close(fd: ::c_int) -> ::c_int;
434     pub fn dup(fd: ::c_int) -> ::c_int;
435     pub fn dup2(src: ::c_int, dst: ::c_int) -> ::c_int;
436     pub fn execl(path: *const c_char,
437                  arg0: *const c_char, ...) -> ::c_int;
438     pub fn execle(path: *const ::c_char,
439                   arg0: *const ::c_char, ...) -> ::c_int;
440     pub fn execlp(file: *const ::c_char,
441                   arg0: *const ::c_char, ...) -> ::c_int;
442     pub fn execv(prog: *const c_char,
443                  argv: *const *const c_char) -> ::c_int;
444     pub fn execve(prog: *const c_char, argv: *const *const c_char,
445                   envp: *const *const c_char)
446                   -> ::c_int;
447     pub fn execvp(c: *const c_char,
448                   argv: *const *const c_char) -> ::c_int;
449     pub fn fork() -> pid_t;
450     pub fn fpathconf(filedes: ::c_int, name: ::c_int) -> c_long;
451     pub fn getcwd(buf: *mut c_char, size: ::size_t) -> *mut c_char;
452     pub fn getegid() -> gid_t;
453     pub fn geteuid() -> uid_t;
454     pub fn getgid() -> gid_t;
455     pub fn getgroups(ngroups_max: ::c_int, groups: *mut gid_t)
456                      -> ::c_int;
457     pub fn getlogin() -> *mut c_char;
458     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
459                link_name = "getopt$UNIX2003")]
460     pub fn getopt(argc: ::c_int, argv: *const *mut c_char,
461                   optstr: *const c_char) -> ::c_int;
462     pub fn getpgid(pid: pid_t) -> pid_t;
463     pub fn getpgrp() -> pid_t;
464     pub fn getpid() -> pid_t;
465     pub fn getppid() -> pid_t;
466     pub fn getuid() -> uid_t;
467     pub fn isatty(fd: ::c_int) -> ::c_int;
468     pub fn link(src: *const c_char, dst: *const c_char) -> ::c_int;
469     pub fn lseek(fd: ::c_int, offset: off_t, whence: ::c_int) -> off_t;
470     pub fn pathconf(path: *const c_char, name: ::c_int) -> c_long;
471     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
472                link_name = "pause$UNIX2003")]
473     pub fn pause() -> ::c_int;
474     pub fn pipe(fds: *mut ::c_int) -> ::c_int;
475     pub fn posix_memalign(memptr: *mut *mut ::c_void,
476                       align: ::size_t,
477                       size: ::size_t) -> ::c_int;
478     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
479                link_name = "read$UNIX2003")]
480     pub fn read(fd: ::c_int, buf: *mut ::c_void, count: ::size_t)
481                 -> ::ssize_t;
482     pub fn rmdir(path: *const c_char) -> ::c_int;
483     pub fn seteuid(uid: uid_t) -> ::c_int;
484     pub fn setgid(gid: gid_t) -> ::c_int;
485     pub fn setpgid(pid: pid_t, pgid: pid_t) -> ::c_int;
486     pub fn setsid() -> pid_t;
487     pub fn setuid(uid: uid_t) -> ::c_int;
488     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
489                link_name = "sleep$UNIX2003")]
490     pub fn sleep(secs: ::c_uint) -> ::c_uint;
491     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
492                link_name = "nanosleep$UNIX2003")]
493     #[cfg_attr(target_os = "netbsd", link_name = "__nanosleep50")]
494     pub fn nanosleep(rqtp: *const timespec,
495                      rmtp: *mut timespec) -> ::c_int;
496     pub fn tcgetpgrp(fd: ::c_int) -> pid_t;
497     pub fn tcsetpgrp(fd: ::c_int, pgrp: ::pid_t) -> ::c_int;
498     pub fn ttyname(fd: ::c_int) -> *mut c_char;
499     pub fn unlink(c: *const c_char) -> ::c_int;
500     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
501                link_name = "wait$UNIX2003")]
502     pub fn wait(status: *mut ::c_int) -> pid_t;
503     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
504                link_name = "waitpid$UNIX2003")]
505     pub fn waitpid(pid: pid_t, status: *mut ::c_int, options: ::c_int)
506                    -> pid_t;
507     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
508                link_name = "write$UNIX2003")]
509     pub fn write(fd: ::c_int, buf: *const ::c_void, count: ::size_t)
510                  -> ::ssize_t;
511     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
512                link_name = "pread$UNIX2003")]
513     pub fn pread(fd: ::c_int, buf: *mut ::c_void, count: ::size_t,
514                  offset: off_t) -> ::ssize_t;
515     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
516                link_name = "pwrite$UNIX2003")]
517     pub fn pwrite(fd: ::c_int, buf: *const ::c_void, count: ::size_t,
518                   offset: off_t) -> ::ssize_t;
519     pub fn umask(mask: mode_t) -> mode_t;
520 
521     #[cfg_attr(target_os = "netbsd", link_name = "__utime50")]
522     pub fn utime(file: *const c_char, buf: *const utimbuf) -> ::c_int;
523 
524     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
525                    link_name = "kill$UNIX2003")]
526     pub fn kill(pid: pid_t, sig: ::c_int) -> ::c_int;
527 
528     pub fn mlock(addr: *const ::c_void, len: ::size_t) -> ::c_int;
529     pub fn munlock(addr: *const ::c_void, len: ::size_t) -> ::c_int;
530     pub fn mlockall(flags: ::c_int) -> ::c_int;
531     pub fn munlockall() -> ::c_int;
532 
533     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
534                link_name = "mmap$UNIX2003")]
535     pub fn mmap(addr: *mut ::c_void,
536                 len: ::size_t,
537                 prot: ::c_int,
538                 flags: ::c_int,
539                 fd: ::c_int,
540                 offset: off_t)
541                 -> *mut ::c_void;
542     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
543                link_name = "munmap$UNIX2003")]
544     pub fn munmap(addr: *mut ::c_void, len: ::size_t) -> ::c_int;
545 
546     pub fn if_nametoindex(ifname: *const c_char) -> ::c_uint;
547     pub fn if_indextoname(ifindex: ::c_uint,
548                           ifname: *mut ::c_char) -> *mut ::c_char;
549 
550     #[cfg_attr(target_os = "macos", link_name = "lstat$INODE64")]
551     #[cfg_attr(target_os = "netbsd", link_name = "__lstat50")]
552     pub fn lstat(path: *const c_char, buf: *mut stat) -> ::c_int;
553 
554     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
555                link_name = "fsync$UNIX2003")]
556     pub fn fsync(fd: ::c_int) -> ::c_int;
557 
558     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
559                link_name = "setenv$UNIX2003")]
560     pub fn setenv(name: *const c_char, val: *const c_char,
561                   overwrite: ::c_int) -> ::c_int;
562     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
563                link_name = "unsetenv$UNIX2003")]
564     #[cfg_attr(target_os = "netbsd", link_name = "__unsetenv13")]
565     pub fn unsetenv(name: *const c_char) -> ::c_int;
566 
567     pub fn symlink(path1: *const c_char,
568                    path2: *const c_char) -> ::c_int;
569 
570     pub fn ftruncate(fd: ::c_int, length: off_t) -> ::c_int;
571 
572     pub fn signal(signum: ::c_int, handler: sighandler_t) -> sighandler_t;
573 
574     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
575                link_name = "getrlimit$UNIX2003")]
576     pub fn getrlimit(resource: ::c_int, rlim: *mut rlimit) -> ::c_int;
577     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
578                link_name = "setrlimit$UNIX2003")]
579     pub fn setrlimit(resource: ::c_int, rlim: *const rlimit) -> ::c_int;
580     #[cfg_attr(target_os = "netbsd", link_name = "__getrusage50")]
581     pub fn getrusage(resource: ::c_int, usage: *mut rusage) -> ::c_int;
582 
583     #[cfg_attr(any(target_os = "macos", target_os = "ios"),
584                link_name = "realpath$DARWIN_EXTSN")]
585     pub fn realpath(pathname: *const ::c_char, resolved: *mut ::c_char)
586                     -> *mut ::c_char;
587 
588     pub fn flock(fd: ::c_int, operation: ::c_int) -> ::c_int;
589 
590     #[cfg_attr(target_os = "netbsd", link_name = "__gettimeofday50")]
591     pub fn gettimeofday(tp: *mut ::timeval,
592                         tz: *mut ::c_void) -> ::c_int;
593     #[cfg_attr(target_os = "netbsd", link_name = "__times13")]
594     pub fn times(buf: *mut ::tms) -> ::clock_t;
595 
596     pub fn pthread_self() -> ::pthread_t;
597     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
598                link_name = "pthread_join$UNIX2003")]
599     pub fn pthread_join(native: ::pthread_t,
600                         value: *mut *mut ::c_void) -> ::c_int;
601     pub fn pthread_exit(value: *mut ::c_void);
602     pub fn pthread_attr_init(attr: *mut ::pthread_attr_t) -> ::c_int;
603     pub fn pthread_attr_destroy(attr: *mut ::pthread_attr_t) -> ::c_int;
604     pub fn pthread_attr_setstacksize(attr: *mut ::pthread_attr_t,
605                                      stack_size: ::size_t) -> ::c_int;
606     pub fn pthread_attr_setdetachstate(attr: *mut ::pthread_attr_t,
607                                        state: ::c_int) -> ::c_int;
608     pub fn pthread_detach(thread: ::pthread_t) -> ::c_int;
609     #[cfg_attr(target_os = "netbsd", link_name = "__libc_thr_yield")]
610     pub fn sched_yield() -> ::c_int;
611     pub fn pthread_key_create(key: *mut pthread_key_t,
612                               dtor: Option<unsafe extern fn(*mut ::c_void)>)
613                               -> ::c_int;
614     pub fn pthread_key_delete(key: pthread_key_t) -> ::c_int;
615     pub fn pthread_getspecific(key: pthread_key_t) -> *mut ::c_void;
616     pub fn pthread_setspecific(key: pthread_key_t, value: *const ::c_void)
617                                -> ::c_int;
618     pub fn pthread_mutex_init(lock: *mut pthread_mutex_t,
619                               attr: *const pthread_mutexattr_t) -> ::c_int;
620     pub fn pthread_mutex_destroy(lock: *mut pthread_mutex_t) -> ::c_int;
621     pub fn pthread_mutex_lock(lock: *mut pthread_mutex_t) -> ::c_int;
622     pub fn pthread_mutex_trylock(lock: *mut pthread_mutex_t) -> ::c_int;
623     pub fn pthread_mutex_unlock(lock: *mut pthread_mutex_t) -> ::c_int;
624 
625     pub fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> ::c_int;
626     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
627                link_name = "pthread_mutexattr_destroy$UNIX2003")]
628     pub fn pthread_mutexattr_destroy(attr: *mut pthread_mutexattr_t) -> ::c_int;
629     pub fn pthread_mutexattr_settype(attr: *mut pthread_mutexattr_t,
630                                      _type: ::c_int) -> ::c_int;
631 
632     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
633                link_name = "pthread_cond_init$UNIX2003")]
634     pub fn pthread_cond_init(cond: *mut pthread_cond_t,
635                              attr: *const pthread_condattr_t) -> ::c_int;
636     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
637                link_name = "pthread_cond_wait$UNIX2003")]
638     pub fn pthread_cond_wait(cond: *mut pthread_cond_t,
639                              lock: *mut pthread_mutex_t) -> ::c_int;
640     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
641                link_name = "pthread_cond_timedwait$UNIX2003")]
642     pub fn pthread_cond_timedwait(cond: *mut pthread_cond_t,
643                               lock: *mut pthread_mutex_t,
644                               abstime: *const ::timespec) -> ::c_int;
645     pub fn pthread_cond_signal(cond: *mut pthread_cond_t) -> ::c_int;
646     pub fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> ::c_int;
647     pub fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> ::c_int;
648     pub fn pthread_condattr_init(attr: *mut pthread_condattr_t) -> ::c_int;
649     pub fn pthread_condattr_destroy(attr: *mut pthread_condattr_t) -> ::c_int;
650     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
651                link_name = "pthread_rwlock_init$UNIX2003")]
652     pub fn pthread_rwlock_init(lock: *mut pthread_rwlock_t,
653                                attr: *const pthread_rwlockattr_t) -> ::c_int;
654     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
655                link_name = "pthread_rwlock_destroy$UNIX2003")]
656     pub fn pthread_rwlock_destroy(lock: *mut pthread_rwlock_t) -> ::c_int;
657     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
658                link_name = "pthread_rwlock_rdlock$UNIX2003")]
659     pub fn pthread_rwlock_rdlock(lock: *mut pthread_rwlock_t) -> ::c_int;
660     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
661                link_name = "pthread_rwlock_tryrdlock$UNIX2003")]
662     pub fn pthread_rwlock_tryrdlock(lock: *mut pthread_rwlock_t) -> ::c_int;
663     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
664                link_name = "pthread_rwlock_wrlock$UNIX2003")]
665     pub fn pthread_rwlock_wrlock(lock: *mut pthread_rwlock_t) -> ::c_int;
666     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
667                link_name = "pthread_rwlock_trywrlock$UNIX2003")]
668     pub fn pthread_rwlock_trywrlock(lock: *mut pthread_rwlock_t) -> ::c_int;
669     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
670                link_name = "pthread_rwlock_unlock$UNIX2003")]
671     pub fn pthread_rwlock_unlock(lock: *mut pthread_rwlock_t) -> ::c_int;
672     pub fn pthread_rwlockattr_init(attr: *mut pthread_rwlockattr_t) -> ::c_int;
673     pub fn pthread_rwlockattr_destroy(attr: *mut pthread_rwlockattr_t)
674                                       -> ::c_int;
675     #[cfg_attr(all(target_os = "linux", not(target_env = "musl")),
676                link_name = "__xpg_strerror_r")]
677     pub fn strerror_r(errnum: ::c_int, buf: *mut c_char,
678                       buflen: ::size_t) -> ::c_int;
679 
680     pub fn getsockopt(sockfd: ::c_int,
681                       level: ::c_int,
682                       optname: ::c_int,
683                       optval: *mut ::c_void,
684                       optlen: *mut ::socklen_t) -> ::c_int;
685     pub fn raise(signum: ::c_int) -> ::c_int;
686     #[cfg_attr(target_os = "netbsd", link_name = "__sigaction14")]
687     pub fn sigaction(signum: ::c_int,
688                      act: *const sigaction,
689                      oldact: *mut sigaction) -> ::c_int;
690 
691     #[cfg_attr(target_os = "netbsd", link_name = "__utimes50")]
692     pub fn utimes(filename: *const ::c_char,
693                   times: *const ::timeval) -> ::c_int;
694     pub fn dlopen(filename: *const ::c_char,
695                   flag: ::c_int) -> *mut ::c_void;
696     pub fn dlerror() -> *mut ::c_char;
697     pub fn dlsym(handle: *mut ::c_void,
698                  symbol: *const ::c_char) -> *mut ::c_void;
699     pub fn dlclose(handle: *mut ::c_void) -> ::c_int;
700     pub fn dladdr(addr: *const ::c_void, info: *mut Dl_info) -> ::c_int;
701 
702     pub fn getaddrinfo(node: *const c_char,
703                        service: *const c_char,
704                        hints: *const addrinfo,
705                        res: *mut *mut addrinfo) -> ::c_int;
706     pub fn freeaddrinfo(res: *mut addrinfo);
707     pub fn gai_strerror(errcode: ::c_int) -> *const ::c_char;
708     #[cfg_attr(any(
709                    all(target_os = "linux", not(target_env = "musl")),
710                    target_os = "freebsd",
711                    target_os = "dragonfly",
712                    target_os = "haiku"),
713                link_name = "__res_init")]
714     #[cfg_attr(any(target_os = "macos", target_os = "ios"),
715                link_name = "res_9_init")]
716     pub fn res_init() -> ::c_int;
717 
718     #[cfg_attr(target_os = "netbsd", link_name = "__gmtime_r50")]
719     pub fn gmtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm;
720     #[cfg_attr(target_os = "netbsd", link_name = "__localtime_r50")]
721     pub fn localtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm;
722     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
723                link_name = "mktime$UNIX2003")]
724     #[cfg_attr(target_os = "netbsd", link_name = "__mktime50")]
725     pub fn mktime(tm: *mut tm) -> time_t;
726     #[cfg_attr(target_os = "netbsd", link_name = "__time50")]
727     pub fn time(time: *mut time_t) -> time_t;
728     #[cfg_attr(target_os = "netbsd", link_name = "__gmtime50")]
729     pub fn gmtime(time_p: *const time_t) -> *mut tm;
730     #[cfg_attr(target_os = "netbsd", link_name = "__locatime50")]
731     pub fn localtime(time_p: *const time_t) -> *mut tm;
732 
733     #[cfg_attr(target_os = "netbsd", link_name = "__mknod50")]
734     pub fn mknod(pathname: *const ::c_char, mode: ::mode_t,
735                  dev: ::dev_t) -> ::c_int;
736     pub fn uname(buf: *mut ::utsname) -> ::c_int;
737     pub fn gethostname(name: *mut ::c_char, len: ::size_t) -> ::c_int;
738     pub fn chroot(name: *const ::c_char) -> ::c_int;
739     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
740                link_name = "usleep$UNIX2003")]
741     pub fn usleep(secs: ::c_uint) -> ::c_int;
742     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
743                link_name = "send$UNIX2003")]
744     pub fn send(socket: ::c_int, buf: *const ::c_void, len: ::size_t,
745                 flags: ::c_int) -> ::ssize_t;
746     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
747                link_name = "recv$UNIX2003")]
748     pub fn recv(socket: ::c_int, buf: *mut ::c_void, len: ::size_t,
749                 flags: ::c_int) -> ::ssize_t;
750     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
751                link_name = "putenv$UNIX2003")]
752     #[cfg_attr(target_os = "netbsd", link_name = "__putenv50")]
753     pub fn putenv(string: *mut c_char) -> ::c_int;
754     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
755                link_name = "poll$UNIX2003")]
756     pub fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: ::c_int) -> ::c_int;
757     #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
758                link_name = "select$1050")]
759     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
760                link_name = "select$UNIX2003")]
761     #[cfg_attr(target_os = "netbsd", link_name = "__select50")]
762     pub fn select(nfds: ::c_int,
763                   readfs: *mut fd_set,
764                   writefds: *mut fd_set,
765                   errorfds: *mut fd_set,
766                   timeout: *mut timeval) -> ::c_int;
767     #[cfg_attr(target_os = "netbsd", link_name = "__setlocale50")]
768     pub fn setlocale(category: ::c_int,
769                      locale: *const ::c_char) -> *mut ::c_char;
770     pub fn localeconv() -> *mut lconv;
771 
772     pub fn sem_destroy(sem: *mut sem_t) -> ::c_int;
773     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
774                link_name = "sem_wait$UNIX2003")]
775     pub fn sem_wait(sem: *mut sem_t) -> ::c_int;
776     pub fn sem_trywait(sem: *mut sem_t) -> ::c_int;
777     pub fn sem_post(sem: *mut sem_t) -> ::c_int;
778     pub fn sem_init(sem: *mut sem_t,
779                     pshared: ::c_int,
780                     value: ::c_uint)
781                     -> ::c_int;
782     pub fn statvfs(path: *const c_char, buf: *mut statvfs) -> ::c_int;
783     pub fn fstatvfs(fd: ::c_int, buf: *mut statvfs) -> ::c_int;
784 
785     pub fn readlink(path: *const c_char,
786                     buf: *mut c_char,
787                     bufsz: ::size_t)
788                     -> ::ssize_t;
789 
790     #[cfg_attr(target_os = "netbsd", link_name = "__sigemptyset14")]
791     pub fn sigemptyset(set: *mut sigset_t) -> ::c_int;
792     #[cfg_attr(target_os = "netbsd", link_name = "__sigaddset14")]
793     pub fn sigaddset(set: *mut sigset_t, signum: ::c_int) -> ::c_int;
794     #[cfg_attr(target_os = "netbsd", link_name = "__sigfillset14")]
795     pub fn sigfillset(set: *mut sigset_t) -> ::c_int;
796     #[cfg_attr(target_os = "netbsd", link_name = "__sigdelset14")]
797     pub fn sigdelset(set: *mut sigset_t, signum: ::c_int) -> ::c_int;
798     #[cfg_attr(target_os = "netbsd", link_name = "__sigismember14")]
799     pub fn sigismember(set: *const sigset_t, signum: ::c_int) -> ::c_int;
800 
801     #[cfg_attr(target_os = "netbsd", link_name = "__sigprocmask14")]
802     pub fn sigprocmask(how: ::c_int,
803                        set: *const sigset_t,
804                        oldset: *mut sigset_t)
805                        -> ::c_int;
806     #[cfg_attr(target_os = "netbsd", link_name = "__sigpending14")]
807     pub fn sigpending(set: *mut sigset_t) -> ::c_int;
808 
809     #[cfg_attr(target_os = "netbsd", link_name = "__timegm50")]
810     pub fn timegm(tm: *mut ::tm) -> time_t;
811 
812     pub fn getsid(pid: pid_t) -> pid_t;
813 
814     pub fn sysconf(name: ::c_int) -> ::c_long;
815 
816     pub fn mkfifo(path: *const c_char, mode: mode_t) -> ::c_int;
817 
818     #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
819                link_name = "pselect$1050")]
820     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
821                link_name = "pselect$UNIX2003")]
822     #[cfg_attr(target_os = "netbsd", link_name = "__pselect50")]
823     pub fn pselect(nfds: ::c_int,
824                    readfs: *mut fd_set,
825                    writefds: *mut fd_set,
826                    errorfds: *mut fd_set,
827                    timeout: *const timespec,
828                    sigmask: *const sigset_t) -> ::c_int;
829     pub fn fseeko(stream: *mut ::FILE,
830                   offset: ::off_t,
831                   whence: ::c_int) -> ::c_int;
832     pub fn ftello(stream: *mut ::FILE) -> ::off_t;
833     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
834                link_name = "tcdrain$UNIX2003")]
835     pub fn tcdrain(fd: ::c_int) -> ::c_int;
836     pub fn cfgetispeed(termios: *const ::termios) -> ::speed_t;
837     pub fn cfgetospeed(termios: *const ::termios) -> ::speed_t;
838     pub fn cfmakeraw(termios: *mut ::termios);
839     pub fn cfsetispeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int;
840     pub fn cfsetospeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int;
841     pub fn cfsetspeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int;
842     pub fn tcgetattr(fd: ::c_int, termios: *mut ::termios) -> ::c_int;
843     pub fn tcsetattr(fd: ::c_int,
844                      optional_actions: ::c_int,
845                      termios: *const ::termios) -> ::c_int;
846     pub fn tcflow(fd: ::c_int, action: ::c_int) -> ::c_int;
847     pub fn tcflush(fd: ::c_int, action: ::c_int) -> ::c_int;
848     pub fn tcgetsid(fd: ::c_int) -> ::pid_t;
849     pub fn tcsendbreak(fd: ::c_int, duration: ::c_int) -> ::c_int;
850     pub fn mkstemp(template: *mut ::c_char) -> ::c_int;
851     pub fn mkdtemp(template: *mut ::c_char) -> *mut ::c_char;
852 
853     pub fn tmpnam(ptr: *mut ::c_char) -> *mut ::c_char;
854 
855     pub fn openlog(ident: *const ::c_char, logopt: ::c_int, facility: ::c_int);
856     pub fn closelog();
857     pub fn setlogmask(maskpri: ::c_int) -> ::c_int;
858     pub fn syslog(priority: ::c_int, message: *const ::c_char, ...);
859     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
860                link_name = "nice$UNIX2003")]
861     pub fn nice(incr: ::c_int) -> ::c_int;
862 
863     pub fn grantpt(fd: ::c_int) -> ::c_int;
864     pub fn posix_openpt(flags: ::c_int) -> ::c_int;
865     pub fn ptsname(fd: ::c_int) -> *mut ::c_char;
866     pub fn unlockpt(fd: ::c_int) -> ::c_int;
867 }
868 
869 cfg_if! {
870     if #[cfg(target_env = "uclibc")] {
871         mod uclibc;
872         pub use self::uclibc::*;
873     } else if #[cfg(target_env = "newlib")] {
874         mod newlib;
875         pub use self::newlib::*;
876     } else if #[cfg(any(target_os = "linux",
877                         target_os = "android",
878                         target_os = "emscripten",
879                         target_os = "fuchsia"))] {
880         mod notbsd;
881         pub use self::notbsd::*;
882     } else if #[cfg(any(target_os = "macos",
883                         target_os = "ios",
884                         target_os = "freebsd",
885                         target_os = "dragonfly",
886                         target_os = "openbsd",
887                         target_os = "netbsd",
888                         target_os = "bitrig"))] {
889         mod bsd;
890         pub use self::bsd::*;
891     } else if #[cfg(target_os = "solaris")] {
892         mod solaris;
893         pub use self::solaris::*;
894     } else if #[cfg(target_os = "haiku")] {
895         mod haiku;
896         pub use self::haiku::*;
897     } else {
898         // Unknown target_os
899     }
900 }
901