xref: /rust-libc-0.2.174/src/unix/mod.rs (revision b46b6e2e)
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 int8_t = i8;
9 pub type int16_t = i16;
10 pub type int32_t = i32;
11 pub type int64_t = i64;
12 pub type uint8_t = u8;
13 pub type uint16_t = u16;
14 pub type uint32_t = u32;
15 pub type uint64_t = u64;
16 
17 pub type c_schar = i8;
18 pub type c_uchar = u8;
19 pub type c_short = i16;
20 pub type c_ushort = u16;
21 pub type c_int = i32;
22 pub type c_uint = u32;
23 pub type c_float = f32;
24 pub type c_double = f64;
25 pub type c_longlong = i64;
26 pub type c_ulonglong = u64;
27 pub type intmax_t = i64;
28 pub type uintmax_t = u64;
29 
30 pub type size_t = usize;
31 pub type ptrdiff_t = isize;
32 pub type intptr_t = isize;
33 pub type uintptr_t = usize;
34 pub type ssize_t = isize;
35 
36 pub type pid_t = i32;
37 pub type uid_t = u32;
38 pub type gid_t = u32;
39 pub type in_addr_t = u32;
40 pub type in_port_t = u16;
41 pub type sighandler_t = ::size_t;
42 pub type cc_t = ::c_uchar;
43 
44 pub enum DIR {}
45 pub enum locale_t {}
46 
47 s! {
48     pub struct group {
49         pub gr_name: *mut ::c_char,
50         pub gr_passwd: *mut ::c_char,
51         pub gr_gid: ::gid_t,
52         pub gr_mem: *mut *mut ::c_char,
53     }
54 
55     pub struct utimbuf {
56         pub actime: time_t,
57         pub modtime: time_t,
58     }
59 
60     pub struct timeval {
61         pub tv_sec: time_t,
62         pub tv_usec: suseconds_t,
63     }
64 
65     // linux x32 compatibility
66     // See https://sourceware.org/bugzilla/show_bug.cgi?id=16437
67     pub struct timespec {
68         pub tv_sec: time_t,
69         #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
70         pub tv_nsec: i64,
71         #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
72         pub tv_nsec: ::c_long,
73     }
74 
75     pub struct rlimit {
76         pub rlim_cur: rlim_t,
77         pub rlim_max: rlim_t,
78     }
79 
80     pub struct rusage {
81         pub ru_utime: timeval,
82         pub ru_stime: timeval,
83         pub ru_maxrss: c_long,
84         #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
85         __pad1: u32,
86         pub ru_ixrss: c_long,
87         #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
88         __pad2: u32,
89         pub ru_idrss: c_long,
90         #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
91         __pad3: u32,
92         pub ru_isrss: c_long,
93         #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
94         __pad4: u32,
95         pub ru_minflt: c_long,
96         #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
97         __pad5: u32,
98         pub ru_majflt: c_long,
99         #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
100         __pad6: u32,
101         pub ru_nswap: c_long,
102         #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
103         __pad7: u32,
104         pub ru_inblock: c_long,
105         #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
106         __pad8: u32,
107         pub ru_oublock: c_long,
108         #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
109         __pad9: u32,
110         pub ru_msgsnd: c_long,
111         #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
112         __pad10: u32,
113         pub ru_msgrcv: c_long,
114         #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
115         __pad11: u32,
116         pub ru_nsignals: c_long,
117         #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
118         __pad12: u32,
119         pub ru_nvcsw: c_long,
120         #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
121         __pad13: u32,
122         pub ru_nivcsw: c_long,
123         #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
124         __pad14: u32,
125 
126         #[cfg(any(target_env = "musl", target_os = "emscripten"))]
127         __reserved: [c_long; 16],
128     }
129 
130     #[cfg_attr(target_os = "netbsd", repr(packed))]
131     pub struct in_addr {
132         pub s_addr: in_addr_t,
133     }
134 
135     #[cfg_attr(feature = "align", repr(align(4)))]
136     pub struct in6_addr {
137         pub s6_addr: [u8; 16],
138         #[cfg(not(feature = "align"))]
139         __align: [u32; 0],
140     }
141 
142     pub struct ip_mreq {
143         pub imr_multiaddr: in_addr,
144         pub imr_interface: in_addr,
145     }
146 
147     pub struct ipv6_mreq {
148         pub ipv6mr_multiaddr: in6_addr,
149         #[cfg(target_os = "android")]
150         pub ipv6mr_interface: ::c_int,
151         #[cfg(not(target_os = "android"))]
152         pub ipv6mr_interface: ::c_uint,
153     }
154 
155     pub struct hostent {
156         pub h_name: *mut ::c_char,
157         pub h_aliases: *mut *mut ::c_char,
158         pub h_addrtype: ::c_int,
159         pub h_length: ::c_int,
160         pub h_addr_list: *mut *mut ::c_char,
161     }
162 
163     pub struct iovec {
164         pub iov_base: *mut ::c_void,
165         pub iov_len: ::size_t,
166     }
167 
168     pub struct pollfd {
169         pub fd: ::c_int,
170         pub events: ::c_short,
171         pub revents: ::c_short,
172     }
173 
174     pub struct winsize {
175         pub ws_row: ::c_ushort,
176         pub ws_col: ::c_ushort,
177         pub ws_xpixel: ::c_ushort,
178         pub ws_ypixel: ::c_ushort,
179     }
180 
181     pub struct linger {
182         pub l_onoff: ::c_int,
183         pub l_linger: ::c_int,
184     }
185 
186     pub struct sigval {
187         // Actually a union of an int and a void*
188         pub sival_ptr: *mut ::c_void
189     }
190 
191     // <sys/time.h>
192     pub struct itimerval {
193         pub it_interval: ::timeval,
194         pub it_value: ::timeval,
195     }
196 
197     // <sys/times.h>
198     pub struct tms {
199         pub tms_utime: ::clock_t,
200         pub tms_stime: ::clock_t,
201         pub tms_cutime: ::clock_t,
202         pub tms_cstime: ::clock_t,
203     }
204 
205     pub struct servent {
206         pub s_name: *mut ::c_char,
207         pub s_aliases: *mut *mut ::c_char,
208         pub s_port: ::c_int,
209         pub s_proto: *mut ::c_char,
210     }
211 
212     pub struct protoent {
213         pub p_name: *mut ::c_char,
214         pub p_aliases: *mut *mut ::c_char,
215         pub p_proto: ::c_int,
216     }
217 }
218 
219 pub const INT_MIN: c_int = -2147483648;
220 pub const INT_MAX: c_int = 2147483647;
221 
222 pub const SIG_DFL: sighandler_t = 0 as sighandler_t;
223 pub const SIG_IGN: sighandler_t = 1 as sighandler_t;
224 pub const SIG_ERR: sighandler_t = !0 as sighandler_t;
225 
226 pub const DT_UNKNOWN: u8 = 0;
227 pub const DT_FIFO: u8 = 1;
228 pub const DT_CHR: u8 = 2;
229 pub const DT_DIR: u8 = 4;
230 pub const DT_BLK: u8 = 6;
231 pub const DT_REG: u8 = 8;
232 pub const DT_LNK: u8 = 10;
233 pub const DT_SOCK: u8 = 12;
234 
235 pub const FD_CLOEXEC: ::c_int = 0x1;
236 
237 pub const USRQUOTA: ::c_int = 0;
238 pub const GRPQUOTA: ::c_int = 1;
239 
240 pub const SIGIOT: ::c_int = 6;
241 
242 pub const S_ISUID: ::c_int = 0x800;
243 pub const S_ISGID: ::c_int = 0x400;
244 pub const S_ISVTX: ::c_int = 0x200;
245 
246 pub const IF_NAMESIZE: ::size_t = 16;
247 pub const IFNAMSIZ: ::size_t = IF_NAMESIZE;
248 
249 pub const LOG_EMERG: ::c_int = 0;
250 pub const LOG_ALERT: ::c_int = 1;
251 pub const LOG_CRIT: ::c_int = 2;
252 pub const LOG_ERR: ::c_int = 3;
253 pub const LOG_WARNING: ::c_int = 4;
254 pub const LOG_NOTICE: ::c_int = 5;
255 pub const LOG_INFO: ::c_int = 6;
256 pub const LOG_DEBUG: ::c_int = 7;
257 
258 pub const LOG_KERN: ::c_int = 0;
259 pub const LOG_USER: ::c_int = 1 << 3;
260 pub const LOG_MAIL: ::c_int = 2 << 3;
261 pub const LOG_DAEMON: ::c_int = 3 << 3;
262 pub const LOG_AUTH: ::c_int = 4 << 3;
263 pub const LOG_SYSLOG: ::c_int = 5 << 3;
264 pub const LOG_LPR: ::c_int = 6 << 3;
265 pub const LOG_NEWS: ::c_int = 7 << 3;
266 pub const LOG_UUCP: ::c_int = 8 << 3;
267 pub const LOG_LOCAL0: ::c_int = 16 << 3;
268 pub const LOG_LOCAL1: ::c_int = 17 << 3;
269 pub const LOG_LOCAL2: ::c_int = 18 << 3;
270 pub const LOG_LOCAL3: ::c_int = 19 << 3;
271 pub const LOG_LOCAL4: ::c_int = 20 << 3;
272 pub const LOG_LOCAL5: ::c_int = 21 << 3;
273 pub const LOG_LOCAL6: ::c_int = 22 << 3;
274 pub const LOG_LOCAL7: ::c_int = 23 << 3;
275 
276 pub const LOG_PID: ::c_int = 0x01;
277 pub const LOG_CONS: ::c_int = 0x02;
278 pub const LOG_ODELAY: ::c_int = 0x04;
279 pub const LOG_NDELAY: ::c_int = 0x08;
280 pub const LOG_NOWAIT: ::c_int = 0x10;
281 
282 pub const LOG_PRIMASK: ::c_int = 7;
283 pub const LOG_FACMASK: ::c_int = 0x3f8;
284 
285 pub const PRIO_PROCESS: ::c_int = 0;
286 pub const PRIO_PGRP: ::c_int = 1;
287 pub const PRIO_USER: ::c_int = 2;
288 
289 pub const PRIO_MIN: ::c_int = -20;
290 pub const PRIO_MAX: ::c_int = 20;
291 
292 pub const IPPROTO_ICMP: ::c_int = 1;
293 pub const IPPROTO_ICMPV6: ::c_int = 58;
294 pub const IPPROTO_TCP: ::c_int = 6;
295 pub const IPPROTO_UDP: ::c_int = 17;
296 pub const IPPROTO_IP: ::c_int = 0;
297 pub const IPPROTO_IPV6: ::c_int = 41;
298 
299 pub const INADDR_LOOPBACK: in_addr_t = 2130706433;
300 pub const INADDR_ANY: in_addr_t = 0;
301 pub const INADDR_BROADCAST: in_addr_t = 4294967295;
302 pub const INADDR_NONE: in_addr_t = 4294967295;
303 
304 pub const ARPOP_REQUEST: u16 = 1;
305 pub const ARPOP_REPLY: u16 = 2;
306 
307 pub const ATF_COM: ::c_int = 0x02;
308 pub const ATF_PERM: ::c_int = 0x04;
309 pub const ATF_PUBL: ::c_int = 0x08;
310 pub const ATF_USETRAILERS: ::c_int = 0x10;
311 
312 cfg_if! {
313     if #[cfg(cross_platform_docs)] {
314         // on dox builds don't pull in anything
315     } else if #[cfg(target_os = "l4re")] {
316         // required libraries for L4Re are linked externally, ATM
317     } else if #[cfg(feature = "use_std")] {
318         // cargo build, don't pull in anything extra as the libstd dep
319         // already pulls in all libs.
320     } else if #[cfg(target_env = "musl")] {
321         #[cfg_attr(feature = "rustc-dep-of-std",
322                    link(name = "c", kind = "static",
323                         cfg(target_feature = "crt-static")))]
324         #[cfg_attr(feature = "rustc-dep-of-std",
325                    link(name = "c", cfg(not(target_feature = "crt-static"))))]
326         extern {}
327     } else if #[cfg(target_os = "emscripten")] {
328         #[link(name = "c")]
329         extern {}
330     } else if #[cfg(all(target_os = "netbsd",
331                         feature = "rustc-dep-of-std",
332                         target_vendor = "rumprun"))] {
333         // Since we don't use -nodefaultlibs on Rumprun, libc is always pulled
334         // in automatically by the linker. We avoid passing it explicitly, as it
335         // causes some versions of binutils to crash with an assertion failure.
336         #[link(name = "m")]
337         extern {}
338     } else if #[cfg(any(target_os = "macos",
339                         target_os = "ios",
340                         target_os = "android",
341                         target_os = "openbsd",
342                         target_os = "bitrig"))] {
343         #[link(name = "c")]
344         #[link(name = "m")]
345         extern {}
346     } else if #[cfg(target_os = "haiku")] {
347         #[link(name = "root")]
348         #[link(name = "network")]
349         extern {}
350     } else if #[cfg(target_os = "fuchsia")] {
351         #[link(name = "c")]
352         #[link(name = "fdio")]
353         extern {}
354     } else if #[cfg(target_env = "newlib")] {
355         #[link(name = "c")]
356         #[link(name = "m")]
357         extern {}
358     } else if #[cfg(target_os = "hermit")] {
359         // no_default_libraries is set to false for HermitCore, so only a link
360         // to "pthread" needs to be added.
361         #[link(name = "pthread")]
362         extern {}
363     } else {
364         #[link(name = "c")]
365         #[link(name = "m")]
366         #[link(name = "rt")]
367         #[link(name = "pthread")]
368         extern {}
369     }
370 }
371 
372 pub enum FILE {}
373 pub enum fpos_t {} // TODO: fill this out with a struct
374 
375 extern {
376     pub fn isalnum(c: c_int) -> c_int;
377     pub fn isalpha(c: c_int) -> c_int;
378     pub fn iscntrl(c: c_int) -> c_int;
379     pub fn isdigit(c: c_int) -> c_int;
380     pub fn isgraph(c: c_int) -> c_int;
381     pub fn islower(c: c_int) -> c_int;
382     pub fn isprint(c: c_int) -> c_int;
383     pub fn ispunct(c: c_int) -> c_int;
384     pub fn isspace(c: c_int) -> c_int;
385     pub fn isupper(c: c_int) -> c_int;
386     pub fn isxdigit(c: c_int) -> c_int;
387     pub fn tolower(c: c_int) -> c_int;
388     pub fn toupper(c: c_int) -> c_int;
389     #[cfg_attr(
390         all(target_os = "macos", target_arch = "x86"),
391         link_name = "fopen$UNIX2003"
392     )]
393     pub fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE;
394     #[cfg_attr(
395         all(target_os = "macos", target_arch = "x86"),
396         link_name = "freopen$UNIX2003"
397     )]
398     pub fn freopen(filename: *const c_char, mode: *const c_char,
399                    file: *mut FILE) -> *mut FILE;
400     pub fn fflush(file: *mut FILE) -> c_int;
401     pub fn fclose(file: *mut FILE) -> c_int;
402     pub fn remove(filename: *const c_char) -> c_int;
403     pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int;
404     pub fn tmpfile() -> *mut FILE;
405     pub fn setvbuf(stream: *mut FILE, buffer: *mut c_char, mode: c_int,
406                    size: size_t) -> c_int;
407     pub fn setbuf(stream: *mut FILE, buf: *mut c_char);
408     pub fn getchar() -> c_int;
409     pub fn putchar(c: c_int) -> c_int;
410     pub fn fgetc(stream: *mut FILE) -> c_int;
411     pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char;
412     pub fn fputc(c: c_int, stream: *mut FILE) -> c_int;
413     #[cfg_attr(
414         all(target_os = "macos", target_arch = "x86"),
415         link_name = "fputs$UNIX2003"
416     )]
417     pub fn fputs(s: *const c_char, stream: *mut FILE) -> c_int;
418     pub fn puts(s: *const c_char) -> c_int;
419     pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int;
420     pub fn fread(ptr: *mut c_void, size: size_t, nobj: size_t,
421                  stream: *mut FILE) -> size_t;
422     #[cfg_attr(
423         all(target_os = "macos", target_arch = "x86"),
424         link_name = "fwrite$UNIX2003"
425     )]
426     pub fn fwrite(ptr: *const c_void, size: size_t, nobj: size_t,
427                   stream: *mut FILE) -> size_t;
428     pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int;
429     pub fn ftell(stream: *mut FILE) -> c_long;
430     pub fn rewind(stream: *mut FILE);
431     #[cfg_attr(target_os = "netbsd", link_name = "__fgetpos50")]
432     pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int;
433     #[cfg_attr(target_os = "netbsd", link_name = "__fsetpos50")]
434     pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int;
435     pub fn feof(stream: *mut FILE) -> c_int;
436     pub fn ferror(stream: *mut FILE) -> c_int;
437     pub fn perror(s: *const c_char);
438     pub fn atoi(s: *const c_char) -> c_int;
439     #[cfg_attr(
440         all(target_os = "macos", target_arch = "x86"),
441         link_name = "strtod$UNIX2003"
442     )]
443     pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double;
444     pub fn strtol(s: *const c_char, endp: *mut *mut c_char,
445                   base: c_int) -> c_long;
446     pub fn strtoul(s: *const c_char, endp: *mut *mut c_char,
447                    base: c_int) -> c_ulong;
448     pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void;
449     pub fn malloc(size: size_t) -> *mut c_void;
450     pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
451     pub fn free(p: *mut c_void);
452     pub fn abort() -> !;
453     pub fn exit(status: c_int) -> !;
454     pub fn _exit(status: c_int) -> !;
455     pub fn atexit(cb: extern fn()) -> c_int;
456     #[cfg_attr(
457         all(target_os = "macos", target_arch = "x86"),
458         link_name = "system$UNIX2003"
459     )]
460     pub fn system(s: *const c_char) -> c_int;
461     pub fn getenv(s: *const c_char) -> *mut c_char;
462 
463     pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char;
464     pub fn strncpy(dst: *mut c_char, src: *const c_char,
465                    n: size_t) -> *mut c_char;
466     pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char;
467     pub fn strncat(s: *mut c_char, ct: *const c_char,
468                    n: size_t) -> *mut c_char;
469     pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int;
470     pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int;
471     pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int;
472     pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char;
473     pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char;
474     pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t;
475     pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t;
476     pub fn strdup(cs: *const c_char) -> *mut c_char;
477     pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char;
478     pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
479     pub fn strlen(cs: *const c_char) -> size_t;
480     pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t;
481     #[cfg_attr(
482         all(target_os = "macos", target_arch = "x86"),
483         link_name = "strerror$UNIX2003"
484     )]
485     pub fn strerror(n: c_int) -> *mut c_char;
486     pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char;
487     pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t;
488     pub fn wcslen(buf: *const wchar_t) -> size_t;
489     pub fn wcstombs(dest: *mut c_char, src: *const wchar_t,
490                     n: size_t) -> ::size_t;
491 
492     pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
493     pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int;
494     pub fn memcpy(dest: *mut c_void, src: *const c_void,
495                   n: size_t) -> *mut c_void;
496     pub fn memmove(dest: *mut c_void, src: *const c_void,
497                    n: size_t) -> *mut c_void;
498     pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void;
499 }
500 
501 extern {
502     #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam50")]
503     pub fn getpwnam(name: *const ::c_char) -> *mut passwd;
504     #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid50")]
505     pub fn getpwuid(uid: ::uid_t) -> *mut passwd;
506 
507     pub fn fprintf(stream: *mut ::FILE,
508                    format: *const ::c_char, ...) -> ::c_int;
509     pub fn printf(format: *const ::c_char, ...) -> ::c_int;
510     pub fn snprintf(s: *mut ::c_char, n: ::size_t,
511                     format: *const ::c_char, ...) -> ::c_int;
512     pub fn sprintf(s: *mut ::c_char, format: *const ::c_char, ...) -> ::c_int;
513     pub fn fscanf(stream: *mut ::FILE, format: *const ::c_char, ...) -> ::c_int;
514     pub fn scanf(format: *const ::c_char, ...) -> ::c_int;
515     pub fn sscanf(s: *const ::c_char, format: *const ::c_char, ...) -> ::c_int;
516     pub fn getchar_unlocked() -> ::c_int;
517     pub fn putchar_unlocked(c: ::c_int) -> ::c_int;
518 
519     #[cfg_attr(target_os = "netbsd", link_name = "__socket30")]
520     pub fn socket(domain: ::c_int, ty: ::c_int, protocol: ::c_int) -> ::c_int;
521     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
522                link_name = "connect$UNIX2003")]
523     pub fn connect(socket: ::c_int, address: *const sockaddr,
524                    len: socklen_t) -> ::c_int;
525     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
526                link_name = "listen$UNIX2003")]
527     pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int;
528     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
529                link_name = "accept$UNIX2003")]
530     pub fn accept(socket: ::c_int, address: *mut sockaddr,
531                   address_len: *mut socklen_t) -> ::c_int;
532     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
533                link_name = "getpeername$UNIX2003")]
534     pub fn getpeername(socket: ::c_int, address: *mut sockaddr,
535                        address_len: *mut socklen_t) -> ::c_int;
536     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
537                link_name = "getsockname$UNIX2003")]
538     pub fn getsockname(socket: ::c_int, address: *mut sockaddr,
539                        address_len: *mut socklen_t) -> ::c_int;
540     pub fn setsockopt(socket: ::c_int, level: ::c_int, name: ::c_int,
541                       value: *const ::c_void,
542                       option_len: socklen_t) -> ::c_int;
543     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
544                link_name = "socketpair$UNIX2003")]
545     pub fn socketpair(domain: ::c_int, type_: ::c_int, protocol: ::c_int,
546                       socket_vector: *mut ::c_int) -> ::c_int;
547     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
548                link_name = "sendto$UNIX2003")]
549     pub fn sendto(socket: ::c_int, buf: *const ::c_void, len: ::size_t,
550                   flags: ::c_int, addr: *const sockaddr,
551                   addrlen: socklen_t) -> ::ssize_t;
552     pub fn shutdown(socket: ::c_int, how: ::c_int) -> ::c_int;
553 
554     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
555                link_name = "chmod$UNIX2003")]
556     pub fn chmod(path: *const c_char, mode: mode_t) -> ::c_int;
557     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
558                link_name = "fchmod$UNIX2003")]
559     pub fn fchmod(fd: ::c_int, mode: mode_t) -> ::c_int;
560 
561     #[cfg_attr(target_os = "macos", link_name = "fstat$INODE64")]
562     #[cfg_attr(target_os = "netbsd", link_name = "__fstat50")]
563     #[cfg_attr(target_os = "freebsd", link_name = "fstat@FBSD_1.0")]
564     pub fn fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int;
565 
566     pub fn mkdir(path: *const c_char, mode: mode_t) -> ::c_int;
567 
568     #[cfg_attr(target_os = "macos", link_name = "stat$INODE64")]
569     #[cfg_attr(target_os = "netbsd", link_name = "__stat50")]
570     #[cfg_attr(target_os = "freebsd", link_name = "stat@FBSD_1.0")]
571     pub fn stat(path: *const c_char, buf: *mut stat) -> ::c_int;
572 
573     pub fn pclose(stream: *mut ::FILE) -> ::c_int;
574     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
575                link_name = "fdopen$UNIX2003")]
576     pub fn fdopen(fd: ::c_int, mode: *const c_char) -> *mut ::FILE;
577     pub fn fileno(stream: *mut ::FILE) -> ::c_int;
578 
579     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
580                link_name = "open$UNIX2003")]
581     pub fn open(path: *const c_char, oflag: ::c_int, ...) -> ::c_int;
582     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
583                link_name = "creat$UNIX2003")]
584     pub fn creat(path: *const c_char, mode: mode_t) -> ::c_int;
585     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
586                link_name = "fcntl$UNIX2003")]
587     pub fn fcntl(fd: ::c_int, cmd: ::c_int, ...) -> ::c_int;
588 
589     #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
590                link_name = "opendir$INODE64")]
591     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
592                link_name = "opendir$INODE64$UNIX2003")]
593     #[cfg_attr(target_os = "netbsd", link_name = "__opendir30")]
594     pub fn opendir(dirname: *const c_char) -> *mut ::DIR;
595 
596     #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
597                link_name = "fdopendir$INODE64")]
598     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
599                link_name = "fdopendir$INODE64$UNIX2003")]
600     pub fn fdopendir(fd: ::c_int) -> *mut ::DIR;
601 
602     #[cfg_attr(target_os = "macos", link_name = "readdir$INODE64")]
603     #[cfg_attr(target_os = "netbsd", link_name = "__readdir30")]
604     #[cfg_attr(target_os = "freebsd", link_name = "readdir@FBSD_1.0")]
605     pub fn readdir(dirp: *mut ::DIR) -> *mut ::dirent;
606     #[cfg_attr(target_os = "macos", link_name = "readdir_r$INODE64")]
607     #[cfg_attr(target_os = "netbsd", link_name = "__readdir_r30")]
608     #[cfg_attr(target_os = "solaris", link_name = "__posix_readdir_r")]
609     #[cfg_attr(target_os = "freebsd", link_name = "readdir_r@FBSD_1.0")]
610     pub fn readdir_r(dirp: *mut ::DIR, entry: *mut ::dirent,
611                      result: *mut *mut ::dirent) -> ::c_int;
612     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
613                link_name = "closedir$UNIX2003")]
614     pub fn closedir(dirp: *mut ::DIR) -> ::c_int;
615     #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
616                link_name = "rewinddir$INODE64")]
617     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
618                link_name = "rewinddir$INODE64$UNIX2003")]
619     pub fn rewinddir(dirp: *mut ::DIR);
620 
621     pub fn openat(dirfd: ::c_int, pathname: *const ::c_char,
622                   flags: ::c_int, ...) -> ::c_int;
623     pub fn fchmodat(dirfd: ::c_int, pathname: *const ::c_char,
624                     mode: ::mode_t, flags: ::c_int) -> ::c_int;
625     pub fn fchown(fd: ::c_int,
626                   owner: ::uid_t,
627                   group: ::gid_t) -> ::c_int;
628     pub fn fchownat(dirfd: ::c_int, pathname: *const ::c_char,
629                     owner: ::uid_t, group: ::gid_t,
630                     flags: ::c_int) -> ::c_int;
631     #[cfg_attr(target_os = "macos", link_name = "fstatat$INODE64")]
632     #[cfg_attr(target_os = "freebsd", link_name = "fstatat@FBSD_1.1")]
633     pub fn fstatat(dirfd: ::c_int, pathname: *const ::c_char,
634                    buf: *mut stat, flags: ::c_int) -> ::c_int;
635     pub fn linkat(olddirfd: ::c_int, oldpath: *const ::c_char,
636                   newdirfd: ::c_int, newpath: *const ::c_char,
637                   flags: ::c_int) -> ::c_int;
638     pub fn mkdirat(dirfd: ::c_int, pathname: *const ::c_char,
639                    mode: ::mode_t) -> ::c_int;
640     pub fn readlinkat(dirfd: ::c_int, pathname: *const ::c_char,
641                       buf: *mut ::c_char, bufsiz: ::size_t) -> ::ssize_t;
642     pub fn renameat(olddirfd: ::c_int, oldpath: *const ::c_char,
643                     newdirfd: ::c_int, newpath: *const ::c_char)
644                     -> ::c_int;
645     pub fn symlinkat(target: *const ::c_char, newdirfd: ::c_int,
646                      linkpath: *const ::c_char) -> ::c_int;
647     pub fn unlinkat(dirfd: ::c_int, pathname: *const ::c_char,
648                     flags: ::c_int) -> ::c_int;
649 
650     pub fn access(path: *const c_char, amode: ::c_int) -> ::c_int;
651     pub fn alarm(seconds: ::c_uint) -> ::c_uint;
652     pub fn chdir(dir: *const c_char) -> ::c_int;
653     pub fn fchdir(dirfd: ::c_int) -> ::c_int;
654     pub fn chown(path: *const c_char, uid: uid_t,
655                  gid: gid_t) -> ::c_int;
656     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
657                link_name = "lchown$UNIX2003")]
658     pub fn lchown(path: *const c_char, uid: uid_t,
659                   gid: gid_t) -> ::c_int;
660     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
661                link_name = "close$NOCANCEL$UNIX2003")]
662     #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
663                link_name = "close$NOCANCEL")]
664     pub fn close(fd: ::c_int) -> ::c_int;
665     pub fn dup(fd: ::c_int) -> ::c_int;
666     pub fn dup2(src: ::c_int, dst: ::c_int) -> ::c_int;
667     pub fn execl(path: *const c_char,
668                  arg0: *const c_char, ...) -> ::c_int;
669     pub fn execle(path: *const ::c_char,
670                   arg0: *const ::c_char, ...) -> ::c_int;
671     pub fn execlp(file: *const ::c_char,
672                   arg0: *const ::c_char, ...) -> ::c_int;
673     pub fn execv(prog: *const c_char,
674                  argv: *const *const c_char) -> ::c_int;
675     pub fn execve(prog: *const c_char, argv: *const *const c_char,
676                   envp: *const *const c_char)
677                   -> ::c_int;
678     pub fn execvp(c: *const c_char,
679                   argv: *const *const c_char) -> ::c_int;
680     pub fn fork() -> pid_t;
681     pub fn fpathconf(filedes: ::c_int, name: ::c_int) -> c_long;
682     pub fn getcwd(buf: *mut c_char, size: ::size_t) -> *mut c_char;
683     pub fn getegid() -> gid_t;
684     pub fn geteuid() -> uid_t;
685     pub fn getgid() -> gid_t;
686     pub fn getgroups(ngroups_max: ::c_int, groups: *mut gid_t)
687                      -> ::c_int;
688     pub fn getlogin() -> *mut c_char;
689     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
690                link_name = "getopt$UNIX2003")]
691     pub fn getopt(argc: ::c_int, argv: *const *mut c_char,
692                   optstr: *const c_char) -> ::c_int;
693     pub fn getpgid(pid: pid_t) -> pid_t;
694     pub fn getpgrp() -> pid_t;
695     pub fn getpid() -> pid_t;
696     pub fn getppid() -> pid_t;
697     pub fn getuid() -> uid_t;
698     pub fn isatty(fd: ::c_int) -> ::c_int;
699     pub fn link(src: *const c_char, dst: *const c_char) -> ::c_int;
700     pub fn lseek(fd: ::c_int, offset: off_t, whence: ::c_int) -> off_t;
701     pub fn pathconf(path: *const c_char, name: ::c_int) -> c_long;
702     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
703                link_name = "pause$UNIX2003")]
704     pub fn pause() -> ::c_int;
705     pub fn pipe(fds: *mut ::c_int) -> ::c_int;
706     pub fn posix_memalign(memptr: *mut *mut ::c_void,
707                       align: ::size_t,
708                       size: ::size_t) -> ::c_int;
709     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
710                link_name = "read$UNIX2003")]
711     pub fn read(fd: ::c_int, buf: *mut ::c_void, count: ::size_t)
712                 -> ::ssize_t;
713     pub fn rmdir(path: *const c_char) -> ::c_int;
714     pub fn seteuid(uid: uid_t) -> ::c_int;
715     pub fn setgid(gid: gid_t) -> ::c_int;
716     pub fn setpgid(pid: pid_t, pgid: pid_t) -> ::c_int;
717     pub fn setsid() -> pid_t;
718     pub fn setuid(uid: uid_t) -> ::c_int;
719     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
720                link_name = "sleep$UNIX2003")]
721     pub fn sleep(secs: ::c_uint) -> ::c_uint;
722     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
723                link_name = "nanosleep$UNIX2003")]
724     #[cfg_attr(target_os = "netbsd", link_name = "__nanosleep50")]
725     pub fn nanosleep(rqtp: *const timespec,
726                      rmtp: *mut timespec) -> ::c_int;
727     pub fn tcgetpgrp(fd: ::c_int) -> pid_t;
728     pub fn tcsetpgrp(fd: ::c_int, pgrp: ::pid_t) -> ::c_int;
729     pub fn ttyname(fd: ::c_int) -> *mut c_char;
730     pub fn unlink(c: *const c_char) -> ::c_int;
731     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
732                link_name = "wait$UNIX2003")]
733     pub fn wait(status: *mut ::c_int) -> pid_t;
734     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
735                link_name = "waitpid$UNIX2003")]
736     pub fn waitpid(pid: pid_t, status: *mut ::c_int, options: ::c_int)
737                    -> pid_t;
738     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
739                link_name = "write$UNIX2003")]
740     pub fn write(fd: ::c_int, buf: *const ::c_void, count: ::size_t)
741                  -> ::ssize_t;
742     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
743                link_name = "pread$UNIX2003")]
744     pub fn pread(fd: ::c_int, buf: *mut ::c_void, count: ::size_t,
745                  offset: off_t) -> ::ssize_t;
746     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
747                link_name = "pwrite$UNIX2003")]
748     pub fn pwrite(fd: ::c_int, buf: *const ::c_void, count: ::size_t,
749                   offset: off_t) -> ::ssize_t;
750     pub fn umask(mask: mode_t) -> mode_t;
751 
752     #[cfg_attr(target_os = "netbsd", link_name = "__utime50")]
753     pub fn utime(file: *const c_char, buf: *const utimbuf) -> ::c_int;
754 
755     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
756                    link_name = "kill$UNIX2003")]
757     pub fn kill(pid: pid_t, sig: ::c_int) -> ::c_int;
758     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
759                link_name = "killpg$UNIX2003")]
760     pub fn killpg(pgrp: pid_t, sig: ::c_int) -> ::c_int;
761 
762     pub fn mlock(addr: *const ::c_void, len: ::size_t) -> ::c_int;
763     pub fn munlock(addr: *const ::c_void, len: ::size_t) -> ::c_int;
764     pub fn mlockall(flags: ::c_int) -> ::c_int;
765     pub fn munlockall() -> ::c_int;
766 
767     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
768                link_name = "mmap$UNIX2003")]
769     pub fn mmap(addr: *mut ::c_void,
770                 len: ::size_t,
771                 prot: ::c_int,
772                 flags: ::c_int,
773                 fd: ::c_int,
774                 offset: off_t)
775                 -> *mut ::c_void;
776     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
777                link_name = "munmap$UNIX2003")]
778     pub fn munmap(addr: *mut ::c_void, len: ::size_t) -> ::c_int;
779 
780     pub fn if_nametoindex(ifname: *const c_char) -> ::c_uint;
781     pub fn if_indextoname(ifindex: ::c_uint,
782                           ifname: *mut ::c_char) -> *mut ::c_char;
783 
784     #[cfg_attr(target_os = "macos", link_name = "lstat$INODE64")]
785     #[cfg_attr(target_os = "netbsd", link_name = "__lstat50")]
786     #[cfg_attr(target_os = "freebsd", link_name = "lstat@FBSD_1.0")]
787     pub fn lstat(path: *const c_char, buf: *mut stat) -> ::c_int;
788 
789     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
790                link_name = "fsync$UNIX2003")]
791     pub fn fsync(fd: ::c_int) -> ::c_int;
792 
793     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
794                link_name = "setenv$UNIX2003")]
795     pub fn setenv(name: *const c_char, val: *const c_char,
796                   overwrite: ::c_int) -> ::c_int;
797     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
798                link_name = "unsetenv$UNIX2003")]
799     #[cfg_attr(target_os = "netbsd", link_name = "__unsetenv13")]
800     pub fn unsetenv(name: *const c_char) -> ::c_int;
801 
802     pub fn symlink(path1: *const c_char,
803                    path2: *const c_char) -> ::c_int;
804 
805     pub fn truncate(path: *const c_char, length: off_t) -> ::c_int;
806     pub fn ftruncate(fd: ::c_int, length: off_t) -> ::c_int;
807 
808     pub fn signal(signum: ::c_int, handler: sighandler_t) -> sighandler_t;
809 
810     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
811                link_name = "getrlimit$UNIX2003")]
812     pub fn getrlimit(resource: ::c_int, rlim: *mut rlimit) -> ::c_int;
813     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
814                link_name = "setrlimit$UNIX2003")]
815     pub fn setrlimit(resource: ::c_int, rlim: *const rlimit) -> ::c_int;
816     #[cfg_attr(target_os = "netbsd", link_name = "__getrusage50")]
817     pub fn getrusage(resource: ::c_int, usage: *mut rusage) -> ::c_int;
818 
819     #[cfg_attr(any(target_os = "macos", target_os = "ios"),
820                link_name = "realpath$DARWIN_EXTSN")]
821     pub fn realpath(pathname: *const ::c_char, resolved: *mut ::c_char)
822                     -> *mut ::c_char;
823 
824     pub fn flock(fd: ::c_int, operation: ::c_int) -> ::c_int;
825 
826     #[cfg_attr(target_os = "netbsd", link_name = "__gettimeofday50")]
827     pub fn gettimeofday(tp: *mut ::timeval,
828                         tz: *mut ::c_void) -> ::c_int;
829     #[cfg_attr(target_os = "netbsd", link_name = "__times13")]
830     pub fn times(buf: *mut ::tms) -> ::clock_t;
831 
832     pub fn pthread_self() -> ::pthread_t;
833     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
834                link_name = "pthread_join$UNIX2003")]
835     pub fn pthread_join(native: ::pthread_t,
836                         value: *mut *mut ::c_void) -> ::c_int;
837     pub fn pthread_exit(value: *mut ::c_void);
838     pub fn pthread_attr_init(attr: *mut ::pthread_attr_t) -> ::c_int;
839     pub fn pthread_attr_destroy(attr: *mut ::pthread_attr_t) -> ::c_int;
840     pub fn pthread_attr_setstacksize(attr: *mut ::pthread_attr_t,
841                                      stack_size: ::size_t) -> ::c_int;
842     pub fn pthread_attr_setdetachstate(attr: *mut ::pthread_attr_t,
843                                        state: ::c_int) -> ::c_int;
844     pub fn pthread_detach(thread: ::pthread_t) -> ::c_int;
845     #[cfg_attr(target_os = "netbsd", link_name = "__libc_thr_yield")]
846     pub fn sched_yield() -> ::c_int;
847     pub fn pthread_key_create(key: *mut pthread_key_t,
848                               dtor: Option<unsafe extern fn(*mut ::c_void)>)
849                               -> ::c_int;
850     pub fn pthread_key_delete(key: pthread_key_t) -> ::c_int;
851     pub fn pthread_getspecific(key: pthread_key_t) -> *mut ::c_void;
852     pub fn pthread_setspecific(key: pthread_key_t, value: *const ::c_void)
853                                -> ::c_int;
854     pub fn pthread_mutex_init(lock: *mut pthread_mutex_t,
855                               attr: *const pthread_mutexattr_t) -> ::c_int;
856     pub fn pthread_mutex_destroy(lock: *mut pthread_mutex_t) -> ::c_int;
857     pub fn pthread_mutex_lock(lock: *mut pthread_mutex_t) -> ::c_int;
858     pub fn pthread_mutex_trylock(lock: *mut pthread_mutex_t) -> ::c_int;
859     pub fn pthread_mutex_unlock(lock: *mut pthread_mutex_t) -> ::c_int;
860 
861     pub fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> ::c_int;
862     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
863                link_name = "pthread_mutexattr_destroy$UNIX2003")]
864     pub fn pthread_mutexattr_destroy(attr: *mut pthread_mutexattr_t) -> ::c_int;
865     pub fn pthread_mutexattr_settype(attr: *mut pthread_mutexattr_t,
866                                      _type: ::c_int) -> ::c_int;
867 
868     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
869                link_name = "pthread_cond_init$UNIX2003")]
870     pub fn pthread_cond_init(cond: *mut pthread_cond_t,
871                              attr: *const pthread_condattr_t) -> ::c_int;
872     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
873                link_name = "pthread_cond_wait$UNIX2003")]
874     pub fn pthread_cond_wait(cond: *mut pthread_cond_t,
875                              lock: *mut pthread_mutex_t) -> ::c_int;
876     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
877                link_name = "pthread_cond_timedwait$UNIX2003")]
878     pub fn pthread_cond_timedwait(cond: *mut pthread_cond_t,
879                               lock: *mut pthread_mutex_t,
880                               abstime: *const ::timespec) -> ::c_int;
881     pub fn pthread_cond_signal(cond: *mut pthread_cond_t) -> ::c_int;
882     pub fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> ::c_int;
883     pub fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> ::c_int;
884     pub fn pthread_condattr_init(attr: *mut pthread_condattr_t) -> ::c_int;
885     pub fn pthread_condattr_destroy(attr: *mut pthread_condattr_t) -> ::c_int;
886     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
887                link_name = "pthread_rwlock_init$UNIX2003")]
888     pub fn pthread_rwlock_init(lock: *mut pthread_rwlock_t,
889                                attr: *const pthread_rwlockattr_t) -> ::c_int;
890     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
891                link_name = "pthread_rwlock_destroy$UNIX2003")]
892     pub fn pthread_rwlock_destroy(lock: *mut pthread_rwlock_t) -> ::c_int;
893     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
894                link_name = "pthread_rwlock_rdlock$UNIX2003")]
895     pub fn pthread_rwlock_rdlock(lock: *mut pthread_rwlock_t) -> ::c_int;
896     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
897                link_name = "pthread_rwlock_tryrdlock$UNIX2003")]
898     pub fn pthread_rwlock_tryrdlock(lock: *mut pthread_rwlock_t) -> ::c_int;
899     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
900                link_name = "pthread_rwlock_wrlock$UNIX2003")]
901     pub fn pthread_rwlock_wrlock(lock: *mut pthread_rwlock_t) -> ::c_int;
902     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
903                link_name = "pthread_rwlock_trywrlock$UNIX2003")]
904     pub fn pthread_rwlock_trywrlock(lock: *mut pthread_rwlock_t) -> ::c_int;
905     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
906                link_name = "pthread_rwlock_unlock$UNIX2003")]
907     pub fn pthread_rwlock_unlock(lock: *mut pthread_rwlock_t) -> ::c_int;
908     pub fn pthread_rwlockattr_init(attr: *mut pthread_rwlockattr_t) -> ::c_int;
909     pub fn pthread_rwlockattr_destroy(attr: *mut pthread_rwlockattr_t)
910                                       -> ::c_int;
911     #[cfg_attr(all(target_os = "linux", not(target_env = "musl")),
912                link_name = "__xpg_strerror_r")]
913     pub fn strerror_r(errnum: ::c_int, buf: *mut c_char,
914                       buflen: ::size_t) -> ::c_int;
915 
916     pub fn getsockopt(sockfd: ::c_int,
917                       level: ::c_int,
918                       optname: ::c_int,
919                       optval: *mut ::c_void,
920                       optlen: *mut ::socklen_t) -> ::c_int;
921     pub fn raise(signum: ::c_int) -> ::c_int;
922     #[cfg_attr(target_os = "netbsd", link_name = "__sigaction14")]
923     pub fn sigaction(signum: ::c_int,
924                      act: *const sigaction,
925                      oldact: *mut sigaction) -> ::c_int;
926 
927     #[cfg_attr(target_os = "netbsd", link_name = "__utimes50")]
928     pub fn utimes(filename: *const ::c_char,
929                   times: *const ::timeval) -> ::c_int;
930     pub fn dlopen(filename: *const ::c_char,
931                   flag: ::c_int) -> *mut ::c_void;
932     pub fn dlerror() -> *mut ::c_char;
933     pub fn dlsym(handle: *mut ::c_void,
934                  symbol: *const ::c_char) -> *mut ::c_void;
935     pub fn dlclose(handle: *mut ::c_void) -> ::c_int;
936     pub fn dladdr(addr: *const ::c_void, info: *mut Dl_info) -> ::c_int;
937 
938     pub fn getaddrinfo(node: *const c_char,
939                        service: *const c_char,
940                        hints: *const addrinfo,
941                        res: *mut *mut addrinfo) -> ::c_int;
942     pub fn freeaddrinfo(res: *mut addrinfo);
943     pub fn gai_strerror(errcode: ::c_int) -> *const ::c_char;
944     #[cfg_attr(any(
945                    all(target_os = "linux", not(target_env = "musl")),
946                    target_os = "freebsd",
947                    target_os = "dragonfly",
948                    target_os = "haiku"),
949                link_name = "__res_init")]
950     #[cfg_attr(any(target_os = "macos", target_os = "ios"),
951                link_name = "res_9_init")]
952     pub fn res_init() -> ::c_int;
953 
954     #[cfg_attr(target_os = "netbsd", link_name = "__gmtime_r50")]
955     pub fn gmtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm;
956     #[cfg_attr(target_os = "netbsd", link_name = "__localtime_r50")]
957     pub fn localtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm;
958     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
959                link_name = "mktime$UNIX2003")]
960     #[cfg_attr(target_os = "netbsd", link_name = "__mktime50")]
961     pub fn mktime(tm: *mut tm) -> time_t;
962     #[cfg_attr(target_os = "netbsd", link_name = "__time50")]
963     pub fn time(time: *mut time_t) -> time_t;
964     #[cfg_attr(target_os = "netbsd", link_name = "__gmtime50")]
965     pub fn gmtime(time_p: *const time_t) -> *mut tm;
966     #[cfg_attr(target_os = "netbsd", link_name = "__locatime50")]
967     pub fn localtime(time_p: *const time_t) -> *mut tm;
968     #[cfg_attr(target_os = "netbsd", link_name = "__difftime50")]
969     pub fn difftime(time1: time_t, time0: time_t) -> ::c_double;
970 
971     #[cfg_attr(target_os = "netbsd", link_name = "__mknod50")]
972     #[cfg_attr(target_os = "freebsd", link_name = "mknod@FBSD_1.0")]
973     pub fn mknod(pathname: *const ::c_char, mode: ::mode_t,
974                  dev: ::dev_t) -> ::c_int;
975     pub fn uname(buf: *mut ::utsname) -> ::c_int;
976     pub fn gethostname(name: *mut ::c_char, len: ::size_t) -> ::c_int;
977     pub fn getservbyname(name: *const ::c_char,
978                          proto: *const ::c_char) -> *mut servent;
979     pub fn getprotobyname(name: *const ::c_char) -> *mut protoent;
980     pub fn getprotobynumber(proto: ::c_int) -> *mut protoent;
981     pub fn chroot(name: *const ::c_char) -> ::c_int;
982     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
983                link_name = "usleep$UNIX2003")]
984     pub fn usleep(secs: ::c_uint) -> ::c_int;
985     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
986                link_name = "send$UNIX2003")]
987     pub fn send(socket: ::c_int, buf: *const ::c_void, len: ::size_t,
988                 flags: ::c_int) -> ::ssize_t;
989     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
990                link_name = "recv$UNIX2003")]
991     pub fn recv(socket: ::c_int, buf: *mut ::c_void, len: ::size_t,
992                 flags: ::c_int) -> ::ssize_t;
993     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
994                link_name = "putenv$UNIX2003")]
995     #[cfg_attr(target_os = "netbsd", link_name = "__putenv50")]
996     pub fn putenv(string: *mut c_char) -> ::c_int;
997     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
998                link_name = "poll$UNIX2003")]
999     pub fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: ::c_int) -> ::c_int;
1000     #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
1001                link_name = "select$1050")]
1002     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
1003                link_name = "select$UNIX2003")]
1004     #[cfg_attr(target_os = "netbsd", link_name = "__select50")]
1005     pub fn select(nfds: ::c_int,
1006                   readfs: *mut fd_set,
1007                   writefds: *mut fd_set,
1008                   errorfds: *mut fd_set,
1009                   timeout: *mut timeval) -> ::c_int;
1010     #[cfg_attr(target_os = "netbsd", link_name = "__setlocale50")]
1011     pub fn setlocale(category: ::c_int,
1012                      locale: *const ::c_char) -> *mut ::c_char;
1013     pub fn localeconv() -> *mut lconv;
1014 
1015     pub fn sem_destroy(sem: *mut sem_t) -> ::c_int;
1016     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
1017                link_name = "sem_wait$UNIX2003")]
1018     pub fn sem_wait(sem: *mut sem_t) -> ::c_int;
1019     pub fn sem_trywait(sem: *mut sem_t) -> ::c_int;
1020     pub fn sem_post(sem: *mut sem_t) -> ::c_int;
1021     pub fn sem_init(sem: *mut sem_t,
1022                     pshared: ::c_int,
1023                     value: ::c_uint)
1024                     -> ::c_int;
1025     pub fn statvfs(path: *const c_char, buf: *mut statvfs) -> ::c_int;
1026     pub fn fstatvfs(fd: ::c_int, buf: *mut statvfs) -> ::c_int;
1027 
1028     pub fn readlink(path: *const c_char,
1029                     buf: *mut c_char,
1030                     bufsz: ::size_t)
1031                     -> ::ssize_t;
1032 
1033     #[cfg_attr(target_os = "netbsd", link_name = "__sigemptyset14")]
1034     pub fn sigemptyset(set: *mut sigset_t) -> ::c_int;
1035     #[cfg_attr(target_os = "netbsd", link_name = "__sigaddset14")]
1036     pub fn sigaddset(set: *mut sigset_t, signum: ::c_int) -> ::c_int;
1037     #[cfg_attr(target_os = "netbsd", link_name = "__sigfillset14")]
1038     pub fn sigfillset(set: *mut sigset_t) -> ::c_int;
1039     #[cfg_attr(target_os = "netbsd", link_name = "__sigdelset14")]
1040     pub fn sigdelset(set: *mut sigset_t, signum: ::c_int) -> ::c_int;
1041     #[cfg_attr(target_os = "netbsd", link_name = "__sigismember14")]
1042     pub fn sigismember(set: *const sigset_t, signum: ::c_int) -> ::c_int;
1043 
1044     #[cfg_attr(target_os = "netbsd", link_name = "__sigprocmask14")]
1045     pub fn sigprocmask(how: ::c_int,
1046                        set: *const sigset_t,
1047                        oldset: *mut sigset_t)
1048                        -> ::c_int;
1049     #[cfg_attr(target_os = "netbsd", link_name = "__sigpending14")]
1050     pub fn sigpending(set: *mut sigset_t) -> ::c_int;
1051 
1052     #[cfg_attr(target_os = "netbsd", link_name = "__timegm50")]
1053     pub fn timegm(tm: *mut ::tm) -> time_t;
1054 
1055     pub fn getsid(pid: pid_t) -> pid_t;
1056 
1057     pub fn sysconf(name: ::c_int) -> ::c_long;
1058 
1059     pub fn mkfifo(path: *const c_char, mode: mode_t) -> ::c_int;
1060 
1061     #[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
1062                link_name = "pselect$1050")]
1063     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
1064                link_name = "pselect$UNIX2003")]
1065     #[cfg_attr(target_os = "netbsd", link_name = "__pselect50")]
1066     pub fn pselect(nfds: ::c_int,
1067                    readfs: *mut fd_set,
1068                    writefds: *mut fd_set,
1069                    errorfds: *mut fd_set,
1070                    timeout: *const timespec,
1071                    sigmask: *const sigset_t) -> ::c_int;
1072     pub fn fseeko(stream: *mut ::FILE,
1073                   offset: ::off_t,
1074                   whence: ::c_int) -> ::c_int;
1075     pub fn ftello(stream: *mut ::FILE) -> ::off_t;
1076     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
1077                link_name = "tcdrain$UNIX2003")]
1078     pub fn tcdrain(fd: ::c_int) -> ::c_int;
1079     pub fn cfgetispeed(termios: *const ::termios) -> ::speed_t;
1080     pub fn cfgetospeed(termios: *const ::termios) -> ::speed_t;
1081     pub fn cfmakeraw(termios: *mut ::termios);
1082     pub fn cfsetispeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int;
1083     pub fn cfsetospeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int;
1084     pub fn cfsetspeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int;
1085     pub fn tcgetattr(fd: ::c_int, termios: *mut ::termios) -> ::c_int;
1086     pub fn tcsetattr(fd: ::c_int,
1087                      optional_actions: ::c_int,
1088                      termios: *const ::termios) -> ::c_int;
1089     pub fn tcflow(fd: ::c_int, action: ::c_int) -> ::c_int;
1090     pub fn tcflush(fd: ::c_int, action: ::c_int) -> ::c_int;
1091     pub fn tcgetsid(fd: ::c_int) -> ::pid_t;
1092     pub fn tcsendbreak(fd: ::c_int, duration: ::c_int) -> ::c_int;
1093     pub fn mkstemp(template: *mut ::c_char) -> ::c_int;
1094     pub fn mkdtemp(template: *mut ::c_char) -> *mut ::c_char;
1095 
1096     pub fn tmpnam(ptr: *mut ::c_char) -> *mut ::c_char;
1097 
1098     pub fn openlog(ident: *const ::c_char, logopt: ::c_int, facility: ::c_int);
1099     pub fn closelog();
1100     pub fn setlogmask(maskpri: ::c_int) -> ::c_int;
1101     #[cfg_attr(target_os = "macos", link_name = "syslog$DARWIN_EXTSN")]
1102     pub fn syslog(priority: ::c_int, message: *const ::c_char, ...);
1103     #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
1104                link_name = "nice$UNIX2003")]
1105     pub fn nice(incr: ::c_int) -> ::c_int;
1106 
1107     pub fn grantpt(fd: ::c_int) -> ::c_int;
1108     pub fn posix_openpt(flags: ::c_int) -> ::c_int;
1109     pub fn ptsname(fd: ::c_int) -> *mut ::c_char;
1110     pub fn unlockpt(fd: ::c_int) -> ::c_int;
1111 }
1112 
1113 cfg_if! {
1114     if #[cfg(target_env = "uclibc")] {
1115         mod uclibc;
1116         pub use self::uclibc::*;
1117     } else if #[cfg(target_env = "newlib")] {
1118         mod newlib;
1119         pub use self::newlib::*;
1120     } else if #[cfg(any(target_os = "linux",
1121                         target_os = "android",
1122                         target_os = "emscripten",
1123                         target_os = "fuchsia"))] {
1124         mod notbsd;
1125         pub use self::notbsd::*;
1126     } else if #[cfg(any(target_os = "macos",
1127                         target_os = "ios",
1128                         target_os = "freebsd",
1129                         target_os = "dragonfly",
1130                         target_os = "openbsd",
1131                         target_os = "netbsd",
1132                         target_os = "bitrig"))] {
1133         mod bsd;
1134         pub use self::bsd::*;
1135     } else if #[cfg(target_os = "solaris")] {
1136         mod solaris;
1137         pub use self::solaris::*;
1138     } else if #[cfg(target_os = "haiku")] {
1139         mod haiku;
1140         pub use self::haiku::*;
1141     } else if #[cfg(target_os = "hermit")] {
1142         mod hermit;
1143         pub use self::hermit::*;
1144     } else {
1145         // Unknown target_os
1146     }
1147 }
1148 
1149 cfg_if! {
1150     if #[cfg(core_cvoid)] {
1151         pub use core::ffi::c_void;
1152     } else {
1153         // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help
1154         // enable more optimization opportunities around it recognizing things
1155         // like malloc/free.
1156         #[repr(u8)]
1157         pub enum c_void {
1158             // Two dummy variants so the #[repr] attribute can be used.
1159             #[doc(hidden)]
1160             __variant1,
1161             #[doc(hidden)]
1162             __variant2,
1163         }
1164     }
1165 }
1166