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