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