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