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