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