libc/unix/
mod.rs

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