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
6use crate::prelude::*;
7
8pub type intmax_t = i64;
9pub type uintmax_t = u64;
10
11pub type size_t = usize;
12pub type ptrdiff_t = isize;
13pub type intptr_t = isize;
14pub type uintptr_t = usize;
15pub type ssize_t = isize;
16
17pub type pid_t = i32;
18pub type in_addr_t = u32;
19pub type in_port_t = u16;
20pub type sighandler_t = size_t;
21pub type cc_t = c_uchar;
22
23cfg_if! {
24    if #[cfg(any(
25        target_os = "espidf",
26        target_os = "horizon",
27        target_os = "vita"
28    ))] {
29        pub type uid_t = c_ushort;
30        pub type gid_t = c_ushort;
31    } else if #[cfg(target_os = "nto")] {
32        pub type uid_t = i32;
33        pub type gid_t = i32;
34    } else {
35        pub type uid_t = u32;
36        pub type gid_t = u32;
37    }
38}
39
40extern_ty! {
41    pub enum DIR {}
42}
43
44#[cfg(not(target_os = "nuttx"))]
45pub type locale_t = *mut c_void;
46
47s! {
48    pub struct group {
49        pub gr_name: *mut c_char,
50        pub gr_passwd: *mut c_char,
51        pub gr_gid: crate::gid_t,
52        pub gr_mem: *mut *mut c_char,
53    }
54
55    pub struct utimbuf {
56        pub actime: time_t,
57        pub modtime: time_t,
58    }
59
60    pub struct timeval {
61        pub tv_sec: time_t,
62        #[cfg(not(gnu_time_bits64))]
63        pub tv_usec: crate::suseconds_t,
64        // For 64 bit time on 32 bit linux glibc, suseconds_t is still
65        // a 32 bit type.  Use __suseconds64_t instead
66        #[cfg(gnu_time_bits64)]
67        pub tv_usec: __suseconds64_t,
68    }
69
70    // linux x32 compatibility
71    // See https://sourceware.org/bugzilla/show_bug.cgi?id=16437
72    #[cfg(all(not(target_env = "gnu"), not(target_os = "aix")))]
73    pub struct timespec {
74        pub tv_sec: time_t,
75        #[cfg(all(musl32_time64, target_endian = "big"))]
76        __pad0: Padding<u32>,
77        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
78        pub tv_nsec: i64,
79        #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
80        pub tv_nsec: c_long,
81        #[cfg(all(musl32_time64, target_endian = "little"))]
82        __pad0: Padding<u32>,
83    }
84
85    pub struct rlimit {
86        pub rlim_cur: rlim_t,
87        pub rlim_max: rlim_t,
88    }
89
90    pub struct rusage {
91        pub ru_utime: timeval,
92        pub ru_stime: timeval,
93        pub ru_maxrss: c_long,
94        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
95        __pad1: Padding<u32>,
96        pub ru_ixrss: c_long,
97        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
98        __pad2: Padding<u32>,
99        pub ru_idrss: c_long,
100        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
101        __pad3: Padding<u32>,
102        pub ru_isrss: c_long,
103        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
104        __pad4: Padding<u32>,
105        pub ru_minflt: c_long,
106        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
107        __pad5: Padding<u32>,
108        pub ru_majflt: c_long,
109        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
110        __pad6: Padding<u32>,
111        pub ru_nswap: c_long,
112        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
113        __pad7: Padding<u32>,
114        pub ru_inblock: c_long,
115        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
116        __pad8: Padding<u32>,
117        pub ru_oublock: c_long,
118        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
119        __pad9: Padding<u32>,
120        pub ru_msgsnd: c_long,
121        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
122        __pad10: Padding<u32>,
123        pub ru_msgrcv: c_long,
124        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
125        __pad11: Padding<u32>,
126        pub ru_nsignals: c_long,
127        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
128        __pad12: Padding<u32>,
129        pub ru_nvcsw: c_long,
130        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
131        __pad13: Padding<u32>,
132        pub ru_nivcsw: c_long,
133        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
134        __pad14: Padding<u32>,
135
136        #[cfg(any(target_env = "musl", target_env = "ohos", target_os = "emscripten"))]
137        __reserved: Padding<[c_long; 16]>,
138    }
139
140    #[cfg(not(target_os = "nuttx"))]
141    pub struct ipv6_mreq {
142        pub ipv6mr_multiaddr: in6_addr,
143        #[cfg(target_os = "android")]
144        pub ipv6mr_interface: c_int,
145        #[cfg(not(target_os = "android"))]
146        pub ipv6mr_interface: c_uint,
147    }
148
149    #[cfg(all(not(target_os = "cygwin"), not(target_os = "horizon")))]
150    pub struct hostent {
151        pub h_name: *mut c_char,
152        pub h_aliases: *mut *mut c_char,
153        pub h_addrtype: c_int,
154        pub h_length: c_int,
155        pub h_addr_list: *mut *mut c_char,
156    }
157
158    pub struct iovec {
159        pub iov_base: *mut c_void,
160        pub iov_len: size_t,
161    }
162
163    #[cfg(not(target_os = "horizon"))]
164    pub struct pollfd {
165        pub fd: c_int,
166        pub events: c_short,
167        pub revents: c_short,
168    }
169
170    pub struct winsize {
171        pub ws_row: c_ushort,
172        pub ws_col: c_ushort,
173        pub ws_xpixel: c_ushort,
174        pub ws_ypixel: c_ushort,
175    }
176
177    #[cfg(not(target_os = "cygwin"))]
178    pub struct linger {
179        pub l_onoff: c_int,
180        pub l_linger: c_int,
181    }
182
183    pub struct sigval {
184        // Actually a union of an int and a void*
185        pub sival_ptr: *mut c_void,
186    }
187
188    // <sys/time.h>
189    pub struct itimerval {
190        pub it_interval: crate::timeval,
191        pub it_value: crate::timeval,
192    }
193
194    // <sys/times.h>
195    pub struct tms {
196        pub tms_utime: crate::clock_t,
197        pub tms_stime: crate::clock_t,
198        pub tms_cutime: crate::clock_t,
199        pub tms_cstime: crate::clock_t,
200    }
201
202    pub struct servent {
203        pub s_name: *mut c_char,
204        pub s_aliases: *mut *mut c_char,
205        #[cfg(target_os = "cygwin")]
206        pub s_port: c_short,
207        #[cfg(not(target_os = "cygwin"))]
208        pub s_port: c_int,
209        pub s_proto: *mut c_char,
210    }
211
212    pub struct protoent {
213        pub p_name: *mut c_char,
214        pub p_aliases: *mut *mut c_char,
215        #[cfg(not(target_os = "cygwin"))]
216        pub p_proto: c_int,
217        #[cfg(target_os = "cygwin")]
218        pub p_proto: c_short,
219    }
220
221    #[repr(align(4))]
222    pub struct in6_addr {
223        pub s6_addr: [u8; 16],
224    }
225}
226
227pub const INT_MIN: c_int = -2147483648;
228pub const INT_MAX: c_int = 2147483647;
229
230pub const SIG_DFL: sighandler_t = 0 as sighandler_t;
231pub const SIG_IGN: sighandler_t = 1 as sighandler_t;
232pub const SIG_ERR: sighandler_t = !0 as sighandler_t;
233
234cfg_if! {
235    if #[cfg(all(not(target_os = "nto"), not(target_os = "aix")))] {
236        pub const DT_UNKNOWN: u8 = 0;
237        pub const DT_FIFO: u8 = 1;
238        pub const DT_CHR: u8 = 2;
239        pub const DT_DIR: u8 = 4;
240        pub const DT_BLK: u8 = 6;
241        pub const DT_REG: u8 = 8;
242        pub const DT_LNK: u8 = 10;
243        pub const DT_SOCK: u8 = 12;
244    }
245}
246cfg_if! {
247    if #[cfg(not(target_os = "redox"))] {
248        pub const FD_CLOEXEC: c_int = 0x1;
249    }
250}
251
252cfg_if! {
253    if #[cfg(not(any(target_os = "nto", target_os = "l4re")))] {
254        pub const USRQUOTA: c_int = 0;
255        pub const GRPQUOTA: c_int = 1;
256    }
257}
258pub const SIGIOT: c_int = 6;
259
260pub const S_ISUID: mode_t = 0o4000;
261pub const S_ISGID: mode_t = 0o2000;
262pub const S_ISVTX: mode_t = 0o1000;
263
264cfg_if! {
265    if #[cfg(not(any(
266        target_os = "haiku",
267        target_os = "illumos",
268        target_os = "solaris",
269        target_os = "cygwin"
270    )))] {
271        pub const IF_NAMESIZE: size_t = 16;
272        pub const IFNAMSIZ: size_t = IF_NAMESIZE;
273    }
274}
275
276pub const LOG_EMERG: c_int = 0;
277pub const LOG_ALERT: c_int = 1;
278pub const LOG_CRIT: c_int = 2;
279pub const LOG_ERR: c_int = 3;
280pub const LOG_WARNING: c_int = 4;
281pub const LOG_NOTICE: c_int = 5;
282pub const LOG_INFO: c_int = 6;
283pub const LOG_DEBUG: c_int = 7;
284
285pub const LOG_KERN: c_int = 0;
286pub const LOG_USER: c_int = 1 << 3;
287pub const LOG_MAIL: c_int = 2 << 3;
288pub const LOG_DAEMON: c_int = 3 << 3;
289pub const LOG_AUTH: c_int = 4 << 3;
290pub const LOG_SYSLOG: c_int = 5 << 3;
291pub const LOG_LPR: c_int = 6 << 3;
292pub const LOG_NEWS: c_int = 7 << 3;
293pub const LOG_UUCP: c_int = 8 << 3;
294pub const LOG_LOCAL0: c_int = 16 << 3;
295pub const LOG_LOCAL1: c_int = 17 << 3;
296pub const LOG_LOCAL2: c_int = 18 << 3;
297pub const LOG_LOCAL3: c_int = 19 << 3;
298pub const LOG_LOCAL4: c_int = 20 << 3;
299pub const LOG_LOCAL5: c_int = 21 << 3;
300pub const LOG_LOCAL6: c_int = 22 << 3;
301pub const LOG_LOCAL7: c_int = 23 << 3;
302
303cfg_if! {
304    if #[cfg(not(target_os = "haiku"))] {
305        pub const LOG_PID: c_int = 0x01;
306        pub const LOG_CONS: c_int = 0x02;
307        pub const LOG_ODELAY: c_int = 0x04;
308        pub const LOG_NDELAY: c_int = 0x08;
309        pub const LOG_NOWAIT: c_int = 0x10;
310    }
311}
312pub const LOG_PRIMASK: c_int = 7;
313pub const LOG_FACMASK: c_int = 0x3f8;
314
315cfg_if! {
316    if #[cfg(not(target_os = "nto"))] {
317        pub const PRIO_MIN: c_int = -20;
318        pub const PRIO_MAX: c_int = 20;
319    }
320}
321pub const IPPROTO_ICMP: c_int = 1;
322pub const IPPROTO_ICMPV6: c_int = 58;
323pub const IPPROTO_TCP: c_int = 6;
324pub const IPPROTO_UDP: c_int = 17;
325pub const IPPROTO_IP: c_int = 0;
326pub const IPPROTO_IPV6: c_int = 41;
327
328pub const INADDR_LOOPBACK: in_addr_t = 2130706433;
329pub const INADDR_ANY: in_addr_t = 0;
330pub const INADDR_BROADCAST: in_addr_t = 4294967295;
331pub const INADDR_NONE: in_addr_t = 4294967295;
332
333pub const IN6ADDR_LOOPBACK_INIT: in6_addr = in6_addr {
334    s6_addr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
335};
336
337pub const IN6ADDR_ANY_INIT: in6_addr = in6_addr {
338    s6_addr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
339};
340
341pub const ARPOP_REQUEST: u16 = 1;
342pub const ARPOP_REPLY: u16 = 2;
343
344pub const ATF_COM: c_int = 0x02;
345pub const ATF_PERM: c_int = 0x04;
346pub const ATF_PUBL: c_int = 0x08;
347pub const ATF_USETRAILERS: c_int = 0x10;
348
349cfg_if! {
350    if #[cfg(any(target_os = "nto", target_os = "aix"))] {
351        pub const FNM_PERIOD: c_int = 1 << 1;
352    } else {
353        pub const FNM_PERIOD: c_int = 1 << 2;
354    }
355}
356pub const FNM_NOMATCH: c_int = 1;
357
358cfg_if! {
359    if #[cfg(any(
360        target_os = "illumos",
361        target_os = "solaris",
362        target_os = "netbsd"
363    ))] {
364        pub const FNM_CASEFOLD: c_int = 1 << 3;
365    } else if #[cfg(not(target_os = "aix"))] {
366        pub const FNM_CASEFOLD: c_int = 1 << 4;
367    }
368}
369
370cfg_if! {
371    if #[cfg(any(
372        target_os = "macos",
373        target_os = "freebsd",
374        target_os = "android",
375        target_os = "openbsd",
376        target_os = "cygwin",
377        target_os = "netbsd",
378    ))] {
379        pub const FNM_PATHNAME: c_int = 1 << 1;
380    } else {
381        pub const FNM_PATHNAME: c_int = 1 << 0;
382    }
383}
384
385cfg_if! {
386    if #[cfg(any(
387        target_os = "macos",
388        target_os = "freebsd",
389        target_os = "android",
390        target_os = "openbsd",
391        target_os = "netbsd",
392        target_os = "cygwin",
393    ))] {
394        pub const FNM_NOESCAPE: c_int = 1 << 0;
395    } else if #[cfg(target_os = "nto")] {
396        pub const FNM_NOESCAPE: c_int = 1 << 2;
397    } else if #[cfg(target_os = "aix")] {
398        pub const FNM_NOESCAPE: c_int = 1 << 3;
399    } else {
400        pub const FNM_NOESCAPE: c_int = 1 << 1;
401    }
402}
403
404extern "C" {
405    pub static in6addr_loopback: in6_addr;
406    pub static in6addr_any: in6_addr;
407}
408
409cfg_if! {
410    if #[cfg(any(
411        target_os = "l4re",
412        target_os = "espidf",
413        target_os = "nuttx"
414    ))] {
415        // required libraries are linked externally for these platforms:
416        // * L4Re
417        // * ESP-IDF
418        // * NuttX
419    } else if #[cfg(feature = "std")] {
420        // cargo build, don't pull in anything extra as the std dep
421        // already pulls in all libs.
422    } else if #[cfg(all(
423        any(
424            all(
425                target_os = "linux",
426                any(target_env = "gnu", target_env = "uclibc")
427            ),
428            target_os = "cygwin"
429        ),
430        feature = "rustc-dep-of-std"
431    ))] {
432        #[link(
433            name = "util",
434            kind = "static",
435            modifiers = "-bundle",
436            cfg(target_feature = "crt-static")
437        )]
438        #[link(
439            name = "rt",
440            kind = "static",
441            modifiers = "-bundle",
442            cfg(target_feature = "crt-static")
443        )]
444        #[link(
445            name = "pthread",
446            kind = "static",
447            modifiers = "-bundle",
448            cfg(target_feature = "crt-static")
449        )]
450        #[link(
451            name = "m",
452            kind = "static",
453            modifiers = "-bundle",
454            cfg(target_feature = "crt-static")
455        )]
456        #[link(
457            name = "dl",
458            kind = "static",
459            modifiers = "-bundle",
460            cfg(target_feature = "crt-static")
461        )]
462        #[link(
463            name = "c",
464            kind = "static",
465            modifiers = "-bundle",
466            cfg(target_feature = "crt-static")
467        )]
468        #[link(
469            name = "gcc_eh",
470            kind = "static",
471            modifiers = "-bundle",
472            cfg(target_feature = "crt-static")
473        )]
474        #[link(
475            name = "gcc",
476            kind = "static",
477            modifiers = "-bundle",
478            cfg(target_feature = "crt-static")
479        )]
480        #[link(
481            name = "c",
482            kind = "static",
483            modifiers = "-bundle",
484            cfg(target_feature = "crt-static")
485        )]
486        #[link(name = "util", cfg(not(target_feature = "crt-static")))]
487        #[link(name = "rt", cfg(not(target_feature = "crt-static")))]
488        #[link(name = "pthread", cfg(not(target_feature = "crt-static")))]
489        #[link(name = "m", cfg(not(target_feature = "crt-static")))]
490        #[link(name = "dl", cfg(not(target_feature = "crt-static")))]
491        #[link(name = "c", cfg(not(target_feature = "crt-static")))]
492        extern "C" {}
493    } else if #[cfg(any(target_env = "musl", target_env = "ohos"))] {
494        #[cfg_attr(
495            feature = "rustc-dep-of-std",
496            link(
497                name = "c",
498                kind = "static",
499                modifiers = "-bundle",
500                cfg(target_feature = "crt-static")
501            )
502        )]
503        #[cfg_attr(
504            feature = "rustc-dep-of-std",
505            link(name = "c", cfg(not(target_feature = "crt-static")))
506        )]
507        extern "C" {}
508    } else if #[cfg(target_os = "emscripten")] {
509        // Don't pass -lc to Emscripten, it breaks. See:
510        // https://github.com/emscripten-core/emscripten/issues/22758
511    } else if #[cfg(all(target_os = "android", feature = "rustc-dep-of-std"))] {
512        #[link(
513            name = "c",
514            kind = "static",
515            modifiers = "-bundle",
516            cfg(target_feature = "crt-static")
517        )]
518        #[link(
519            name = "m",
520            kind = "static",
521            modifiers = "-bundle",
522            cfg(target_feature = "crt-static")
523        )]
524        #[link(name = "m", cfg(not(target_feature = "crt-static")))]
525        #[link(name = "c", cfg(not(target_feature = "crt-static")))]
526        extern "C" {}
527    } else if #[cfg(any(
528        target_os = "macos",
529        target_os = "ios",
530        target_os = "tvos",
531        target_os = "watchos",
532        target_os = "visionos",
533        target_os = "android",
534        target_os = "openbsd",
535        target_os = "nto",
536    ))] {
537        #[link(name = "c")]
538        #[link(name = "m")]
539        extern "C" {}
540    } else if #[cfg(target_os = "haiku")] {
541        #[link(name = "root")]
542        #[link(name = "network")]
543        extern "C" {}
544    } else if #[cfg(target_env = "newlib")] {
545        #[link(name = "c")]
546        #[link(name = "m")]
547        extern "C" {}
548    } else if #[cfg(target_env = "illumos")] {
549        #[link(name = "c")]
550        #[link(name = "m")]
551        extern "C" {}
552    } else if #[cfg(target_os = "redox")] {
553        #[cfg_attr(
554            feature = "rustc-dep-of-std",
555            link(
556                name = "c",
557                kind = "static",
558                modifiers = "-bundle",
559                cfg(target_feature = "crt-static")
560            )
561        )]
562        #[cfg_attr(
563            feature = "rustc-dep-of-std",
564            link(name = "c", cfg(not(target_feature = "crt-static")))
565        )]
566        extern "C" {}
567    } else if #[cfg(target_os = "aix")] {
568        #[link(name = "c")]
569        #[link(name = "m")]
570        #[link(name = "bsd")]
571        #[link(name = "pthread")]
572        extern "C" {}
573    } else {
574        #[link(name = "c")]
575        #[link(name = "m")]
576        #[link(name = "rt")]
577        #[link(name = "pthread")]
578        extern "C" {}
579    }
580}
581
582cfg_if! {
583    if #[cfg(not(all(target_os = "linux", target_env = "gnu")))] {
584        extern_ty! {
585            pub enum fpos_t {} // FIXME(unix): fill this out with a struct
586        }
587    }
588}
589
590extern_ty! {
591    pub enum FILE {}
592}
593
594extern "C" {
595    pub fn isalnum(c: c_int) -> c_int;
596    pub fn isalpha(c: c_int) -> c_int;
597    pub fn iscntrl(c: c_int) -> c_int;
598    pub fn isdigit(c: c_int) -> c_int;
599    pub fn isgraph(c: c_int) -> c_int;
600    pub fn islower(c: c_int) -> c_int;
601    pub fn isprint(c: c_int) -> c_int;
602    pub fn ispunct(c: c_int) -> c_int;
603    pub fn isspace(c: c_int) -> c_int;
604    pub fn isupper(c: c_int) -> c_int;
605    pub fn isxdigit(c: c_int) -> c_int;
606    pub fn isblank(c: c_int) -> c_int;
607    pub fn tolower(c: c_int) -> c_int;
608    pub fn toupper(c: c_int) -> c_int;
609    pub fn qsort(
610        base: *mut c_void,
611        num: size_t,
612        size: size_t,
613        compar: Option<unsafe extern "C" fn(*const c_void, *const c_void) -> c_int>,
614    );
615    pub fn bsearch(
616        key: *const c_void,
617        base: *const c_void,
618        num: size_t,
619        size: size_t,
620        compar: Option<unsafe extern "C" fn(*const c_void, *const c_void) -> c_int>,
621    ) -> *mut c_void;
622    #[cfg_attr(
623        all(target_os = "macos", target_arch = "x86"),
624        link_name = "fopen$UNIX2003"
625    )]
626    #[cfg_attr(gnu_file_offset_bits64, link_name = "fopen64")]
627    pub fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE;
628    #[cfg_attr(
629        all(target_os = "macos", target_arch = "x86"),
630        link_name = "freopen$UNIX2003"
631    )]
632    #[cfg_attr(gnu_file_offset_bits64, link_name = "freopen64")]
633    pub fn freopen(filename: *const c_char, mode: *const c_char, file: *mut FILE) -> *mut FILE;
634
635    pub fn fflush(file: *mut FILE) -> c_int;
636    pub fn fclose(file: *mut FILE) -> c_int;
637    pub fn remove(filename: *const c_char) -> c_int;
638    pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int;
639    #[cfg_attr(gnu_file_offset_bits64, link_name = "tmpfile64")]
640    pub fn tmpfile() -> *mut FILE;
641    pub fn setvbuf(stream: *mut FILE, buffer: *mut c_char, mode: c_int, size: size_t) -> c_int;
642    pub fn setbuf(stream: *mut FILE, buf: *mut c_char);
643    pub fn getchar() -> c_int;
644    pub fn putchar(c: c_int) -> c_int;
645    pub fn fgetc(stream: *mut FILE) -> c_int;
646    pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char;
647    pub fn fputc(c: c_int, stream: *mut FILE) -> c_int;
648    #[cfg_attr(
649        all(target_os = "macos", target_arch = "x86"),
650        link_name = "fputs$UNIX2003"
651    )]
652    pub fn fputs(s: *const c_char, stream: *mut FILE) -> c_int;
653    pub fn puts(s: *const c_char) -> c_int;
654    pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int;
655    pub fn fread(ptr: *mut c_void, size: size_t, nobj: size_t, stream: *mut FILE) -> size_t;
656    #[cfg_attr(
657        all(target_os = "macos", target_arch = "x86"),
658        link_name = "fwrite$UNIX2003"
659    )]
660    pub fn fwrite(ptr: *const c_void, size: size_t, nobj: size_t, stream: *mut FILE) -> size_t;
661    pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int;
662    pub fn ftell(stream: *mut FILE) -> c_long;
663    pub fn rewind(stream: *mut FILE);
664    #[cfg_attr(target_os = "netbsd", link_name = "__fgetpos50")]
665    #[cfg_attr(gnu_file_offset_bits64, link_name = "fgetpos64")]
666    pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int;
667    #[cfg_attr(target_os = "netbsd", link_name = "__fsetpos50")]
668    #[cfg_attr(gnu_file_offset_bits64, link_name = "fsetpos64")]
669    pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int;
670    pub fn feof(stream: *mut FILE) -> c_int;
671    pub fn ferror(stream: *mut FILE) -> c_int;
672    pub fn clearerr(stream: *mut FILE);
673    pub fn perror(s: *const c_char);
674    pub fn atof(s: *const c_char) -> c_double;
675    pub fn atoi(s: *const c_char) -> c_int;
676    pub fn atol(s: *const c_char) -> c_long;
677    pub fn atoll(s: *const c_char) -> c_longlong;
678    #[cfg_attr(
679        all(target_os = "macos", target_arch = "x86"),
680        link_name = "strtod$UNIX2003"
681    )]
682    pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double;
683    pub fn strtof(s: *const c_char, endp: *mut *mut c_char) -> c_float;
684    pub fn strtol(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_long;
685    pub fn strtoll(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_longlong;
686    pub fn strtoul(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_ulong;
687    pub fn strtoull(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_ulonglong;
688    #[cfg_attr(target_os = "aix", link_name = "vec_calloc")]
689    pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void;
690    #[cfg_attr(target_os = "aix", link_name = "vec_malloc")]
691    pub fn malloc(size: size_t) -> *mut c_void;
692    pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
693    pub fn free(p: *mut c_void);
694    pub fn abort() -> !;
695    pub fn exit(status: c_int) -> !;
696    pub fn _exit(status: c_int) -> !;
697    #[cfg_attr(
698        all(target_os = "macos", target_arch = "x86"),
699        link_name = "system$UNIX2003"
700    )]
701    pub fn system(s: *const c_char) -> c_int;
702    pub fn getenv(s: *const c_char) -> *mut c_char;
703
704    pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char;
705    pub fn strncpy(dst: *mut c_char, src: *const c_char, n: size_t) -> *mut c_char;
706    pub fn stpcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char;
707    pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char;
708    pub fn strncat(s: *mut c_char, ct: *const c_char, n: size_t) -> *mut c_char;
709    pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int;
710    pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int;
711    pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int;
712    pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char;
713    pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char;
714    pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t;
715    pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t;
716    pub fn strdup(cs: *const c_char) -> *mut c_char;
717    pub fn strndup(cs: *const c_char, n: size_t) -> *mut c_char;
718    pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char;
719    pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
720    pub fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_int;
721    pub fn strncasecmp(s1: *const c_char, s2: *const c_char, n: size_t) -> c_int;
722    pub fn strlen(cs: *const c_char) -> size_t;
723    pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t;
724    #[cfg_attr(
725        all(target_os = "macos", target_arch = "x86"),
726        link_name = "strerror$UNIX2003"
727    )]
728    pub fn strerror(n: c_int) -> *mut c_char;
729    pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char;
730    pub fn strtok_r(s: *mut c_char, t: *const c_char, p: *mut *mut c_char) -> *mut c_char;
731    pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t;
732    pub fn strsignal(sig: c_int) -> *mut c_char;
733    pub fn wcslen(buf: *const wchar_t) -> size_t;
734    pub fn wcstombs(dest: *mut c_char, src: *const wchar_t, n: size_t) -> size_t;
735
736    pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
737    pub fn wmemchr(cx: *const wchar_t, c: wchar_t, n: size_t) -> *mut wchar_t;
738    pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int;
739    pub fn memcpy(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void;
740    pub fn memmove(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void;
741    pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void;
742    pub fn memccpy(dest: *mut c_void, src: *const c_void, c: c_int, n: size_t) -> *mut c_void;
743}
744
745extern "C" {
746    #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam50")]
747    pub fn getpwnam(name: *const c_char) -> *mut passwd;
748    #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid50")]
749    pub fn getpwuid(uid: crate::uid_t) -> *mut passwd;
750
751    pub fn fprintf(stream: *mut crate::FILE, format: *const c_char, ...) -> c_int;
752    pub fn printf(format: *const c_char, ...) -> c_int;
753    pub fn snprintf(s: *mut c_char, n: size_t, format: *const c_char, ...) -> c_int;
754    pub fn sprintf(s: *mut c_char, format: *const c_char, ...) -> c_int;
755    #[cfg_attr(
756        all(target_os = "linux", not(target_env = "uclibc")),
757        link_name = "__isoc99_fscanf"
758    )]
759    pub fn fscanf(stream: *mut crate::FILE, format: *const c_char, ...) -> c_int;
760    #[cfg_attr(
761        all(target_os = "linux", not(target_env = "uclibc")),
762        link_name = "__isoc99_scanf"
763    )]
764    pub fn scanf(format: *const c_char, ...) -> c_int;
765    #[cfg_attr(
766        all(target_os = "linux", not(target_env = "uclibc")),
767        link_name = "__isoc99_sscanf"
768    )]
769    pub fn sscanf(s: *const c_char, format: *const c_char, ...) -> c_int;
770    pub fn getchar_unlocked() -> c_int;
771    pub fn putchar_unlocked(c: c_int) -> c_int;
772
773    #[cfg(not(all(target_arch = "powerpc", target_vendor = "nintendo")))]
774    #[cfg_attr(target_os = "netbsd", link_name = "__socket30")]
775    #[cfg_attr(target_os = "illumos", link_name = "__xnet_socket")]
776    #[cfg_attr(target_os = "solaris", link_name = "__xnet7_socket")]
777    #[cfg_attr(target_os = "espidf", link_name = "lwip_socket")]
778    pub fn socket(domain: c_int, ty: c_int, protocol: c_int) -> c_int;
779    #[cfg(not(all(target_arch = "powerpc", target_vendor = "nintendo")))]
780    #[cfg_attr(
781        all(target_os = "macos", target_arch = "x86"),
782        link_name = "connect$UNIX2003"
783    )]
784    #[cfg_attr(
785        any(target_os = "illumos", target_os = "solaris"),
786        link_name = "__xnet_connect"
787    )]
788    #[cfg_attr(target_os = "espidf", link_name = "lwip_connect")]
789    pub fn connect(socket: c_int, address: *const sockaddr, len: socklen_t) -> c_int;
790    #[cfg_attr(
791        all(target_os = "macos", target_arch = "x86"),
792        link_name = "listen$UNIX2003"
793    )]
794    #[cfg_attr(target_os = "espidf", link_name = "lwip_listen")]
795    pub fn listen(socket: c_int, backlog: c_int) -> c_int;
796    #[cfg(not(all(target_arch = "powerpc", target_vendor = "nintendo")))]
797    #[cfg_attr(
798        all(target_os = "macos", target_arch = "x86"),
799        link_name = "accept$UNIX2003"
800    )]
801    #[cfg_attr(target_os = "espidf", link_name = "lwip_accept")]
802    #[cfg_attr(target_os = "aix", link_name = "naccept")]
803    pub fn accept(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int;
804    #[cfg(not(all(target_arch = "powerpc", target_vendor = "nintendo")))]
805    #[cfg_attr(
806        all(target_os = "macos", target_arch = "x86"),
807        link_name = "getpeername$UNIX2003"
808    )]
809    #[cfg_attr(target_os = "espidf", link_name = "lwip_getpeername")]
810    #[cfg_attr(target_os = "aix", link_name = "ngetpeername")]
811    pub fn getpeername(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t)
812        -> c_int;
813    #[cfg(not(all(target_arch = "powerpc", target_vendor = "nintendo")))]
814    #[cfg_attr(
815        all(target_os = "macos", target_arch = "x86"),
816        link_name = "getsockname$UNIX2003"
817    )]
818    #[cfg_attr(target_os = "espidf", link_name = "lwip_getsockname")]
819    #[cfg_attr(target_os = "aix", link_name = "ngetsockname")]
820    pub fn getsockname(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t)
821        -> c_int;
822    #[cfg_attr(target_os = "espidf", link_name = "lwip_setsockopt")]
823    #[cfg_attr(gnu_time_bits64, link_name = "__setsockopt64")]
824    pub fn setsockopt(
825        socket: c_int,
826        level: c_int,
827        name: c_int,
828        value: *const c_void,
829        option_len: socklen_t,
830    ) -> c_int;
831    #[cfg_attr(
832        all(target_os = "macos", target_arch = "x86"),
833        link_name = "socketpair$UNIX2003"
834    )]
835    #[cfg_attr(
836        any(target_os = "illumos", target_os = "solaris"),
837        link_name = "__xnet_socketpair"
838    )]
839    pub fn socketpair(
840        domain: c_int,
841        type_: c_int,
842        protocol: c_int,
843        socket_vector: *mut c_int,
844    ) -> c_int;
845    #[cfg(not(all(target_arch = "powerpc", target_vendor = "nintendo")))]
846    #[cfg_attr(
847        all(target_os = "macos", target_arch = "x86"),
848        link_name = "sendto$UNIX2003"
849    )]
850    #[cfg_attr(
851        any(target_os = "illumos", target_os = "solaris"),
852        link_name = "__xnet_sendto"
853    )]
854    #[cfg_attr(target_os = "espidf", link_name = "lwip_sendto")]
855    pub fn sendto(
856        socket: c_int,
857        buf: *const c_void,
858        len: size_t,
859        flags: c_int,
860        addr: *const sockaddr,
861        addrlen: socklen_t,
862    ) -> ssize_t;
863    #[cfg_attr(target_os = "espidf", link_name = "lwip_shutdown")]
864    pub fn shutdown(socket: c_int, how: c_int) -> c_int;
865
866    #[cfg_attr(
867        all(target_os = "macos", target_arch = "x86"),
868        link_name = "chmod$UNIX2003"
869    )]
870    pub fn chmod(path: *const c_char, mode: mode_t) -> c_int;
871    #[cfg_attr(
872        all(target_os = "macos", target_arch = "x86"),
873        link_name = "fchmod$UNIX2003"
874    )]
875    pub fn fchmod(fd: c_int, mode: mode_t) -> c_int;
876
877    #[cfg_attr(
878        all(target_os = "macos", not(target_arch = "aarch64")),
879        link_name = "fstat$INODE64"
880    )]
881    #[cfg_attr(target_os = "netbsd", link_name = "__fstat50")]
882    #[cfg_attr(
883        all(target_os = "freebsd", any(freebsd11, freebsd10)),
884        link_name = "fstat@FBSD_1.0"
885    )]
886    #[cfg_attr(gnu_time_bits64, link_name = "__fstat64_time64")]
887    #[cfg_attr(
888        all(not(gnu_time_bits64), gnu_file_offset_bits64),
889        link_name = "fstat64"
890    )]
891    #[cfg_attr(musl32_time64, link_name = "__fstat_time64")]
892    pub fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
893
894    pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int;
895
896    #[cfg_attr(
897        all(target_os = "macos", not(target_arch = "aarch64")),
898        link_name = "stat$INODE64"
899    )]
900    #[cfg_attr(target_os = "netbsd", link_name = "__stat50")]
901    #[cfg_attr(
902        all(target_os = "freebsd", any(freebsd11, freebsd10)),
903        link_name = "stat@FBSD_1.0"
904    )]
905    #[cfg_attr(gnu_time_bits64, link_name = "__stat64_time64")]
906    #[cfg_attr(
907        all(not(gnu_time_bits64), gnu_file_offset_bits64),
908        link_name = "stat64"
909    )]
910    #[cfg_attr(musl32_time64, link_name = "__stat_time64")]
911    pub fn stat(path: *const c_char, buf: *mut stat) -> c_int;
912
913    pub fn pclose(stream: *mut crate::FILE) -> c_int;
914    #[cfg_attr(
915        all(target_os = "macos", target_arch = "x86"),
916        link_name = "fdopen$UNIX2003"
917    )]
918    pub fn fdopen(fd: c_int, mode: *const c_char) -> *mut crate::FILE;
919    pub fn fileno(stream: *mut crate::FILE) -> c_int;
920
921    #[cfg_attr(
922        all(target_os = "macos", target_arch = "x86"),
923        link_name = "open$UNIX2003"
924    )]
925    #[cfg_attr(gnu_file_offset_bits64, link_name = "open64")]
926    pub fn open(path: *const c_char, oflag: c_int, ...) -> c_int;
927    #[cfg_attr(
928        all(target_os = "macos", target_arch = "x86"),
929        link_name = "creat$UNIX2003"
930    )]
931    #[cfg_attr(gnu_file_offset_bits64, link_name = "creat64")]
932    pub fn creat(path: *const c_char, mode: mode_t) -> c_int;
933    #[cfg_attr(
934        all(target_os = "macos", target_arch = "x86"),
935        link_name = "fcntl$UNIX2003"
936    )]
937    #[cfg_attr(gnu_time_bits64, link_name = "__fcntl_time64")]
938    #[cfg_attr(
939        all(not(gnu_time_bits64), gnu_file_offset_bits64),
940        link_name = "__fcntl_time64"
941    )]
942    pub fn fcntl(fd: c_int, cmd: c_int, ...) -> c_int;
943
944    #[cfg_attr(
945        all(target_os = "macos", target_arch = "x86_64"),
946        link_name = "opendir$INODE64"
947    )]
948    #[cfg_attr(
949        all(target_os = "macos", target_arch = "x86"),
950        link_name = "opendir$INODE64$UNIX2003"
951    )]
952    #[cfg_attr(target_os = "netbsd", link_name = "__opendir30")]
953    pub fn opendir(dirname: *const c_char) -> *mut crate::DIR;
954
955    #[cfg_attr(
956        all(target_os = "macos", not(target_arch = "aarch64")),
957        link_name = "readdir$INODE64"
958    )]
959    #[cfg_attr(target_os = "netbsd", link_name = "__readdir30")]
960    #[cfg_attr(
961        all(target_os = "freebsd", any(freebsd11, freebsd10)),
962        link_name = "readdir@FBSD_1.0"
963    )]
964    #[cfg_attr(gnu_file_offset_bits64, link_name = "readdir64")]
965    pub fn readdir(dirp: *mut crate::DIR) -> *mut crate::dirent;
966    #[cfg_attr(
967        all(target_os = "macos", target_arch = "x86"),
968        link_name = "closedir$UNIX2003"
969    )]
970    pub fn closedir(dirp: *mut crate::DIR) -> c_int;
971    #[cfg_attr(
972        all(target_os = "macos", target_arch = "x86_64"),
973        link_name = "rewinddir$INODE64"
974    )]
975    #[cfg_attr(
976        all(target_os = "macos", target_arch = "x86"),
977        link_name = "rewinddir$INODE64$UNIX2003"
978    )]
979    pub fn rewinddir(dirp: *mut crate::DIR);
980
981    pub fn fchmodat(dirfd: c_int, pathname: *const c_char, mode: mode_t, flags: c_int) -> c_int;
982    pub fn fchown(fd: c_int, owner: crate::uid_t, group: crate::gid_t) -> c_int;
983    #[cfg(not(target_os = "l4re"))]
984    pub fn fchownat(
985        dirfd: c_int,
986        pathname: *const c_char,
987        owner: crate::uid_t,
988        group: crate::gid_t,
989        flags: c_int,
990    ) -> c_int;
991    #[cfg_attr(
992        all(target_os = "macos", not(target_arch = "aarch64")),
993        link_name = "fstatat$INODE64"
994    )]
995    #[cfg_attr(
996        all(target_os = "freebsd", any(freebsd11, freebsd10)),
997        link_name = "fstatat@FBSD_1.1"
998    )]
999    #[cfg_attr(gnu_time_bits64, link_name = "__fstatat64_time64")]
1000    #[cfg_attr(
1001        all(not(gnu_time_bits64), gnu_file_offset_bits64),
1002        link_name = "fstatat64"
1003    )]
1004    #[cfg(not(target_os = "l4re"))]
1005    #[cfg_attr(musl32_time64, link_name = "__fstatat_time64")]
1006    pub fn fstatat(dirfd: c_int, pathname: *const c_char, buf: *mut stat, flags: c_int) -> c_int;
1007    #[cfg(not(target_os = "l4re"))]
1008    pub fn linkat(
1009        olddirfd: c_int,
1010        oldpath: *const c_char,
1011        newdirfd: c_int,
1012        newpath: *const c_char,
1013        flags: c_int,
1014    ) -> c_int;
1015    #[cfg(not(target_os = "l4re"))]
1016    pub fn renameat(
1017        olddirfd: c_int,
1018        oldpath: *const c_char,
1019        newdirfd: c_int,
1020        newpath: *const c_char,
1021    ) -> c_int;
1022    #[cfg(not(target_os = "l4re"))]
1023    pub fn symlinkat(target: *const c_char, newdirfd: c_int, linkpath: *const c_char) -> c_int;
1024    #[cfg(not(target_os = "l4re"))]
1025    pub fn unlinkat(dirfd: c_int, pathname: *const c_char, flags: c_int) -> c_int;
1026
1027    pub fn access(path: *const c_char, amode: c_int) -> c_int;
1028    pub fn alarm(seconds: c_uint) -> c_uint;
1029    pub fn chdir(dir: *const c_char) -> c_int;
1030    pub fn fchdir(dirfd: c_int) -> c_int;
1031    pub fn chown(path: *const c_char, uid: uid_t, gid: gid_t) -> c_int;
1032    #[cfg_attr(
1033        all(target_os = "macos", target_arch = "x86"),
1034        link_name = "lchown$UNIX2003"
1035    )]
1036    pub fn lchown(path: *const c_char, uid: uid_t, gid: gid_t) -> c_int;
1037    #[cfg_attr(
1038        all(target_os = "macos", target_arch = "x86"),
1039        link_name = "close$NOCANCEL$UNIX2003"
1040    )]
1041    #[cfg_attr(
1042        all(target_os = "macos", target_arch = "x86_64"),
1043        link_name = "close$NOCANCEL"
1044    )]
1045    pub fn close(fd: c_int) -> c_int;
1046    pub fn dup(fd: c_int) -> c_int;
1047    pub fn dup2(src: c_int, dst: c_int) -> c_int;
1048
1049    pub fn execl(path: *const c_char, arg0: *const c_char, ...) -> c_int;
1050    pub fn execle(path: *const c_char, arg0: *const c_char, ...) -> c_int;
1051    pub fn execlp(file: *const c_char, arg0: *const c_char, ...) -> c_int;
1052
1053    // DIFF(main): changed to `*const *mut` in e77f551de9
1054    pub fn execv(prog: *const c_char, argv: *const *const c_char) -> c_int;
1055    pub fn execve(
1056        prog: *const c_char,
1057        argv: *const *const c_char,
1058        envp: *const *const c_char,
1059    ) -> c_int;
1060    pub fn execvp(c: *const c_char, argv: *const *const c_char) -> c_int;
1061
1062    pub fn fork() -> pid_t;
1063    pub fn fpathconf(filedes: c_int, name: c_int) -> c_long;
1064    pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char;
1065    pub fn getegid() -> gid_t;
1066    pub fn geteuid() -> uid_t;
1067    pub fn getgid() -> gid_t;
1068    pub fn getgroups(ngroups_max: c_int, groups: *mut gid_t) -> c_int;
1069    #[cfg_attr(target_os = "illumos", link_name = "getloginx")]
1070    pub fn getlogin() -> *mut c_char;
1071    #[cfg_attr(
1072        all(target_os = "macos", target_arch = "x86"),
1073        link_name = "getopt$UNIX2003"
1074    )]
1075    pub fn getopt(argc: c_int, argv: *const *mut c_char, optstr: *const c_char) -> c_int;
1076    pub fn getpgid(pid: pid_t) -> pid_t;
1077    pub fn getpgrp() -> pid_t;
1078    pub fn getpid() -> pid_t;
1079    pub fn getppid() -> pid_t;
1080    pub fn getuid() -> uid_t;
1081    pub fn isatty(fd: c_int) -> c_int;
1082    #[cfg_attr(target_os = "solaris", link_name = "__link_xpg4")]
1083    pub fn link(src: *const c_char, dst: *const c_char) -> c_int;
1084    #[cfg_attr(gnu_file_offset_bits64, link_name = "lseek64")]
1085    pub fn lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t;
1086    pub fn pathconf(path: *const c_char, name: c_int) -> c_long;
1087    pub fn pipe(fds: *mut c_int) -> c_int;
1088    pub fn posix_memalign(memptr: *mut *mut c_void, align: size_t, size: size_t) -> c_int;
1089    pub fn aligned_alloc(alignment: size_t, size: size_t) -> *mut c_void;
1090    #[cfg_attr(
1091        all(target_os = "macos", target_arch = "x86"),
1092        link_name = "read$UNIX2003"
1093    )]
1094    pub fn read(fd: c_int, buf: *mut c_void, count: size_t) -> ssize_t;
1095    pub fn rmdir(path: *const c_char) -> c_int;
1096    pub fn seteuid(uid: uid_t) -> c_int;
1097    pub fn setegid(gid: gid_t) -> c_int;
1098    pub fn setgid(gid: gid_t) -> c_int;
1099    pub fn setpgid(pid: pid_t, pgid: pid_t) -> c_int;
1100    pub fn setsid() -> pid_t;
1101    pub fn setuid(uid: uid_t) -> c_int;
1102    pub fn setreuid(ruid: uid_t, euid: uid_t) -> c_int;
1103    pub fn setregid(rgid: gid_t, egid: gid_t) -> c_int;
1104    #[cfg_attr(
1105        all(target_os = "macos", target_arch = "x86"),
1106        link_name = "sleep$UNIX2003"
1107    )]
1108    pub fn sleep(secs: c_uint) -> c_uint;
1109    #[cfg_attr(
1110        all(target_os = "macos", target_arch = "x86"),
1111        link_name = "nanosleep$UNIX2003"
1112    )]
1113    #[cfg_attr(target_os = "netbsd", link_name = "__nanosleep50")]
1114    #[cfg_attr(gnu_time_bits64, link_name = "__nanosleep64")]
1115    #[cfg_attr(musl32_time64, link_name = "__nanosleep_time64")]
1116    pub fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int;
1117    pub fn tcgetpgrp(fd: c_int) -> pid_t;
1118    pub fn tcsetpgrp(fd: c_int, pgrp: crate::pid_t) -> c_int;
1119    pub fn ttyname(fd: c_int) -> *mut c_char;
1120    #[cfg_attr(
1121        all(target_os = "macos", target_arch = "x86"),
1122        link_name = "ttyname_r$UNIX2003"
1123    )]
1124    #[cfg_attr(
1125        any(target_os = "illumos", target_os = "solaris"),
1126        link_name = "__posix_ttyname_r"
1127    )]
1128    pub fn ttyname_r(fd: c_int, buf: *mut c_char, buflen: size_t) -> c_int;
1129    pub fn unlink(c: *const c_char) -> c_int;
1130    #[cfg_attr(
1131        all(target_os = "macos", target_arch = "x86"),
1132        link_name = "wait$UNIX2003"
1133    )]
1134    pub fn wait(status: *mut c_int) -> pid_t;
1135    #[cfg_attr(
1136        all(target_os = "macos", target_arch = "x86"),
1137        link_name = "waitpid$UNIX2003"
1138    )]
1139    pub fn waitpid(pid: pid_t, status: *mut c_int, options: c_int) -> pid_t;
1140    #[cfg_attr(
1141        all(target_os = "macos", target_arch = "x86"),
1142        link_name = "write$UNIX2003"
1143    )]
1144    pub fn write(fd: c_int, buf: *const c_void, count: size_t) -> ssize_t;
1145    #[cfg_attr(
1146        all(target_os = "macos", target_arch = "x86"),
1147        link_name = "pread$UNIX2003"
1148    )]
1149    #[cfg_attr(gnu_file_offset_bits64, link_name = "pread64")]
1150    pub fn pread(fd: c_int, buf: *mut c_void, count: size_t, offset: off_t) -> ssize_t;
1151    #[cfg_attr(
1152        all(target_os = "macos", target_arch = "x86"),
1153        link_name = "pwrite$UNIX2003"
1154    )]
1155    #[cfg_attr(gnu_file_offset_bits64, link_name = "pwrite64")]
1156    pub fn pwrite(fd: c_int, buf: *const c_void, count: size_t, offset: off_t) -> ssize_t;
1157    pub fn umask(mask: mode_t) -> mode_t;
1158
1159    #[cfg_attr(target_os = "netbsd", link_name = "__utime50")]
1160    #[cfg_attr(any(gnu_time_bits64, musl32_time64), link_name = "__utime64")]
1161    pub fn utime(file: *const c_char, buf: *const utimbuf) -> c_int;
1162
1163    #[cfg_attr(
1164        all(target_os = "macos", target_arch = "x86"),
1165        link_name = "kill$UNIX2003"
1166    )]
1167    pub fn kill(pid: pid_t, sig: c_int) -> c_int;
1168    #[cfg_attr(
1169        all(target_os = "macos", target_arch = "x86"),
1170        link_name = "killpg$UNIX2003"
1171    )]
1172    pub fn killpg(pgrp: pid_t, sig: c_int) -> c_int;
1173
1174    pub fn mlock(addr: *const c_void, len: size_t) -> c_int;
1175    pub fn munlock(addr: *const c_void, len: size_t) -> c_int;
1176    pub fn mlockall(flags: c_int) -> c_int;
1177    pub fn munlockall() -> c_int;
1178
1179    #[cfg_attr(
1180        all(target_os = "macos", target_arch = "x86"),
1181        link_name = "mmap$UNIX2003"
1182    )]
1183    #[cfg_attr(gnu_file_offset_bits64, link_name = "mmap64")]
1184    pub fn mmap(
1185        addr: *mut c_void,
1186        len: size_t,
1187        prot: c_int,
1188        flags: c_int,
1189        fd: c_int,
1190        offset: off_t,
1191    ) -> *mut c_void;
1192    #[cfg_attr(
1193        all(target_os = "macos", target_arch = "x86"),
1194        link_name = "munmap$UNIX2003"
1195    )]
1196    pub fn munmap(addr: *mut c_void, len: size_t) -> c_int;
1197
1198    pub fn if_nametoindex(ifname: *const c_char) -> c_uint;
1199    pub fn if_indextoname(ifindex: c_uint, ifname: *mut c_char) -> *mut c_char;
1200
1201    #[cfg_attr(
1202        all(target_os = "macos", not(target_arch = "aarch64")),
1203        link_name = "lstat$INODE64"
1204    )]
1205    #[cfg_attr(target_os = "netbsd", link_name = "__lstat50")]
1206    #[cfg_attr(
1207        all(target_os = "freebsd", any(freebsd11, freebsd10)),
1208        link_name = "lstat@FBSD_1.0"
1209    )]
1210    #[cfg_attr(gnu_time_bits64, link_name = "__lstat64_time64")]
1211    #[cfg_attr(
1212        all(not(gnu_time_bits64), gnu_file_offset_bits64),
1213        link_name = "lstat64"
1214    )]
1215    #[cfg_attr(musl32_time64, link_name = "__lstat_time64")]
1216    pub fn lstat(path: *const c_char, buf: *mut stat) -> c_int;
1217
1218    #[cfg_attr(
1219        all(target_os = "macos", target_arch = "x86"),
1220        link_name = "fsync$UNIX2003"
1221    )]
1222    pub fn fsync(fd: c_int) -> c_int;
1223
1224    #[cfg_attr(
1225        all(target_os = "macos", target_arch = "x86"),
1226        link_name = "setenv$UNIX2003"
1227    )]
1228    pub fn setenv(name: *const c_char, val: *const c_char, overwrite: c_int) -> c_int;
1229    #[cfg_attr(
1230        all(target_os = "macos", target_arch = "x86"),
1231        link_name = "unsetenv$UNIX2003"
1232    )]
1233    #[cfg_attr(target_os = "netbsd", link_name = "__unsetenv13")]
1234    pub fn unsetenv(name: *const c_char) -> c_int;
1235
1236    pub fn symlink(path1: *const c_char, path2: *const c_char) -> c_int;
1237
1238    #[cfg_attr(gnu_file_offset_bits64, link_name = "truncate64")]
1239    pub fn truncate(path: *const c_char, length: off_t) -> c_int;
1240    #[cfg_attr(gnu_file_offset_bits64, link_name = "ftruncate64")]
1241    pub fn ftruncate(fd: c_int, length: off_t) -> c_int;
1242
1243    pub fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t;
1244
1245    #[cfg_attr(target_os = "netbsd", link_name = "__getrusage50")]
1246    #[cfg_attr(gnu_time_bits64, link_name = "__getrusage64")]
1247    #[cfg_attr(musl32_time64, link_name = "__getrusage_time64")]
1248    pub fn getrusage(resource: c_int, usage: *mut rusage) -> c_int;
1249
1250    #[cfg_attr(
1251        any(
1252            target_os = "macos",
1253            target_os = "ios",
1254            target_os = "tvos",
1255            target_os = "watchos",
1256            target_os = "visionos"
1257        ),
1258        link_name = "realpath$DARWIN_EXTSN"
1259    )]
1260    pub fn realpath(pathname: *const c_char, resolved: *mut c_char) -> *mut c_char;
1261
1262    #[cfg_attr(target_os = "netbsd", link_name = "__times13")]
1263    pub fn times(buf: *mut crate::tms) -> crate::clock_t;
1264
1265    pub fn pthread_self() -> crate::pthread_t;
1266    pub fn pthread_equal(t1: crate::pthread_t, t2: crate::pthread_t) -> c_int;
1267    #[cfg_attr(
1268        all(target_os = "macos", target_arch = "x86"),
1269        link_name = "pthread_join$UNIX2003"
1270    )]
1271    pub fn pthread_join(native: crate::pthread_t, value: *mut *mut c_void) -> c_int;
1272    pub fn pthread_exit(value: *mut c_void) -> !;
1273    pub fn pthread_attr_init(attr: *mut crate::pthread_attr_t) -> c_int;
1274    pub fn pthread_attr_destroy(attr: *mut crate::pthread_attr_t) -> c_int;
1275    pub fn pthread_attr_getstacksize(
1276        attr: *const crate::pthread_attr_t,
1277        stacksize: *mut size_t,
1278    ) -> c_int;
1279    pub fn pthread_attr_setstacksize(attr: *mut crate::pthread_attr_t, stack_size: size_t)
1280        -> c_int;
1281    pub fn pthread_attr_setdetachstate(attr: *mut crate::pthread_attr_t, state: c_int) -> c_int;
1282    pub fn pthread_detach(thread: crate::pthread_t) -> c_int;
1283    #[cfg_attr(target_os = "netbsd", link_name = "__libc_thr_yield")]
1284    pub fn sched_yield() -> c_int;
1285    pub fn pthread_key_create(
1286        key: *mut crate::pthread_key_t,
1287        dtor: Option<unsafe extern "C" fn(*mut c_void)>,
1288    ) -> c_int;
1289    pub fn pthread_key_delete(key: crate::pthread_key_t) -> c_int;
1290    pub fn pthread_getspecific(key: crate::pthread_key_t) -> *mut c_void;
1291    pub fn pthread_setspecific(key: crate::pthread_key_t, value: *const c_void) -> c_int;
1292    pub fn pthread_mutex_init(
1293        lock: *mut crate::pthread_mutex_t,
1294        attr: *const crate::pthread_mutexattr_t,
1295    ) -> c_int;
1296    pub fn pthread_mutex_destroy(lock: *mut crate::pthread_mutex_t) -> c_int;
1297    pub fn pthread_mutex_lock(lock: *mut crate::pthread_mutex_t) -> c_int;
1298    pub fn pthread_mutex_trylock(lock: *mut crate::pthread_mutex_t) -> c_int;
1299    pub fn pthread_mutex_unlock(lock: *mut crate::pthread_mutex_t) -> c_int;
1300
1301    pub fn pthread_mutexattr_init(attr: *mut crate::pthread_mutexattr_t) -> c_int;
1302    #[cfg_attr(
1303        all(target_os = "macos", target_arch = "x86"),
1304        link_name = "pthread_mutexattr_destroy$UNIX2003"
1305    )]
1306    pub fn pthread_mutexattr_destroy(attr: *mut crate::pthread_mutexattr_t) -> c_int;
1307    pub fn pthread_mutexattr_settype(attr: *mut crate::pthread_mutexattr_t, _type: c_int) -> c_int;
1308
1309    #[cfg_attr(
1310        all(target_os = "macos", target_arch = "x86"),
1311        link_name = "pthread_cond_init$UNIX2003"
1312    )]
1313    pub fn pthread_cond_init(
1314        cond: *mut crate::pthread_cond_t,
1315        attr: *const crate::pthread_condattr_t,
1316    ) -> c_int;
1317    #[cfg_attr(
1318        all(target_os = "macos", target_arch = "x86"),
1319        link_name = "pthread_cond_wait$UNIX2003"
1320    )]
1321    pub fn pthread_cond_wait(
1322        cond: *mut crate::pthread_cond_t,
1323        lock: *mut crate::pthread_mutex_t,
1324    ) -> c_int;
1325    #[cfg_attr(
1326        all(target_os = "macos", target_arch = "x86"),
1327        link_name = "pthread_cond_timedwait$UNIX2003"
1328    )]
1329    #[cfg_attr(gnu_time_bits64, link_name = "__pthread_cond_timedwait64")]
1330    #[cfg_attr(musl32_time64, link_name = "__pthread_cond_timedwait_time64")]
1331    pub fn pthread_cond_timedwait(
1332        cond: *mut crate::pthread_cond_t,
1333        lock: *mut crate::pthread_mutex_t,
1334        abstime: *const crate::timespec,
1335    ) -> c_int;
1336    pub fn pthread_cond_signal(cond: *mut crate::pthread_cond_t) -> c_int;
1337    pub fn pthread_cond_broadcast(cond: *mut crate::pthread_cond_t) -> c_int;
1338    pub fn pthread_cond_destroy(cond: *mut crate::pthread_cond_t) -> c_int;
1339    pub fn pthread_condattr_init(attr: *mut crate::pthread_condattr_t) -> c_int;
1340    pub fn pthread_condattr_destroy(attr: *mut crate::pthread_condattr_t) -> c_int;
1341    #[cfg_attr(
1342        all(target_os = "macos", target_arch = "x86"),
1343        link_name = "pthread_rwlock_init$UNIX2003"
1344    )]
1345    pub fn pthread_rwlock_init(
1346        lock: *mut crate::pthread_rwlock_t,
1347        attr: *const crate::pthread_rwlockattr_t,
1348    ) -> c_int;
1349    #[cfg_attr(
1350        all(target_os = "macos", target_arch = "x86"),
1351        link_name = "pthread_rwlock_destroy$UNIX2003"
1352    )]
1353    pub fn pthread_rwlock_destroy(lock: *mut crate::pthread_rwlock_t) -> c_int;
1354    #[cfg_attr(
1355        all(target_os = "macos", target_arch = "x86"),
1356        link_name = "pthread_rwlock_rdlock$UNIX2003"
1357    )]
1358    pub fn pthread_rwlock_rdlock(lock: *mut crate::pthread_rwlock_t) -> c_int;
1359    #[cfg_attr(
1360        all(target_os = "macos", target_arch = "x86"),
1361        link_name = "pthread_rwlock_tryrdlock$UNIX2003"
1362    )]
1363    pub fn pthread_rwlock_tryrdlock(lock: *mut crate::pthread_rwlock_t) -> c_int;
1364    #[cfg_attr(
1365        all(target_os = "macos", target_arch = "x86"),
1366        link_name = "pthread_rwlock_wrlock$UNIX2003"
1367    )]
1368    pub fn pthread_rwlock_wrlock(lock: *mut crate::pthread_rwlock_t) -> c_int;
1369    #[cfg_attr(
1370        all(target_os = "macos", target_arch = "x86"),
1371        link_name = "pthread_rwlock_trywrlock$UNIX2003"
1372    )]
1373    pub fn pthread_rwlock_trywrlock(lock: *mut crate::pthread_rwlock_t) -> c_int;
1374    #[cfg_attr(
1375        all(target_os = "macos", target_arch = "x86"),
1376        link_name = "pthread_rwlock_unlock$UNIX2003"
1377    )]
1378    pub fn pthread_rwlock_unlock(lock: *mut crate::pthread_rwlock_t) -> c_int;
1379    pub fn pthread_rwlockattr_init(attr: *mut crate::pthread_rwlockattr_t) -> c_int;
1380    pub fn pthread_rwlockattr_destroy(attr: *mut crate::pthread_rwlockattr_t) -> c_int;
1381
1382    #[cfg_attr(
1383        any(target_os = "illumos", target_os = "solaris"),
1384        link_name = "__xnet_getsockopt"
1385    )]
1386    #[cfg_attr(target_os = "espidf", link_name = "lwip_getsockopt")]
1387    #[cfg_attr(gnu_time_bits64, link_name = "__getsockopt64")]
1388    pub fn getsockopt(
1389        sockfd: c_int,
1390        level: c_int,
1391        optname: c_int,
1392        optval: *mut c_void,
1393        optlen: *mut crate::socklen_t,
1394    ) -> c_int;
1395    pub fn raise(signum: c_int) -> c_int;
1396
1397    #[cfg_attr(target_os = "netbsd", link_name = "__utimes50")]
1398    #[cfg_attr(gnu_time_bits64, link_name = "__utimes64")]
1399    #[cfg_attr(musl32_time64, link_name = "__utimes_time64")]
1400    pub fn utimes(filename: *const c_char, times: *const crate::timeval) -> c_int;
1401    pub fn dlopen(filename: *const c_char, flag: c_int) -> *mut c_void;
1402    pub fn dlerror() -> *mut c_char;
1403    #[cfg_attr(musl32_time64, link_name = "__dlsym_time64")]
1404    pub fn dlsym(handle: *mut c_void, symbol: *const c_char) -> *mut c_void;
1405    pub fn dlclose(handle: *mut c_void) -> c_int;
1406
1407    #[cfg(not(all(target_arch = "powerpc", target_vendor = "nintendo")))]
1408    #[cfg_attr(
1409        any(target_os = "illumos", target_os = "solaris"),
1410        link_name = "__xnet_getaddrinfo"
1411    )]
1412    #[cfg_attr(target_os = "espidf", link_name = "lwip_getaddrinfo")]
1413    pub fn getaddrinfo(
1414        node: *const c_char,
1415        service: *const c_char,
1416        hints: *const addrinfo,
1417        res: *mut *mut addrinfo,
1418    ) -> c_int;
1419    #[cfg(not(all(target_arch = "powerpc", target_vendor = "nintendo")))]
1420    #[cfg_attr(target_os = "espidf", link_name = "lwip_freeaddrinfo")]
1421    pub fn freeaddrinfo(res: *mut addrinfo);
1422    pub fn hstrerror(errcode: c_int) -> *const c_char;
1423    pub fn gai_strerror(errcode: c_int) -> *const c_char;
1424    #[cfg_attr(
1425        any(
1426            all(
1427                target_os = "linux",
1428                not(any(target_env = "musl", target_env = "ohos"))
1429            ),
1430            target_os = "freebsd",
1431            target_os = "cygwin",
1432            target_os = "dragonfly",
1433            target_os = "haiku"
1434        ),
1435        link_name = "__res_init"
1436    )]
1437    #[cfg_attr(
1438        any(
1439            target_os = "macos",
1440            target_os = "ios",
1441            target_os = "tvos",
1442            target_os = "watchos",
1443            target_os = "visionos"
1444        ),
1445        link_name = "res_9_init"
1446    )]
1447    #[cfg_attr(target_os = "aix", link_name = "_res_init")]
1448    #[cfg(not(target_os = "l4re"))]
1449    pub fn res_init() -> c_int;
1450
1451    #[cfg_attr(target_os = "netbsd", link_name = "__gmtime_r50")]
1452    #[cfg_attr(gnu_time_bits64, link_name = "__gmtime64_r")]
1453    #[cfg_attr(not(musl32_time64), allow(deprecated))]
1454    #[cfg_attr(musl32_time64, link_name = "__gmtime64_r")]
1455    pub fn gmtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm;
1456    #[cfg_attr(target_os = "netbsd", link_name = "__localtime_r50")]
1457    #[cfg_attr(gnu_time_bits64, link_name = "__localtime64_r")]
1458    #[cfg_attr(not(musl32_time64), allow(deprecated))]
1459    #[cfg_attr(musl32_time64, link_name = "__localtime64_r")]
1460    pub fn localtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm;
1461    #[cfg_attr(
1462        all(target_os = "macos", target_arch = "x86"),
1463        link_name = "mktime$UNIX2003"
1464    )]
1465    #[cfg_attr(target_os = "netbsd", link_name = "__mktime50")]
1466    #[cfg_attr(any(gnu_time_bits64, musl32_time64), link_name = "__mktime64")]
1467    #[cfg_attr(not(musl32_time64), allow(deprecated))]
1468    pub fn mktime(tm: *mut tm) -> time_t;
1469    #[cfg_attr(target_os = "netbsd", link_name = "__time50")]
1470    #[cfg_attr(any(gnu_time_bits64, musl32_time64), link_name = "__time64")]
1471    #[cfg_attr(not(musl32_time64), allow(deprecated))]
1472    pub fn time(time: *mut time_t) -> time_t;
1473    #[cfg_attr(target_os = "netbsd", link_name = "__gmtime50")]
1474    #[cfg_attr(any(gnu_time_bits64, musl32_time64), link_name = "__gmtime64")]
1475    #[cfg_attr(not(musl32_time64), allow(deprecated))]
1476    pub fn gmtime(time_p: *const time_t) -> *mut tm;
1477    #[cfg_attr(target_os = "netbsd", link_name = "__locatime50")]
1478    #[cfg_attr(any(gnu_time_bits64, musl32_time64), link_name = "__localtime64")]
1479    #[cfg_attr(not(musl32_time64), allow(deprecated))]
1480    pub fn localtime(time_p: *const time_t) -> *mut tm;
1481    #[cfg_attr(target_os = "netbsd", link_name = "__difftime50")]
1482    #[cfg_attr(any(gnu_time_bits64, musl32_time64), link_name = "__difftime64")]
1483    #[cfg_attr(not(musl32_time64), allow(deprecated))]
1484    pub fn difftime(time1: time_t, time0: time_t) -> c_double;
1485    #[cfg(not(target_os = "aix"))]
1486    #[cfg_attr(target_os = "netbsd", link_name = "__timegm50")]
1487    #[cfg_attr(gnu_time_bits64, link_name = "__timegm64")]
1488    #[cfg_attr(not(musl32_time64), allow(deprecated))]
1489    #[cfg_attr(musl32_time64, link_name = "__timegm_time64")]
1490    pub fn timegm(tm: *mut crate::tm) -> time_t;
1491
1492    #[cfg_attr(target_os = "netbsd", link_name = "__mknod50")]
1493    #[cfg_attr(
1494        all(target_os = "freebsd", any(freebsd11, freebsd10)),
1495        link_name = "mknod@FBSD_1.0"
1496    )]
1497    pub fn mknod(pathname: *const c_char, mode: mode_t, dev: crate::dev_t) -> c_int;
1498    #[cfg(not(target_os = "espidf"))]
1499    pub fn gethostname(name: *mut c_char, len: size_t) -> c_int;
1500    pub fn endservent();
1501    pub fn getservbyname(name: *const c_char, proto: *const c_char) -> *mut servent;
1502    pub fn getservbyport(port: c_int, proto: *const c_char) -> *mut servent;
1503    pub fn getservent() -> *mut servent;
1504    pub fn setservent(stayopen: c_int);
1505    pub fn getprotobyname(name: *const c_char) -> *mut protoent;
1506    pub fn getprotobynumber(proto: c_int) -> *mut protoent;
1507    pub fn chroot(name: *const c_char) -> c_int;
1508    #[cfg(target_os = "cygwin")]
1509    pub fn usleep(secs: useconds_t) -> c_int;
1510    #[cfg_attr(
1511        all(target_os = "macos", target_arch = "x86"),
1512        link_name = "usleep$UNIX2003"
1513    )]
1514    #[cfg(not(target_os = "cygwin"))]
1515    pub fn usleep(secs: c_uint) -> c_int;
1516    #[cfg_attr(
1517        all(target_os = "macos", target_arch = "x86"),
1518        link_name = "send$UNIX2003"
1519    )]
1520    #[cfg_attr(target_os = "espidf", link_name = "lwip_send")]
1521    pub fn send(socket: c_int, buf: *const c_void, len: size_t, flags: c_int) -> ssize_t;
1522    #[cfg_attr(
1523        all(target_os = "macos", target_arch = "x86"),
1524        link_name = "recv$UNIX2003"
1525    )]
1526    #[cfg_attr(target_os = "espidf", link_name = "lwip_recv")]
1527    pub fn recv(socket: c_int, buf: *mut c_void, len: size_t, flags: c_int) -> ssize_t;
1528    #[cfg_attr(
1529        all(target_os = "macos", target_arch = "x86"),
1530        link_name = "putenv$UNIX2003"
1531    )]
1532    #[cfg_attr(target_os = "netbsd", link_name = "__putenv50")]
1533    pub fn putenv(string: *mut c_char) -> c_int;
1534    #[cfg_attr(
1535        all(target_os = "macos", target_arch = "x86"),
1536        link_name = "poll$UNIX2003"
1537    )]
1538    pub fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: c_int) -> c_int;
1539    #[cfg_attr(
1540        all(target_os = "macos", target_arch = "x86_64"),
1541        link_name = "select$1050"
1542    )]
1543    #[cfg_attr(
1544        all(target_os = "macos", target_arch = "x86"),
1545        link_name = "select$UNIX2003"
1546    )]
1547    #[cfg_attr(target_os = "netbsd", link_name = "__select50")]
1548    #[cfg_attr(target_os = "aix", link_name = "__fd_select")]
1549    #[cfg_attr(gnu_time_bits64, link_name = "__select64")]
1550    #[cfg_attr(musl32_time64, link_name = "__select_time64")]
1551    pub fn select(
1552        nfds: c_int,
1553        readfds: *mut fd_set,
1554        writefds: *mut fd_set,
1555        errorfds: *mut fd_set,
1556        timeout: *mut timeval,
1557    ) -> c_int;
1558    #[cfg_attr(target_os = "netbsd", link_name = "__setlocale50")]
1559    pub fn setlocale(category: c_int, locale: *const c_char) -> *mut c_char;
1560    pub fn localeconv() -> *mut lconv;
1561
1562    #[cfg_attr(
1563        all(target_os = "macos", target_arch = "x86"),
1564        link_name = "sem_wait$UNIX2003"
1565    )]
1566    pub fn sem_wait(sem: *mut sem_t) -> c_int;
1567    pub fn sem_trywait(sem: *mut sem_t) -> c_int;
1568    pub fn sem_post(sem: *mut sem_t) -> c_int;
1569    #[cfg_attr(gnu_file_offset_bits64, link_name = "statvfs64")]
1570    pub fn statvfs(path: *const c_char, buf: *mut crate::statvfs) -> c_int;
1571    #[cfg_attr(gnu_file_offset_bits64, link_name = "fstatvfs64")]
1572    pub fn fstatvfs(fd: c_int, buf: *mut crate::statvfs) -> c_int;
1573
1574    #[cfg_attr(target_os = "netbsd", link_name = "__sigemptyset14")]
1575    pub fn sigemptyset(set: *mut sigset_t) -> c_int;
1576    #[cfg_attr(target_os = "netbsd", link_name = "__sigaddset14")]
1577    pub fn sigaddset(set: *mut sigset_t, signum: c_int) -> c_int;
1578    #[cfg_attr(target_os = "netbsd", link_name = "__sigfillset14")]
1579    pub fn sigfillset(set: *mut sigset_t) -> c_int;
1580    #[cfg_attr(target_os = "netbsd", link_name = "__sigdelset14")]
1581    pub fn sigdelset(set: *mut sigset_t, signum: c_int) -> c_int;
1582    #[cfg_attr(target_os = "netbsd", link_name = "__sigismember14")]
1583    pub fn sigismember(set: *const sigset_t, signum: c_int) -> c_int;
1584
1585    #[cfg_attr(target_os = "netbsd", link_name = "__sigprocmask14")]
1586    pub fn sigprocmask(how: c_int, set: *const sigset_t, oldset: *mut sigset_t) -> c_int;
1587    #[cfg_attr(target_os = "netbsd", link_name = "__sigpending14")]
1588    pub fn sigpending(set: *mut sigset_t) -> c_int;
1589
1590    #[cfg_attr(target_os = "solaris", link_name = "__sysconf_xpg7")]
1591    pub fn sysconf(name: c_int) -> c_long;
1592
1593    pub fn mkfifo(path: *const c_char, mode: mode_t) -> c_int;
1594
1595    #[cfg_attr(gnu_file_offset_bits64, link_name = "fseeko64")]
1596    pub fn fseeko(stream: *mut crate::FILE, offset: off_t, whence: c_int) -> c_int;
1597    #[cfg_attr(gnu_file_offset_bits64, link_name = "ftello64")]
1598    pub fn ftello(stream: *mut crate::FILE) -> off_t;
1599    #[cfg_attr(
1600        all(target_os = "macos", target_arch = "x86"),
1601        link_name = "tcdrain$UNIX2003"
1602    )]
1603    pub fn tcdrain(fd: c_int) -> c_int;
1604    #[cfg_attr(
1605        all(target_os = "linux", target_env = "gnu", target_arch = "arm"),
1606        link_name = "cfgetispeed@GLIBC_2.4"
1607    )]
1608    #[cfg_attr(
1609        all(target_os = "linux", target_env = "gnu", target_arch = "csky"),
1610        link_name = "cfgetispeed@GLIBC_2.29"
1611    )]
1612    #[cfg_attr(
1613        all(target_os = "linux", target_env = "gnu", target_arch = "m68k"),
1614        link_name = "cfgetispeed@GLIBC_2.0"
1615    )]
1616    #[cfg_attr(
1617        all(target_os = "linux", target_env = "gnu", target_arch = "mips"),
1618        link_name = "cfgetispeed@GLIBC_2.0"
1619    )]
1620    #[cfg_attr(
1621        all(target_os = "linux", target_env = "gnu", target_arch = "powerpc"),
1622        link_name = "cfgetispeed@GLIBC_2.0"
1623    )]
1624    #[cfg_attr(
1625        all(target_os = "linux", target_env = "gnu", target_arch = "riscv32"),
1626        link_name = "cfgetispeed@GLIBC_2.33"
1627    )]
1628    #[cfg_attr(
1629        all(target_os = "linux", target_env = "gnu", target_arch = "sparc"),
1630        link_name = "cfgetispeed@GLIBC_2.0"
1631    )]
1632    #[cfg_attr(
1633        all(target_os = "linux", target_env = "gnu", target_arch = "x86"),
1634        link_name = "cfgetispeed@GLIBC_2.0"
1635    )]
1636    #[cfg_attr(
1637        all(target_os = "linux", target_env = "gnu", target_arch = "aarch64"),
1638        link_name = "cfgetispeed@GLIBC_2.17"
1639    )]
1640    #[cfg_attr(
1641        all(target_os = "linux", target_env = "gnu", target_arch = "loongarch64"),
1642        link_name = "cfgetispeed@GLIBC_2.36"
1643    )]
1644    #[cfg_attr(
1645        all(target_os = "linux", target_env = "gnu", target_arch = "mips64"),
1646        link_name = "cfgetispeed@GLIBC_2.0"
1647    )]
1648    #[cfg_attr(
1649        all(
1650            target_os = "linux",
1651            target_env = "gnu",
1652            target_arch = "powerpc64",
1653            target_endian = "big"
1654        ),
1655        link_name = "cfgetispeed@GLIBC_2.3"
1656    )]
1657    #[cfg_attr(
1658        all(
1659            target_os = "linux",
1660            target_env = "gnu",
1661            target_arch = "powerpc64",
1662            target_endian = "little"
1663        ),
1664        link_name = "cfgetispeed@GLIBC_2.17"
1665    )]
1666    #[cfg_attr(
1667        all(target_os = "linux", target_env = "gnu", target_arch = "riscv64"),
1668        link_name = "cfgetispeed@GLIBC_2.27"
1669    )]
1670    #[cfg_attr(
1671        all(target_os = "linux", target_env = "gnu", target_arch = "s390x"),
1672        link_name = "cfgetispeed@GLIBC_2.2"
1673    )]
1674    #[cfg_attr(
1675        all(target_os = "linux", target_env = "gnu", target_arch = "sparc64"),
1676        link_name = "cfgetispeed@GLIBC_2.2"
1677    )]
1678    #[cfg_attr(
1679        all(
1680            target_os = "linux",
1681            target_env = "gnu",
1682            target_arch = "x86_64",
1683            target_pointer_width = "64"
1684        ),
1685        link_name = "cfgetispeed@GLIBC_2.2.5"
1686    )]
1687    #[cfg_attr(
1688        all(
1689            target_os = "linux",
1690            target_env = "gnu",
1691            target_arch = "x86_64",
1692            target_pointer_width = "32"
1693        ),
1694        link_name = "cfgetispeed@GLIBC_2.16"
1695    )]
1696    pub fn cfgetispeed(termios: *const crate::termios) -> crate::speed_t;
1697    #[cfg_attr(
1698        all(target_os = "linux", target_env = "gnu", target_arch = "arm"),
1699        link_name = "cfgetospeed@GLIBC_2.4"
1700    )]
1701    #[cfg_attr(
1702        all(target_os = "linux", target_env = "gnu", target_arch = "csky"),
1703        link_name = "cfgetospeed@GLIBC_2.29"
1704    )]
1705    #[cfg_attr(
1706        all(target_os = "linux", target_env = "gnu", target_arch = "m68k"),
1707        link_name = "cfgetospeed@GLIBC_2.0"
1708    )]
1709    #[cfg_attr(
1710        all(target_os = "linux", target_env = "gnu", target_arch = "mips"),
1711        link_name = "cfgetospeed@GLIBC_2.0"
1712    )]
1713    #[cfg_attr(
1714        all(target_os = "linux", target_env = "gnu", target_arch = "powerpc"),
1715        link_name = "cfgetospeed@GLIBC_2.0"
1716    )]
1717    #[cfg_attr(
1718        all(target_os = "linux", target_env = "gnu", target_arch = "riscv32"),
1719        link_name = "cfgetospeed@GLIBC_2.33"
1720    )]
1721    #[cfg_attr(
1722        all(target_os = "linux", target_env = "gnu", target_arch = "sparc"),
1723        link_name = "cfgetospeed@GLIBC_2.0"
1724    )]
1725    #[cfg_attr(
1726        all(target_os = "linux", target_env = "gnu", target_arch = "x86"),
1727        link_name = "cfgetospeed@GLIBC_2.0"
1728    )]
1729    #[cfg_attr(
1730        all(target_os = "linux", target_env = "gnu", target_arch = "aarch64"),
1731        link_name = "cfgetospeed@GLIBC_2.17"
1732    )]
1733    #[cfg_attr(
1734        all(target_os = "linux", target_env = "gnu", target_arch = "loongarch64"),
1735        link_name = "cfgetospeed@GLIBC_2.36"
1736    )]
1737    #[cfg_attr(
1738        all(target_os = "linux", target_env = "gnu", target_arch = "mips64"),
1739        link_name = "cfgetospeed@GLIBC_2.0"
1740    )]
1741    #[cfg_attr(
1742        all(
1743            target_os = "linux",
1744            target_env = "gnu",
1745            target_arch = "powerpc64",
1746            target_endian = "big"
1747        ),
1748        link_name = "cfgetospeed@GLIBC_2.3"
1749    )]
1750    #[cfg_attr(
1751        all(
1752            target_os = "linux",
1753            target_env = "gnu",
1754            target_arch = "powerpc64",
1755            target_endian = "little"
1756        ),
1757        link_name = "cfgetospeed@GLIBC_2.17"
1758    )]
1759    #[cfg_attr(
1760        all(target_os = "linux", target_env = "gnu", target_arch = "riscv64"),
1761        link_name = "cfgetospeed@GLIBC_2.27"
1762    )]
1763    #[cfg_attr(
1764        all(target_os = "linux", target_env = "gnu", target_arch = "s390x"),
1765        link_name = "cfgetospeed@GLIBC_2.2"
1766    )]
1767    #[cfg_attr(
1768        all(target_os = "linux", target_env = "gnu", target_arch = "sparc64"),
1769        link_name = "cfgetospeed@GLIBC_2.2"
1770    )]
1771    #[cfg_attr(
1772        all(
1773            target_os = "linux",
1774            target_env = "gnu",
1775            target_arch = "x86_64",
1776            target_pointer_width = "64"
1777        ),
1778        link_name = "cfgetospeed@GLIBC_2.2.5"
1779    )]
1780    #[cfg_attr(
1781        all(
1782            target_os = "linux",
1783            target_env = "gnu",
1784            target_arch = "x86_64",
1785            target_pointer_width = "32"
1786        ),
1787        link_name = "cfgetospeed@GLIBC_2.16"
1788    )]
1789    pub fn cfgetospeed(termios: *const crate::termios) -> crate::speed_t;
1790    #[cfg_attr(
1791        all(target_os = "linux", target_env = "gnu", target_arch = "arm"),
1792        link_name = "cfsetispeed@GLIBC_2.4"
1793    )]
1794    #[cfg_attr(
1795        all(target_os = "linux", target_env = "gnu", target_arch = "csky"),
1796        link_name = "cfsetispeed@GLIBC_2.29"
1797    )]
1798    #[cfg_attr(
1799        all(target_os = "linux", target_env = "gnu", target_arch = "m68k"),
1800        link_name = "cfsetispeed@GLIBC_2.0"
1801    )]
1802    #[cfg_attr(
1803        all(target_os = "linux", target_env = "gnu", target_arch = "mips"),
1804        link_name = "cfsetispeed@GLIBC_2.0"
1805    )]
1806    #[cfg_attr(
1807        all(target_os = "linux", target_env = "gnu", target_arch = "powerpc"),
1808        link_name = "cfsetispeed@GLIBC_2.0"
1809    )]
1810    #[cfg_attr(
1811        all(target_os = "linux", target_env = "gnu", target_arch = "riscv32"),
1812        link_name = "cfsetispeed@GLIBC_2.33"
1813    )]
1814    #[cfg_attr(
1815        all(target_os = "linux", target_env = "gnu", target_arch = "sparc"),
1816        link_name = "cfsetispeed@GLIBC_2.0"
1817    )]
1818    #[cfg_attr(
1819        all(target_os = "linux", target_env = "gnu", target_arch = "x86"),
1820        link_name = "cfsetispeed@GLIBC_2.0"
1821    )]
1822    #[cfg_attr(
1823        all(target_os = "linux", target_env = "gnu", target_arch = "aarch64"),
1824        link_name = "cfsetispeed@GLIBC_2.17"
1825    )]
1826    #[cfg_attr(
1827        all(target_os = "linux", target_env = "gnu", target_arch = "loongarch64"),
1828        link_name = "cfsetispeed@GLIBC_2.36"
1829    )]
1830    #[cfg_attr(
1831        all(target_os = "linux", target_env = "gnu", target_arch = "mips64"),
1832        link_name = "cfsetispeed@GLIBC_2.0"
1833    )]
1834    #[cfg_attr(
1835        all(
1836            target_os = "linux",
1837            target_env = "gnu",
1838            target_arch = "powerpc64",
1839            target_endian = "big"
1840        ),
1841        link_name = "cfsetispeed@GLIBC_2.3"
1842    )]
1843    #[cfg_attr(
1844        all(
1845            target_os = "linux",
1846            target_env = "gnu",
1847            target_arch = "powerpc64",
1848            target_endian = "little"
1849        ),
1850        link_name = "cfsetispeed@GLIBC_2.17"
1851    )]
1852    #[cfg_attr(
1853        all(target_os = "linux", target_env = "gnu", target_arch = "riscv64"),
1854        link_name = "cfsetispeed@GLIBC_2.27"
1855    )]
1856    #[cfg_attr(
1857        all(target_os = "linux", target_env = "gnu", target_arch = "s390x"),
1858        link_name = "cfsetispeed@GLIBC_2.2"
1859    )]
1860    #[cfg_attr(
1861        all(target_os = "linux", target_env = "gnu", target_arch = "sparc64"),
1862        link_name = "cfsetispeed@GLIBC_2.2"
1863    )]
1864    #[cfg_attr(
1865        all(
1866            target_os = "linux",
1867            target_env = "gnu",
1868            target_arch = "x86_64",
1869            target_pointer_width = "64"
1870        ),
1871        link_name = "cfsetispeed@GLIBC_2.2.5"
1872    )]
1873    #[cfg_attr(
1874        all(
1875            target_os = "linux",
1876            target_env = "gnu",
1877            target_arch = "x86_64",
1878            target_pointer_width = "32"
1879        ),
1880        link_name = "cfsetispeed@GLIBC_2.16"
1881    )]
1882    pub fn cfsetispeed(termios: *mut crate::termios, speed: crate::speed_t) -> c_int;
1883    #[cfg_attr(
1884        all(target_os = "linux", target_env = "gnu", target_arch = "arm"),
1885        link_name = "cfsetospeed@GLIBC_2.4"
1886    )]
1887    #[cfg_attr(
1888        all(target_os = "linux", target_env = "gnu", target_arch = "csky"),
1889        link_name = "cfsetospeed@GLIBC_2.29"
1890    )]
1891    #[cfg_attr(
1892        all(target_os = "linux", target_env = "gnu", target_arch = "m68k"),
1893        link_name = "cfsetospeed@GLIBC_2.0"
1894    )]
1895    #[cfg_attr(
1896        all(target_os = "linux", target_env = "gnu", target_arch = "mips"),
1897        link_name = "cfsetospeed@GLIBC_2.0"
1898    )]
1899    #[cfg_attr(
1900        all(target_os = "linux", target_env = "gnu", target_arch = "powerpc"),
1901        link_name = "cfsetospeed@GLIBC_2.0"
1902    )]
1903    #[cfg_attr(
1904        all(target_os = "linux", target_env = "gnu", target_arch = "riscv32"),
1905        link_name = "cfsetospeed@GLIBC_2.33"
1906    )]
1907    #[cfg_attr(
1908        all(target_os = "linux", target_env = "gnu", target_arch = "sparc"),
1909        link_name = "cfsetospeed@GLIBC_2.0"
1910    )]
1911    #[cfg_attr(
1912        all(target_os = "linux", target_env = "gnu", target_arch = "x86"),
1913        link_name = "cfsetospeed@GLIBC_2.0"
1914    )]
1915    #[cfg_attr(
1916        all(target_os = "linux", target_env = "gnu", target_arch = "aarch64"),
1917        link_name = "cfsetospeed@GLIBC_2.17"
1918    )]
1919    #[cfg_attr(
1920        all(target_os = "linux", target_env = "gnu", target_arch = "loongarch64"),
1921        link_name = "cfsetospeed@GLIBC_2.36"
1922    )]
1923    #[cfg_attr(
1924        all(target_os = "linux", target_env = "gnu", target_arch = "mips64"),
1925        link_name = "cfsetospeed@GLIBC_2.0"
1926    )]
1927    #[cfg_attr(
1928        all(
1929            target_os = "linux",
1930            target_env = "gnu",
1931            target_arch = "powerpc64",
1932            target_endian = "big"
1933        ),
1934        link_name = "cfsetospeed@GLIBC_2.3"
1935    )]
1936    #[cfg_attr(
1937        all(
1938            target_os = "linux",
1939            target_env = "gnu",
1940            target_arch = "powerpc64",
1941            target_endian = "little"
1942        ),
1943        link_name = "cfsetospeed@GLIBC_2.17"
1944    )]
1945    #[cfg_attr(
1946        all(target_os = "linux", target_env = "gnu", target_arch = "riscv64"),
1947        link_name = "cfsetospeed@GLIBC_2.27"
1948    )]
1949    #[cfg_attr(
1950        all(target_os = "linux", target_env = "gnu", target_arch = "s390x"),
1951        link_name = "cfsetospeed@GLIBC_2.2"
1952    )]
1953    #[cfg_attr(
1954        all(target_os = "linux", target_env = "gnu", target_arch = "sparc64"),
1955        link_name = "cfsetospeed@GLIBC_2.2"
1956    )]
1957    #[cfg_attr(
1958        all(
1959            target_os = "linux",
1960            target_env = "gnu",
1961            target_arch = "x86_64",
1962            target_pointer_width = "64"
1963        ),
1964        link_name = "cfsetospeed@GLIBC_2.2.5"
1965    )]
1966    #[cfg_attr(
1967        all(
1968            target_os = "linux",
1969            target_env = "gnu",
1970            target_arch = "x86_64",
1971            target_pointer_width = "32"
1972        ),
1973        link_name = "cfsetospeed@GLIBC_2.16"
1974    )]
1975    pub fn cfsetospeed(termios: *mut crate::termios, speed: crate::speed_t) -> c_int;
1976    pub fn tcgetattr(fd: c_int, termios: *mut crate::termios) -> c_int;
1977    pub fn tcsetattr(fd: c_int, optional_actions: c_int, termios: *const crate::termios) -> c_int;
1978    pub fn tcflow(fd: c_int, action: c_int) -> c_int;
1979    pub fn tcflush(fd: c_int, action: c_int) -> c_int;
1980    pub fn tcgetsid(fd: c_int) -> crate::pid_t;
1981    pub fn tcsendbreak(fd: c_int, duration: c_int) -> c_int;
1982    #[cfg_attr(gnu_file_offset_bits64, link_name = "mkstemp64")]
1983    pub fn mkstemp(template: *mut c_char) -> c_int;
1984    pub fn mkdtemp(template: *mut c_char) -> *mut c_char;
1985
1986    pub fn tmpnam(ptr: *mut c_char) -> *mut c_char;
1987
1988    pub fn openlog(ident: *const c_char, logopt: c_int, facility: c_int);
1989    pub fn closelog();
1990    pub fn setlogmask(maskpri: c_int) -> c_int;
1991    #[cfg_attr(target_os = "macos", link_name = "syslog$DARWIN_EXTSN")]
1992    pub fn syslog(priority: c_int, message: *const c_char, ...);
1993    #[cfg_attr(
1994        all(target_os = "macos", target_arch = "x86"),
1995        link_name = "nice$UNIX2003"
1996    )]
1997    pub fn nice(incr: c_int) -> c_int;
1998
1999    #[cfg(not(target_os = "l4re"))]
2000    pub fn grantpt(fd: c_int) -> c_int;
2001    #[cfg(not(target_os = "l4re"))]
2002    pub fn posix_openpt(flags: c_int) -> c_int;
2003    #[cfg(not(target_os = "l4re"))]
2004    pub fn ptsname(fd: c_int) -> *mut c_char;
2005    #[cfg(not(target_os = "l4re"))]
2006    pub fn unlockpt(fd: c_int) -> c_int;
2007
2008    #[cfg(not(target_os = "aix"))]
2009    pub fn strcasestr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
2010    pub fn getline(lineptr: *mut *mut c_char, n: *mut size_t, stream: *mut FILE) -> ssize_t;
2011
2012    #[cfg_attr(gnu_file_offset_bits64, link_name = "lockf64")]
2013    pub fn lockf(fd: c_int, cmd: c_int, len: off_t) -> c_int;
2014
2015}
2016
2017safe_f! {
2018    // It seems htonl, etc are macros on macOS. So we have to reimplement them. So let's
2019    // reimplement them for all UNIX platforms
2020    pub const fn htonl(hostlong: u32) -> u32 {
2021        u32::to_be(hostlong)
2022    }
2023    pub const fn htons(hostshort: u16) -> u16 {
2024        u16::to_be(hostshort)
2025    }
2026    pub const fn ntohl(netlong: u32) -> u32 {
2027        u32::from_be(netlong)
2028    }
2029    pub const fn ntohs(netshort: u16) -> u16 {
2030        u16::from_be(netshort)
2031    }
2032}
2033
2034cfg_if! {
2035    if #[cfg(not(any(
2036        target_os = "emscripten",
2037        target_os = "android",
2038        target_os = "haiku",
2039        target_os = "nto",
2040        target_os = "solaris",
2041        target_os = "cygwin",
2042        target_os = "aix",
2043        target_os = "l4re",
2044    )))] {
2045        extern "C" {
2046            #[cfg_attr(target_os = "netbsd", link_name = "__adjtime50")]
2047            #[cfg_attr(any(gnu_time_bits64, musl32_time64), link_name = "__adjtime64")]
2048            pub fn adjtime(delta: *const timeval, olddelta: *mut timeval) -> c_int;
2049        }
2050    } else if #[cfg(target_os = "solaris")] {
2051        extern "C" {
2052            pub fn adjtime(delta: *mut timeval, olddelta: *mut timeval) -> c_int;
2053        }
2054    }
2055}
2056
2057cfg_if! {
2058    if #[cfg(not(any(
2059        target_os = "emscripten",
2060        target_os = "android",
2061        target_os = "nto"
2062    )))] {
2063        extern "C" {
2064            pub fn stpncpy(dst: *mut c_char, src: *const c_char, n: size_t) -> *mut c_char;
2065        }
2066    }
2067}
2068
2069cfg_if! {
2070    if #[cfg(not(any(
2071        target_os = "dragonfly",
2072        target_os = "emscripten",
2073        target_os = "hurd",
2074        target_os = "macos",
2075        target_os = "openbsd",
2076        target_os = "l4re",
2077    )))] {
2078        extern "C" {
2079            pub fn sigqueue(pid: pid_t, sig: c_int, value: crate::sigval) -> c_int;
2080        }
2081    }
2082}
2083
2084cfg_if! {
2085    if #[cfg(not(target_os = "android"))] {
2086        extern "C" {
2087            #[cfg_attr(
2088                all(target_os = "macos", target_arch = "x86"),
2089                link_name = "confstr$UNIX2003"
2090            )]
2091            #[cfg_attr(target_os = "solaris", link_name = "__confstr_xpg7")]
2092            pub fn confstr(name: c_int, buf: *mut c_char, len: size_t) -> size_t;
2093        }
2094    }
2095}
2096
2097cfg_if! {
2098    if #[cfg(not(target_os = "aix"))] {
2099        extern "C" {
2100            pub fn dladdr(addr: *const c_void, info: *mut Dl_info) -> c_int;
2101        }
2102    }
2103}
2104
2105cfg_if! {
2106    if #[cfg(not(target_os = "solaris"))] {
2107        extern "C" {
2108            pub fn flock(fd: c_int, operation: c_int) -> c_int;
2109        }
2110    }
2111}
2112
2113cfg_if! {
2114    if #[cfg(not(any(target_env = "uclibc", target_os = "nto")))] {
2115        extern "C" {
2116            pub fn open_wmemstream(ptr: *mut *mut wchar_t, sizeloc: *mut size_t) -> *mut FILE;
2117        }
2118    }
2119}
2120
2121cfg_if! {
2122    if #[cfg(not(target_os = "redox"))] {
2123        extern "C" {
2124            pub fn getsid(pid: pid_t) -> pid_t;
2125            #[cfg_attr(
2126                all(target_os = "macos", target_arch = "x86"),
2127                link_name = "pause$UNIX2003"
2128            )]
2129            pub fn pause() -> c_int;
2130
2131            #[cfg(not(target_os = "l4re"))]
2132            pub fn mkdirat(dirfd: c_int, pathname: *const c_char, mode: mode_t) -> c_int;
2133            #[cfg_attr(gnu_file_offset_bits64, link_name = "openat64")]
2134            pub fn openat(dirfd: c_int, pathname: *const c_char, flags: c_int, ...) -> c_int;
2135
2136            #[cfg_attr(
2137                all(target_os = "macos", target_arch = "x86_64"),
2138                link_name = "fdopendir$INODE64"
2139            )]
2140            #[cfg_attr(
2141                all(target_os = "macos", target_arch = "x86"),
2142                link_name = "fdopendir$INODE64$UNIX2003"
2143            )]
2144            pub fn fdopendir(fd: c_int) -> *mut crate::DIR;
2145
2146            #[cfg_attr(
2147                all(target_os = "macos", not(target_arch = "aarch64")),
2148                link_name = "readdir_r$INODE64"
2149            )]
2150            #[cfg_attr(target_os = "netbsd", link_name = "__readdir_r30")]
2151            #[cfg_attr(
2152                all(target_os = "freebsd", any(freebsd11, freebsd10)),
2153                link_name = "readdir_r@FBSD_1.0"
2154            )]
2155            #[cfg_attr(
2156                all(target_os = "freebsd", not(any(freebsd11, freebsd10))),
2157                link_name = "readdir_r@FBSD_1.5"
2158            )]
2159            #[allow(non_autolinks)] // FIXME(docs): `<>` breaks line length limit.
2160            /// The 64-bit libc on Solaris and illumos only has readdir_r. If a
2161            /// 32-bit Solaris or illumos target is ever created, it should use
2162            /// __posix_readdir_r. See libc(3LIB) on Solaris or illumos:
2163            /// https://illumos.org/man/3lib/libc
2164            /// https://docs.oracle.com/cd/E36784_01/html/E36873/libc-3lib.html
2165            /// https://www.unix.com/man-page/opensolaris/3LIB/libc/
2166            #[cfg_attr(gnu_file_offset_bits64, link_name = "readdir64_r")]
2167            pub fn readdir_r(
2168                dirp: *mut crate::DIR,
2169                entry: *mut crate::dirent,
2170                result: *mut *mut crate::dirent,
2171            ) -> c_int;
2172        }
2173    }
2174}
2175
2176cfg_if! {
2177    if #[cfg(target_os = "nto")] {
2178        extern "C" {
2179            pub fn readlinkat(
2180                dirfd: c_int,
2181                pathname: *const c_char,
2182                buf: *mut c_char,
2183                bufsiz: size_t,
2184            ) -> c_int;
2185            pub fn readlink(path: *const c_char, buf: *mut c_char, bufsz: size_t) -> c_int;
2186            pub fn pselect(
2187                nfds: c_int,
2188                readfds: *mut fd_set,
2189                writefds: *mut fd_set,
2190                errorfds: *mut fd_set,
2191                timeout: *mut timespec,
2192                sigmask: *const sigset_t,
2193            ) -> c_int;
2194            pub fn sigaction(signum: c_int, act: *const sigaction, oldact: *mut sigaction)
2195                -> c_int;
2196        }
2197    } else {
2198        extern "C" {
2199            #[cfg(not(target_os = "l4re"))]
2200            pub fn readlinkat(
2201                dirfd: c_int,
2202                pathname: *const c_char,
2203                buf: *mut c_char,
2204                bufsiz: size_t,
2205            ) -> ssize_t;
2206            #[cfg(not(target_os = "l4re"))]
2207            pub fn fmemopen(buf: *mut c_void, size: size_t, mode: *const c_char) -> *mut FILE;
2208            #[cfg(not(target_os = "l4re"))]
2209            pub fn open_memstream(ptr: *mut *mut c_char, sizeloc: *mut size_t) -> *mut FILE;
2210            pub fn atexit(cb: extern "C" fn()) -> c_int;
2211            #[cfg_attr(target_os = "netbsd", link_name = "__sigaction14")]
2212            pub fn sigaction(signum: c_int, act: *const sigaction, oldact: *mut sigaction)
2213                -> c_int;
2214            pub fn readlink(path: *const c_char, buf: *mut c_char, bufsz: size_t) -> ssize_t;
2215            #[cfg_attr(
2216                all(target_os = "macos", target_arch = "x86_64"),
2217                link_name = "pselect$1050"
2218            )]
2219            #[cfg_attr(
2220                all(target_os = "macos", target_arch = "x86"),
2221                link_name = "pselect$UNIX2003"
2222            )]
2223            #[cfg_attr(target_os = "netbsd", link_name = "__pselect50")]
2224            #[cfg_attr(gnu_time_bits64, link_name = "__pselect64")]
2225            #[cfg_attr(musl32_time64, link_name = "__pselect_time64")]
2226            pub fn pselect(
2227                nfds: c_int,
2228                readfds: *mut fd_set,
2229                writefds: *mut fd_set,
2230                errorfds: *mut fd_set,
2231                timeout: *const timespec,
2232                sigmask: *const sigset_t,
2233            ) -> c_int;
2234        }
2235    }
2236}
2237
2238cfg_if! {
2239    if #[cfg(any(target_os = "aix", target_os = "nto"))] {
2240        extern "C" {
2241            pub fn cfmakeraw(termios: *mut crate::termios) -> c_int;
2242        }
2243    } else if #[cfg(not(any(target_os = "solaris", target_os = "illumos",)))] {
2244        extern "C" {
2245            pub fn cfmakeraw(termios: *mut crate::termios);
2246        }
2247    }
2248}
2249
2250cfg_if! {
2251    if #[cfg(any(
2252        target_os = "aix",
2253        all(target_os = "nto", target_env = "nto80")
2254    ))] {
2255        extern "C" {
2256            pub fn cfsetspeed(termios: *mut crate::termios, speed: crate::speed_t) -> c_int;
2257        }
2258    } else if #[cfg(not(any(
2259        target_os = "solaris",
2260        target_os = "illumos",
2261        target_os = "nto"
2262    )))] {
2263        extern "C" {
2264            #[cfg(not(target_os = "l4re"))]
2265            #[cfg_attr(
2266                all(target_os = "linux", target_env = "gnu", target_arch = "arm"),
2267                link_name = "cfsetspeed@GLIBC_2.4"
2268            )]
2269            #[cfg_attr(
2270                all(target_os = "linux", target_env = "gnu", target_arch = "csky"),
2271                link_name = "cfsetspeed@GLIBC_2.29"
2272            )]
2273            #[cfg_attr(
2274                all(target_os = "linux", target_env = "gnu", target_arch = "m68k"),
2275                link_name = "cfsetspeed@GLIBC_2.0"
2276            )]
2277            #[cfg_attr(
2278                all(target_os = "linux", target_env = "gnu", target_arch = "mips"),
2279                link_name = "cfsetspeed@GLIBC_2.0"
2280            )]
2281            #[cfg_attr(
2282                all(target_os = "linux", target_env = "gnu", target_arch = "powerpc"),
2283                link_name = "cfsetspeed@GLIBC_2.0"
2284            )]
2285            #[cfg_attr(
2286                all(target_os = "linux", target_env = "gnu", target_arch = "riscv32"),
2287                link_name = "cfsetspeed@GLIBC_2.33"
2288            )]
2289            #[cfg_attr(
2290                all(target_os = "linux", target_env = "gnu", target_arch = "sparc"),
2291                link_name = "cfsetspeed@GLIBC_2.0"
2292            )]
2293            #[cfg_attr(
2294                all(target_os = "linux", target_env = "gnu", target_arch = "x86"),
2295                link_name = "cfsetspeed@GLIBC_2.0"
2296            )]
2297            #[cfg_attr(
2298                all(target_os = "linux", target_env = "gnu", target_arch = "aarch64"),
2299                link_name = "cfsetspeed@GLIBC_2.17"
2300            )]
2301            #[cfg_attr(
2302                all(target_os = "linux", target_env = "gnu", target_arch = "loongarch64"),
2303                link_name = "cfsetspeed@GLIBC_2.36"
2304            )]
2305            #[cfg_attr(
2306                all(target_os = "linux", target_env = "gnu", target_arch = "mips64"),
2307                link_name = "cfsetspeed@GLIBC_2.0"
2308            )]
2309            #[cfg_attr(
2310                all(
2311                    target_os = "linux",
2312                    target_env = "gnu",
2313                    target_arch = "powerpc64",
2314                    target_endian = "big"
2315                ),
2316                link_name = "cfsetspeed@GLIBC_2.3"
2317            )]
2318            #[cfg_attr(
2319                all(
2320                    target_os = "linux",
2321                    target_env = "gnu",
2322                    target_arch = "powerpc64",
2323                    target_endian = "little"
2324                ),
2325                link_name = "cfsetspeed@GLIBC_2.17"
2326            )]
2327            #[cfg_attr(
2328                all(target_os = "linux", target_env = "gnu", target_arch = "riscv64"),
2329                link_name = "cfsetspeed@GLIBC_2.27"
2330            )]
2331            #[cfg_attr(
2332                all(target_os = "linux", target_env = "gnu", target_arch = "s390x"),
2333                link_name = "cfsetspeed@GLIBC_2.2"
2334            )]
2335            #[cfg_attr(
2336                all(target_os = "linux", target_env = "gnu", target_arch = "sparc64"),
2337                link_name = "cfsetspeed@GLIBC_2.2"
2338            )]
2339            #[cfg_attr(
2340                all(
2341                    target_os = "linux",
2342                    target_env = "gnu",
2343                    target_arch = "x86_64",
2344                    target_pointer_width = "64"
2345                ),
2346                link_name = "cfsetspeed@GLIBC_2.2.5"
2347            )]
2348            #[cfg_attr(
2349                all(
2350                    target_os = "linux",
2351                    target_env = "gnu",
2352                    target_arch = "x86_64",
2353                    target_pointer_width = "32"
2354                ),
2355                link_name = "cfsetspeed@GLIBC_2.16"
2356            )]
2357            pub fn cfsetspeed(termios: *mut crate::termios, speed: crate::speed_t) -> c_int;
2358        }
2359    }
2360}
2361
2362extern "C" {
2363    pub fn fnmatch(pattern: *const c_char, name: *const c_char, flags: c_int) -> c_int;
2364}
2365
2366cfg_if! {
2367    if #[cfg(target_env = "newlib")] {
2368        mod newlib;
2369        pub use self::newlib::*;
2370    } else if #[cfg(any(
2371        target_os = "linux",
2372        target_os = "l4re",
2373        target_os = "android",
2374        target_os = "emscripten"
2375    ))] {
2376        mod linux_like;
2377        pub use self::linux_like::*;
2378    } else if #[cfg(any(
2379        target_os = "macos",
2380        target_os = "ios",
2381        target_os = "tvos",
2382        target_os = "watchos",
2383        target_os = "visionos",
2384        target_os = "freebsd",
2385        target_os = "dragonfly",
2386        target_os = "openbsd",
2387        target_os = "netbsd"
2388    ))] {
2389        mod bsd;
2390        pub use self::bsd::*;
2391    } else if #[cfg(any(target_os = "solaris", target_os = "illumos"))] {
2392        mod solarish;
2393        pub use self::solarish::*;
2394    } else if #[cfg(target_os = "haiku")] {
2395        mod haiku;
2396        pub use self::haiku::*;
2397    } else if #[cfg(target_os = "redox")] {
2398        mod redox;
2399        pub use self::redox::*;
2400    } else if #[cfg(target_os = "cygwin")] {
2401        mod cygwin;
2402        pub use self::cygwin::*;
2403    } else if #[cfg(target_os = "nto")] {
2404        mod nto;
2405        pub use self::nto::*;
2406    } else if #[cfg(target_os = "aix")] {
2407        mod aix;
2408        pub use self::aix::*;
2409    } else if #[cfg(target_os = "hurd")] {
2410        mod hurd;
2411        pub use self::hurd::*;
2412    } else if #[cfg(target_os = "nuttx")] {
2413        mod nuttx;
2414        pub use self::nuttx::*;
2415    } else {
2416        // Unknown target_os
2417    }
2418}