Skip to main content

libc/unix/bsd/
mod.rs

1use crate::prelude::*;
2
3pub type off_t = i64;
4pub type useconds_t = u32;
5pub type blkcnt_t = i64;
6pub type socklen_t = u32;
7pub type sa_family_t = u8;
8pub type pthread_t = crate::uintptr_t;
9pub type nfds_t = c_uint;
10#[cfg(target_os = "dragonfly")]
11pub type regoff_t = c_int;
12#[cfg(not(target_os = "dragonfly"))]
13pub type regoff_t = off_t;
14
15s! {
16    pub struct sockaddr {
17        pub sa_len: u8,
18        pub sa_family: sa_family_t,
19        pub sa_data: [c_char; 14],
20    }
21
22    pub struct sockaddr_in6 {
23        pub sin6_len: u8,
24        pub sin6_family: sa_family_t,
25        pub sin6_port: crate::in_port_t,
26        pub sin6_flowinfo: u32,
27        pub sin6_addr: crate::in6_addr,
28        pub sin6_scope_id: u32,
29    }
30
31    pub struct passwd {
32        pub pw_name: *mut c_char,
33        pub pw_passwd: *mut c_char,
34        pub pw_uid: crate::uid_t,
35        pub pw_gid: crate::gid_t,
36        pub pw_change: crate::time_t,
37        pub pw_class: *mut c_char,
38        pub pw_gecos: *mut c_char,
39        pub pw_dir: *mut c_char,
40        pub pw_shell: *mut c_char,
41        pub pw_expire: crate::time_t,
42
43        #[cfg(not(any(
44            target_os = "macos",
45            target_os = "ios",
46            target_os = "tvos",
47            target_os = "watchos",
48            target_os = "visionos",
49            target_os = "netbsd",
50            target_os = "openbsd"
51        )))]
52        pub pw_fields: c_int,
53    }
54
55    pub struct ifaddrs {
56        pub ifa_next: *mut ifaddrs,
57        pub ifa_name: *mut c_char,
58        pub ifa_flags: c_uint,
59        pub ifa_addr: *mut crate::sockaddr,
60        pub ifa_netmask: *mut crate::sockaddr,
61        pub ifa_dstaddr: *mut crate::sockaddr,
62        pub ifa_data: *mut c_void,
63        #[cfg(any(target_os = "dragonfly", target_os = "netbsd"))]
64        pub ifa_addrflags: c_uint,
65    }
66
67    pub struct fd_set {
68        #[cfg(all(
69            target_pointer_width = "64",
70            any(target_os = "freebsd", target_os = "dragonfly")
71        ))]
72        fds_bits: [i64; FD_SETSIZE as usize / 64],
73        #[cfg(not(all(
74            target_pointer_width = "64",
75            any(target_os = "freebsd", target_os = "dragonfly")
76        )))]
77        fds_bits: [i32; FD_SETSIZE as usize / 32],
78    }
79
80    pub struct msghdr {
81        pub msg_name: *mut c_void,
82        pub msg_namelen: crate::socklen_t,
83        pub msg_iov: *mut crate::iovec,
84        pub msg_iovlen: c_int,
85        pub msg_control: *mut c_void,
86        pub msg_controllen: crate::socklen_t,
87        pub msg_flags: c_int,
88    }
89
90    pub struct cmsghdr {
91        pub cmsg_len: crate::socklen_t,
92        pub cmsg_level: c_int,
93        pub cmsg_type: c_int,
94    }
95
96    pub struct fsid_t {
97        __fsid_val: [i32; 2],
98    }
99
100    pub struct if_nameindex {
101        pub if_index: c_uint,
102        pub if_name: *mut c_char,
103    }
104
105    pub struct regex_t {
106        __re_magic: c_int,
107        __re_nsub: size_t,
108        __re_endp: *const c_char,
109        __re_g: *mut c_void,
110    }
111
112    pub struct regmatch_t {
113        pub rm_so: regoff_t,
114        pub rm_eo: regoff_t,
115    }
116
117    pub struct option {
118        pub name: *const c_char,
119        pub has_arg: c_int,
120        pub flag: *mut c_int,
121        pub val: c_int,
122    }
123    pub struct sockaddr_un {
124        pub sun_len: u8,
125        pub sun_family: sa_family_t,
126        pub sun_path: [c_char; 104],
127    }
128
129    pub struct utsname {
130        #[cfg(not(target_os = "dragonfly"))]
131        pub sysname: [c_char; 256],
132        #[cfg(target_os = "dragonfly")]
133        pub sysname: [c_char; 32],
134        #[cfg(not(target_os = "dragonfly"))]
135        pub nodename: [c_char; 256],
136        #[cfg(target_os = "dragonfly")]
137        pub nodename: [c_char; 32],
138        #[cfg(not(target_os = "dragonfly"))]
139        pub release: [c_char; 256],
140        #[cfg(target_os = "dragonfly")]
141        pub release: [c_char; 32],
142        #[cfg(not(target_os = "dragonfly"))]
143        pub version: [c_char; 256],
144        #[cfg(target_os = "dragonfly")]
145        pub version: [c_char; 32],
146        #[cfg(not(target_os = "dragonfly"))]
147        pub machine: [c_char; 256],
148        #[cfg(target_os = "dragonfly")]
149        pub machine: [c_char; 32],
150    }
151}
152
153pub const LC_ALL: c_int = 0;
154pub const LC_COLLATE: c_int = 1;
155pub const LC_CTYPE: c_int = 2;
156pub const LC_MONETARY: c_int = 3;
157pub const LC_NUMERIC: c_int = 4;
158pub const LC_TIME: c_int = 5;
159pub const LC_MESSAGES: c_int = 6;
160
161pub const FIOCLEX: c_ulong = 0x20006601;
162pub const FIONCLEX: c_ulong = 0x20006602;
163pub const FIONREAD: c_ulong = 0x4004667f;
164pub const FIONBIO: c_ulong = 0x8004667e;
165pub const FIOASYNC: c_ulong = 0x8004667d;
166pub const FIOSETOWN: c_ulong = 0x8004667c;
167pub const FIOGETOWN: c_ulong = 0x4004667b;
168
169/// Constants may change across releases. See the [usage guidelines](crate#usage-guidelines)
170/// for details.
171pub const PATH_MAX: c_int = 1024;
172
173pub const MAXPATHLEN: c_int = PATH_MAX;
174
175pub const IOV_MAX: c_int = 1024;
176
177pub const SA_ONSTACK: c_int = 0x0001;
178pub const SA_SIGINFO: c_int = 0x0040;
179pub const SA_RESTART: c_int = 0x0002;
180pub const SA_RESETHAND: c_int = 0x0004;
181pub const SA_NOCLDSTOP: c_int = 0x0008;
182pub const SA_NODEFER: c_int = 0x0010;
183pub const SA_NOCLDWAIT: c_int = 0x0020;
184
185pub const SS_ONSTACK: c_int = 1;
186pub const SS_DISABLE: c_int = 4;
187
188pub const SIGCHLD: c_int = 20;
189pub const SIGBUS: c_int = 10;
190pub const SIGUSR1: c_int = 30;
191pub const SIGUSR2: c_int = 31;
192pub const SIGCONT: c_int = 19;
193pub const SIGSTOP: c_int = 17;
194pub const SIGTSTP: c_int = 18;
195pub const SIGURG: c_int = 16;
196pub const SIGIO: c_int = 23;
197pub const SIGSYS: c_int = 12;
198pub const SIGTTIN: c_int = 21;
199pub const SIGTTOU: c_int = 22;
200pub const SIGXCPU: c_int = 24;
201pub const SIGXFSZ: c_int = 25;
202pub const SIGVTALRM: c_int = 26;
203pub const SIGPROF: c_int = 27;
204pub const SIGWINCH: c_int = 28;
205pub const SIGINFO: c_int = 29;
206
207pub const SIG_SETMASK: c_int = 3;
208pub const SIG_BLOCK: c_int = 0x1;
209pub const SIG_UNBLOCK: c_int = 0x2;
210
211pub const IP_TOS: c_int = 3;
212pub const IP_MULTICAST_IF: c_int = 9;
213pub const IP_MULTICAST_TTL: c_int = 10;
214pub const IP_MULTICAST_LOOP: c_int = 11;
215
216pub const IPV6_UNICAST_HOPS: c_int = 4;
217pub const IPV6_MULTICAST_IF: c_int = 9;
218pub const IPV6_MULTICAST_HOPS: c_int = 10;
219pub const IPV6_MULTICAST_LOOP: c_int = 11;
220pub const IPV6_V6ONLY: c_int = 27;
221pub const IPV6_DONTFRAG: c_int = 62;
222
223pub const IPTOS_ECN_NOTECT: u8 = 0x00;
224pub const IPTOS_ECN_MASK: u8 = 0x03;
225pub const IPTOS_ECN_ECT1: u8 = 0x01;
226pub const IPTOS_ECN_ECT0: u8 = 0x02;
227pub const IPTOS_ECN_CE: u8 = 0x03;
228
229pub const ST_RDONLY: c_ulong = 1;
230
231pub const SCM_RIGHTS: c_int = 0x01;
232
233pub const NCCS: usize = 20;
234
235pub const O_ACCMODE: c_int = 0x3;
236pub const O_RDONLY: c_int = 0;
237pub const O_WRONLY: c_int = 1;
238pub const O_RDWR: c_int = 2;
239pub const O_APPEND: c_int = 8;
240pub const O_CREAT: c_int = 512;
241pub const O_TRUNC: c_int = 1024;
242pub const O_EXCL: c_int = 2048;
243pub const O_ASYNC: c_int = 0x40;
244pub const O_SYNC: c_int = 0x80;
245pub const O_NONBLOCK: c_int = 0x4;
246pub const O_NOFOLLOW: c_int = 0x100;
247pub const O_SHLOCK: c_int = 0x10;
248pub const O_EXLOCK: c_int = 0x20;
249pub const O_FSYNC: c_int = O_SYNC;
250pub const O_NDELAY: c_int = O_NONBLOCK;
251
252pub const F_GETOWN: c_int = 5;
253pub const F_SETOWN: c_int = 6;
254
255pub const F_RDLCK: c_short = 1;
256pub const F_UNLCK: c_short = 2;
257pub const F_WRLCK: c_short = 3;
258
259pub const MNT_RDONLY: c_int = 0x00000001;
260pub const MNT_SYNCHRONOUS: c_int = 0x00000002;
261pub const MNT_NOEXEC: c_int = 0x00000004;
262pub const MNT_NOSUID: c_int = 0x00000008;
263pub const MNT_ASYNC: c_int = 0x00000040;
264pub const MNT_EXPORTED: c_int = 0x00000100;
265pub const MNT_UPDATE: c_int = 0x00010000;
266pub const MNT_RELOAD: c_int = 0x00040000;
267pub const MNT_FORCE: c_int = 0x00080000;
268
269pub const Q_SYNC: c_int = 0x600;
270pub const Q_QUOTAON: c_int = 0x100;
271pub const Q_QUOTAOFF: c_int = 0x200;
272
273pub const TCIOFF: c_int = 3;
274pub const TCION: c_int = 4;
275pub const TCOOFF: c_int = 1;
276pub const TCOON: c_int = 2;
277pub const TCIFLUSH: c_int = 1;
278pub const TCOFLUSH: c_int = 2;
279pub const TCIOFLUSH: c_int = 3;
280pub const TCSANOW: c_int = 0;
281pub const TCSADRAIN: c_int = 1;
282pub const TCSAFLUSH: c_int = 2;
283pub const VEOF: usize = 0;
284pub const VEOL: usize = 1;
285pub const VEOL2: usize = 2;
286pub const VERASE: usize = 3;
287pub const VWERASE: usize = 4;
288pub const VKILL: usize = 5;
289pub const VREPRINT: usize = 6;
290pub const VINTR: usize = 8;
291pub const VQUIT: usize = 9;
292pub const VSUSP: usize = 10;
293pub const VDSUSP: usize = 11;
294pub const VSTART: usize = 12;
295pub const VSTOP: usize = 13;
296pub const VLNEXT: usize = 14;
297pub const VDISCARD: usize = 15;
298pub const VMIN: usize = 16;
299pub const VTIME: usize = 17;
300pub const VSTATUS: usize = 18;
301pub const _POSIX_VDISABLE: crate::cc_t = 0xff;
302pub const IGNBRK: crate::tcflag_t = 0x00000001;
303pub const BRKINT: crate::tcflag_t = 0x00000002;
304pub const IGNPAR: crate::tcflag_t = 0x00000004;
305pub const PARMRK: crate::tcflag_t = 0x00000008;
306pub const INPCK: crate::tcflag_t = 0x00000010;
307pub const ISTRIP: crate::tcflag_t = 0x00000020;
308pub const INLCR: crate::tcflag_t = 0x00000040;
309pub const IGNCR: crate::tcflag_t = 0x00000080;
310pub const ICRNL: crate::tcflag_t = 0x00000100;
311pub const IXON: crate::tcflag_t = 0x00000200;
312pub const IXOFF: crate::tcflag_t = 0x00000400;
313pub const IXANY: crate::tcflag_t = 0x00000800;
314pub const IMAXBEL: crate::tcflag_t = 0x00002000;
315pub const OPOST: crate::tcflag_t = 0x1;
316pub const ONLCR: crate::tcflag_t = 0x2;
317pub const OXTABS: crate::tcflag_t = 0x4;
318pub const ONOEOT: crate::tcflag_t = 0x8;
319pub const CIGNORE: crate::tcflag_t = 0x00000001;
320pub const CSIZE: crate::tcflag_t = 0x00000300;
321pub const CS5: crate::tcflag_t = 0x00000000;
322pub const CS6: crate::tcflag_t = 0x00000100;
323pub const CS7: crate::tcflag_t = 0x00000200;
324pub const CS8: crate::tcflag_t = 0x00000300;
325pub const CSTOPB: crate::tcflag_t = 0x00000400;
326pub const CREAD: crate::tcflag_t = 0x00000800;
327pub const PARENB: crate::tcflag_t = 0x00001000;
328pub const PARODD: crate::tcflag_t = 0x00002000;
329pub const HUPCL: crate::tcflag_t = 0x00004000;
330pub const CLOCAL: crate::tcflag_t = 0x00008000;
331pub const ECHOKE: crate::tcflag_t = 0x00000001;
332pub const ECHOE: crate::tcflag_t = 0x00000002;
333pub const ECHOK: crate::tcflag_t = 0x00000004;
334pub const ECHO: crate::tcflag_t = 0x00000008;
335pub const ECHONL: crate::tcflag_t = 0x00000010;
336pub const ECHOPRT: crate::tcflag_t = 0x00000020;
337pub const ECHOCTL: crate::tcflag_t = 0x00000040;
338pub const ISIG: crate::tcflag_t = 0x00000080;
339pub const ICANON: crate::tcflag_t = 0x00000100;
340pub const ALTWERASE: crate::tcflag_t = 0x00000200;
341pub const IEXTEN: crate::tcflag_t = 0x00000400;
342pub const EXTPROC: crate::tcflag_t = 0x00000800;
343pub const TOSTOP: crate::tcflag_t = 0x00400000;
344pub const FLUSHO: crate::tcflag_t = 0x00800000;
345pub const NOKERNINFO: crate::tcflag_t = 0x02000000;
346pub const PENDIN: crate::tcflag_t = 0x20000000;
347pub const NOFLSH: crate::tcflag_t = 0x80000000;
348pub const MDMBUF: crate::tcflag_t = 0x00100000;
349
350pub const WNOHANG: c_int = 0x00000001;
351pub const WUNTRACED: c_int = 0x00000002;
352
353pub const RTLD_LAZY: c_int = 0x1;
354pub const RTLD_NOW: c_int = 0x2;
355pub const RTLD_NEXT: *mut c_void = -1isize as *mut c_void;
356pub const RTLD_DEFAULT: *mut c_void = -2isize as *mut c_void;
357pub const RTLD_SELF: *mut c_void = -3isize as *mut c_void;
358
359pub const LOG_CRON: c_int = 9 << 3;
360pub const LOG_AUTHPRIV: c_int = 10 << 3;
361pub const LOG_FTP: c_int = 11 << 3;
362pub const LOG_PERROR: c_int = 0x20;
363
364pub const TCP_NODELAY: c_int = 1;
365pub const TCP_MAXSEG: c_int = 2;
366
367pub const PIPE_BUF: usize = 512;
368
369// si_code values for SIGBUS signal
370pub const BUS_ADRALN: c_int = 1;
371pub const BUS_ADRERR: c_int = 2;
372pub const BUS_OBJERR: c_int = 3;
373
374// si_code values for SIGCHLD signal
375pub const CLD_EXITED: c_int = 1;
376pub const CLD_KILLED: c_int = 2;
377pub const CLD_DUMPED: c_int = 3;
378pub const CLD_TRAPPED: c_int = 4;
379pub const CLD_STOPPED: c_int = 5;
380pub const CLD_CONTINUED: c_int = 6;
381
382pub const POLLIN: c_short = 0x1;
383pub const POLLPRI: c_short = 0x2;
384pub const POLLOUT: c_short = 0x4;
385pub const POLLERR: c_short = 0x8;
386pub const POLLHUP: c_short = 0x10;
387pub const POLLNVAL: c_short = 0x20;
388pub const POLLRDNORM: c_short = 0x040;
389pub const POLLWRNORM: c_short = 0x004;
390pub const POLLRDBAND: c_short = 0x080;
391pub const POLLWRBAND: c_short = 0x100;
392
393cfg_if! {
394    // Not yet implemented on NetBSD
395    if #[cfg(not(any(target_os = "netbsd")))] {
396        pub const BIOCGBLEN: c_ulong = 0x40044266;
397        pub const BIOCSBLEN: c_ulong = 0xc0044266;
398        pub const BIOCFLUSH: c_uint = 0x20004268;
399        pub const BIOCPROMISC: c_uint = 0x20004269;
400        pub const BIOCGDLT: c_ulong = 0x4004426a;
401        pub const BIOCGETIF: c_ulong = 0x4020426b;
402        pub const BIOCSETIF: c_ulong = 0x8020426c;
403        pub const BIOCGSTATS: c_ulong = 0x4008426f;
404        pub const BIOCIMMEDIATE: c_ulong = 0x80044270;
405        pub const BIOCVERSION: c_ulong = 0x40044271;
406        pub const BIOCGHDRCMPLT: c_ulong = 0x40044274;
407        pub const BIOCSHDRCMPLT: c_ulong = 0x80044275;
408        pub const SIOCGIFADDR: c_ulong = 0xc0206921;
409    }
410}
411
412cfg_if! {
413    // Redefined in `new/apple`
414    if #[cfg(not(target_vendor = "apple"))] {
415        pub const TIOCCBRK: c_uint = 0x2000747a;
416        pub const TIOCSBRK: c_uint = 0x2000747b;
417    }
418}
419
420pub const PRIO_PROCESS: c_int = 0;
421pub const PRIO_PGRP: c_int = 1;
422pub const PRIO_USER: c_int = 2;
423
424pub const ITIMER_REAL: c_int = 0;
425pub const ITIMER_VIRTUAL: c_int = 1;
426pub const ITIMER_PROF: c_int = 2;
427
428// net/route.h
429
430pub const RTF_UP: c_int = 0x1;
431pub const RTF_GATEWAY: c_int = 0x2;
432pub const RTF_HOST: c_int = 0x4;
433pub const RTF_REJECT: c_int = 0x8;
434pub const RTF_DYNAMIC: c_int = 0x10;
435pub const RTF_MODIFIED: c_int = 0x20;
436pub const RTF_DONE: c_int = 0x40;
437pub const RTF_STATIC: c_int = 0x800;
438pub const RTF_BLACKHOLE: c_int = 0x1000;
439pub const RTF_PROTO2: c_int = 0x4000;
440pub const RTF_PROTO1: c_int = 0x8000;
441
442// Message types
443pub const RTM_ADD: c_int = 0x1;
444pub const RTM_DELETE: c_int = 0x2;
445pub const RTM_CHANGE: c_int = 0x3;
446pub const RTM_GET: c_int = 0x4;
447pub const RTM_LOSING: c_int = 0x5;
448pub const RTM_REDIRECT: c_int = 0x6;
449pub const RTM_MISS: c_int = 0x7;
450
451// Bitmask values for rtm_addrs.
452pub const RTA_DST: c_int = 0x1;
453pub const RTA_GATEWAY: c_int = 0x2;
454pub const RTA_NETMASK: c_int = 0x4;
455pub const RTA_GENMASK: c_int = 0x8;
456pub const RTA_IFP: c_int = 0x10;
457pub const RTA_IFA: c_int = 0x20;
458pub const RTA_AUTHOR: c_int = 0x40;
459pub const RTA_BRD: c_int = 0x80;
460
461// Index offsets for sockaddr array for alternate internal encoding.
462pub const RTAX_DST: c_int = 0;
463pub const RTAX_GATEWAY: c_int = 1;
464pub const RTAX_NETMASK: c_int = 2;
465pub const RTAX_GENMASK: c_int = 3;
466pub const RTAX_IFP: c_int = 4;
467pub const RTAX_IFA: c_int = 5;
468pub const RTAX_AUTHOR: c_int = 6;
469pub const RTAX_BRD: c_int = 7;
470
471f! {
472    pub unsafe fn CMSG_FIRSTHDR(mhdr: *const crate::msghdr) -> *mut cmsghdr {
473        if (*mhdr).msg_controllen as usize >= size_of::<cmsghdr>() {
474            (*mhdr).msg_control.cast()
475        } else {
476            ptr::null_mut()
477        }
478    }
479
480    pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () {
481        let bits = size_of_val(&(*set).fds_bits[0]) * 8;
482        let fd = fd as usize;
483        (*set).fds_bits[fd / bits] &= !(1 << (fd % bits));
484        return;
485    }
486
487    pub unsafe fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool {
488        let bits = size_of_val(&(*set).fds_bits[0]) * 8;
489        let fd = fd as usize;
490        return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0;
491    }
492
493    pub unsafe fn FD_SET(fd: c_int, set: *mut fd_set) -> () {
494        let bits = size_of_val(&(*set).fds_bits[0]) * 8;
495        let fd = fd as usize;
496        (*set).fds_bits[fd / bits] |= 1 << (fd % bits);
497        return;
498    }
499
500    pub unsafe fn FD_ZERO(set: *mut fd_set) -> () {
501        (*set).fds_bits.fill(0);
502    }
503}
504
505safe_f! {
506    pub const safe fn WTERMSIG(status: c_int) -> c_int {
507        status & 0o177
508    }
509
510    pub const safe fn WIFEXITED(status: c_int) -> bool {
511        (status & 0o177) == 0
512    }
513
514    pub const safe fn WEXITSTATUS(status: c_int) -> c_int {
515        (status >> 8) & 0x00ff
516    }
517
518    pub const safe fn WCOREDUMP(status: c_int) -> bool {
519        (status & 0o200) != 0
520    }
521
522    pub const safe fn QCMD(cmd: c_int, type_: c_int) -> c_int {
523        (cmd << 8) | (type_ & 0x00ff)
524    }
525}
526
527extern "C" {
528    #[cfg_attr(
529        all(target_os = "macos", target_arch = "x86"),
530        link_name = "getrlimit$UNIX2003"
531    )]
532    pub fn getrlimit(resource: c_int, rlim: *mut crate::rlimit) -> c_int;
533    #[cfg_attr(
534        all(target_os = "macos", target_arch = "x86"),
535        link_name = "setrlimit$UNIX2003"
536    )]
537    pub fn setrlimit(resource: c_int, rlim: *const crate::rlimit) -> c_int;
538
539    pub fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: size_t) -> c_int;
540    pub fn abs(i: c_int) -> c_int;
541    pub fn labs(i: c_long) -> c_long;
542    #[cfg_attr(
543        all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)),
544        link_name = "rand@FBSD_1.0"
545    )]
546    pub fn rand() -> c_int;
547    #[cfg_attr(
548        all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)),
549        link_name = "srand@FBSD_1.0"
550    )]
551    pub fn srand(seed: c_uint);
552
553    pub fn getifaddrs(ifap: *mut *mut crate::ifaddrs) -> c_int;
554    pub fn freeifaddrs(ifa: *mut crate::ifaddrs);
555    pub fn setgroups(ngroups: c_int, ptr: *const crate::gid_t) -> c_int;
556    pub fn setlogin(name: *const c_char) -> c_int;
557    pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int;
558    pub fn kqueue() -> c_int;
559    pub fn unmount(target: *const c_char, arg: c_int) -> c_int;
560    pub fn syscall(num: c_int, ...) -> c_int;
561    #[cfg_attr(target_os = "netbsd", link_name = "__getpwent50")]
562    pub fn getpwent() -> *mut passwd;
563    pub fn setpwent();
564    pub fn endpwent();
565    pub fn endgrent();
566    pub fn getgrent() -> *mut crate::group;
567
568    pub fn getprogname() -> *const c_char;
569    pub fn setprogname(name: *const c_char);
570    pub fn getloadavg(loadavg: *mut c_double, nelem: c_int) -> c_int;
571    pub fn if_nameindex() -> *mut if_nameindex;
572    pub fn if_freenameindex(ptr: *mut if_nameindex);
573
574    pub fn getpeereid(socket: c_int, euid: *mut crate::uid_t, egid: *mut crate::gid_t) -> c_int;
575
576    #[cfg_attr(
577        all(target_os = "macos", not(target_arch = "aarch64")),
578        link_name = "glob$INODE64"
579    )]
580    #[cfg_attr(target_os = "netbsd", link_name = "__glob30")]
581    #[cfg_attr(
582        all(target_os = "freebsd", any(freebsd11, freebsd10)),
583        link_name = "glob@FBSD_1.0"
584    )]
585    pub fn glob(
586        pattern: *const c_char,
587        flags: c_int,
588        errfunc: Option<extern "C" fn(epath: *const c_char, errno: c_int) -> c_int>,
589        pglob: *mut crate::glob_t,
590    ) -> c_int;
591    #[cfg_attr(target_os = "netbsd", link_name = "__globfree30")]
592    #[cfg_attr(
593        all(target_os = "freebsd", any(freebsd11, freebsd10)),
594        link_name = "globfree@FBSD_1.0"
595    )]
596    pub fn globfree(pglob: *mut crate::glob_t);
597
598    pub fn posix_madvise(addr: *mut c_void, len: size_t, advice: c_int) -> c_int;
599
600    pub fn shm_unlink(name: *const c_char) -> c_int;
601
602    #[cfg_attr(
603        all(target_os = "macos", target_arch = "x86_64"),
604        link_name = "seekdir$INODE64"
605    )]
606    #[cfg_attr(
607        all(target_os = "macos", target_arch = "x86"),
608        link_name = "seekdir$INODE64$UNIX2003"
609    )]
610    pub fn seekdir(dirp: *mut crate::DIR, loc: c_long);
611
612    #[cfg_attr(
613        all(target_os = "macos", target_arch = "x86_64"),
614        link_name = "telldir$INODE64"
615    )]
616    #[cfg_attr(
617        all(target_os = "macos", target_arch = "x86"),
618        link_name = "telldir$INODE64$UNIX2003"
619    )]
620    pub fn telldir(dirp: *mut crate::DIR) -> c_long;
621    pub fn madvise(addr: *mut c_void, len: size_t, advice: c_int) -> c_int;
622
623    #[cfg_attr(
624        all(target_os = "macos", target_arch = "x86"),
625        link_name = "msync$UNIX2003"
626    )]
627    #[cfg_attr(target_os = "netbsd", link_name = "__msync13")]
628    pub fn msync(addr: *mut c_void, len: size_t, flags: c_int) -> c_int;
629
630    #[cfg_attr(
631        all(target_os = "macos", target_arch = "x86"),
632        link_name = "recvfrom$UNIX2003"
633    )]
634    pub fn recvfrom(
635        socket: c_int,
636        buf: *mut c_void,
637        len: size_t,
638        flags: c_int,
639        addr: *mut crate::sockaddr,
640        addrlen: *mut crate::socklen_t,
641    ) -> ssize_t;
642    pub fn mkstemps(template: *mut c_char, suffixlen: c_int) -> c_int;
643    #[cfg_attr(target_os = "netbsd", link_name = "__futimes50")]
644    pub fn futimes(fd: c_int, times: *const crate::timeval) -> c_int;
645    pub fn nl_langinfo(item: crate::nl_item) -> *mut c_char;
646
647    #[cfg_attr(
648        all(target_os = "macos", target_arch = "x86"),
649        link_name = "bind$UNIX2003"
650    )]
651    pub fn bind(
652        socket: c_int,
653        address: *const crate::sockaddr,
654        address_len: crate::socklen_t,
655    ) -> c_int;
656
657    #[cfg_attr(
658        all(target_os = "macos", target_arch = "x86"),
659        link_name = "writev$UNIX2003"
660    )]
661    pub fn writev(fd: c_int, iov: *const crate::iovec, iovcnt: c_int) -> ssize_t;
662    #[cfg_attr(
663        all(target_os = "macos", target_arch = "x86"),
664        link_name = "readv$UNIX2003"
665    )]
666    pub fn readv(fd: c_int, iov: *const crate::iovec, iovcnt: c_int) -> ssize_t;
667
668    #[cfg_attr(
669        all(target_os = "macos", target_arch = "x86"),
670        link_name = "sendmsg$UNIX2003"
671    )]
672    pub fn sendmsg(fd: c_int, msg: *const crate::msghdr, flags: c_int) -> ssize_t;
673    #[cfg_attr(
674        all(target_os = "macos", target_arch = "x86"),
675        link_name = "recvmsg$UNIX2003"
676    )]
677    pub fn recvmsg(fd: c_int, msg: *mut crate::msghdr, flags: c_int) -> ssize_t;
678
679    pub fn sync();
680    pub fn getgrgid_r(
681        gid: crate::gid_t,
682        grp: *mut crate::group,
683        buf: *mut c_char,
684        buflen: size_t,
685        result: *mut *mut crate::group,
686    ) -> c_int;
687    #[cfg_attr(
688        all(target_os = "macos", target_arch = "x86"),
689        link_name = "sigaltstack$UNIX2003"
690    )]
691    #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")]
692    pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> c_int;
693    #[cfg_attr(target_os = "netbsd", link_name = "__sigsuspend14")]
694    pub fn sigsuspend(mask: *const crate::sigset_t) -> c_int;
695    pub fn sem_close(sem: *mut sem_t) -> c_int;
696    pub fn getdtablesize() -> c_int;
697    pub fn getgrnam_r(
698        name: *const c_char,
699        grp: *mut crate::group,
700        buf: *mut c_char,
701        buflen: size_t,
702        result: *mut *mut crate::group,
703    ) -> c_int;
704    #[cfg_attr(
705        all(target_os = "macos", target_arch = "x86"),
706        link_name = "pthread_sigmask$UNIX2003"
707    )]
708    pub fn pthread_sigmask(how: c_int, set: *const sigset_t, oldset: *mut sigset_t) -> c_int;
709    pub fn sem_open(name: *const c_char, oflag: c_int, ...) -> *mut sem_t;
710    pub fn getgrnam(name: *const c_char) -> *mut crate::group;
711    #[cfg_attr(
712        all(target_os = "macos", target_arch = "x86"),
713        link_name = "pthread_cancel$UNIX2003"
714    )]
715    pub fn pthread_cancel(thread: crate::pthread_t) -> c_int;
716    pub fn pthread_kill(thread: crate::pthread_t, sig: c_int) -> c_int;
717    pub fn sched_get_priority_min(policy: c_int) -> c_int;
718    pub fn sched_get_priority_max(policy: c_int) -> c_int;
719    pub fn sem_unlink(name: *const c_char) -> c_int;
720    #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam_r50")]
721    pub fn getpwnam_r(
722        name: *const c_char,
723        pwd: *mut passwd,
724        buf: *mut c_char,
725        buflen: size_t,
726        result: *mut *mut passwd,
727    ) -> c_int;
728    #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")]
729    pub fn getpwuid_r(
730        uid: crate::uid_t,
731        pwd: *mut passwd,
732        buf: *mut c_char,
733        buflen: size_t,
734        result: *mut *mut passwd,
735    ) -> c_int;
736    #[cfg_attr(
737        all(target_os = "macos", target_arch = "x86"),
738        link_name = "sigwait$UNIX2003"
739    )]
740    pub fn sigwait(set: *const sigset_t, sig: *mut c_int) -> c_int;
741    pub fn pthread_atfork(
742        prepare: Option<unsafe extern "C" fn()>,
743        parent: Option<unsafe extern "C" fn()>,
744        child: Option<unsafe extern "C" fn()>,
745    ) -> c_int;
746    pub fn getgrgid(gid: crate::gid_t) -> *mut crate::group;
747    #[cfg_attr(
748        all(target_os = "macos", target_arch = "x86"),
749        link_name = "popen$UNIX2003"
750    )]
751    pub fn popen(command: *const c_char, mode: *const c_char) -> *mut crate::FILE;
752    pub fn faccessat(dirfd: c_int, pathname: *const c_char, mode: c_int, flags: c_int) -> c_int;
753    pub fn pthread_create(
754        native: *mut crate::pthread_t,
755        attr: *const crate::pthread_attr_t,
756        f: extern "C" fn(*mut c_void) -> *mut c_void,
757        value: *mut c_void,
758    ) -> c_int;
759    pub fn acct(filename: *const c_char) -> c_int;
760    #[cfg_attr(
761        all(target_os = "macos", target_arch = "x86"),
762        link_name = "wait4$UNIX2003"
763    )]
764    #[cfg_attr(
765        all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)),
766        link_name = "wait4@FBSD_1.0"
767    )]
768    #[cfg_attr(target_os = "netbsd", link_name = "__wait450")]
769    pub fn wait4(
770        pid: crate::pid_t,
771        status: *mut c_int,
772        options: c_int,
773        rusage: *mut crate::rusage,
774    ) -> crate::pid_t;
775    #[cfg_attr(
776        all(target_os = "macos", target_arch = "x86"),
777        link_name = "getitimer$UNIX2003"
778    )]
779    #[cfg_attr(target_os = "netbsd", link_name = "__getitimer50")]
780    pub fn getitimer(which: c_int, curr_value: *mut crate::itimerval) -> c_int;
781    #[cfg_attr(
782        all(target_os = "macos", target_arch = "x86"),
783        link_name = "setitimer$UNIX2003"
784    )]
785    #[cfg_attr(target_os = "netbsd", link_name = "__setitimer50")]
786    pub fn setitimer(
787        which: c_int,
788        new_value: *const crate::itimerval,
789        old_value: *mut crate::itimerval,
790    ) -> c_int;
791
792    pub fn regcomp(preg: *mut regex_t, pattern: *const c_char, cflags: c_int) -> c_int;
793
794    pub fn regexec(
795        preg: *const regex_t,
796        input: *const c_char,
797        nmatch: size_t,
798        pmatch: *mut regmatch_t,
799        eflags: c_int,
800    ) -> c_int;
801
802    pub fn regerror(
803        errcode: c_int,
804        preg: *const regex_t,
805        errbuf: *mut c_char,
806        errbuf_size: size_t,
807    ) -> size_t;
808
809    pub fn regfree(preg: *mut regex_t);
810
811    pub fn arc4random() -> u32;
812    pub fn arc4random_buf(buf: *mut c_void, size: size_t);
813    pub fn arc4random_uniform(l: u32) -> u32;
814
815    pub fn drand48() -> c_double;
816    pub fn erand48(xseed: *mut c_ushort) -> c_double;
817    pub fn lrand48() -> c_long;
818    pub fn nrand48(xseed: *mut c_ushort) -> c_long;
819    pub fn mrand48() -> c_long;
820    pub fn jrand48(xseed: *mut c_ushort) -> c_long;
821    pub fn srand48(seed: c_long);
822    pub fn seed48(xseed: *mut c_ushort) -> *mut c_ushort;
823    pub fn lcong48(p: *mut c_ushort);
824    pub fn getopt_long(
825        argc: c_int,
826        argv: *const *mut c_char,
827        optstring: *const c_char,
828        longopts: *const option,
829        longindex: *mut c_int,
830    ) -> c_int;
831
832    pub fn strftime(
833        buf: *mut c_char,
834        maxsize: size_t,
835        format: *const c_char,
836        timeptr: *const crate::tm,
837    ) -> size_t;
838    pub fn strftime_l(
839        buf: *mut c_char,
840        maxsize: size_t,
841        format: *const c_char,
842        timeptr: *const crate::tm,
843        locale: crate::locale_t,
844    ) -> size_t;
845
846    #[cfg_attr(target_os = "netbsd", link_name = "__devname50")]
847    pub fn devname(dev: crate::dev_t, mode_t: crate::mode_t) -> *mut c_char;
848
849    pub fn issetugid() -> c_int;
850}
851
852cfg_if! {
853    if #[cfg(any(
854        target_os = "macos",
855        target_os = "ios",
856        target_os = "tvos",
857        target_os = "watchos",
858        target_os = "visionos"
859    ))] {
860        mod apple;
861        pub use self::apple::*;
862    } else if #[cfg(any(target_os = "openbsd", target_os = "netbsd"))] {
863        mod netbsdlike;
864        pub use self::netbsdlike::*;
865    } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] {
866        mod freebsdlike;
867        pub use self::freebsdlike::*;
868    } else {
869        // Unknown target_os
870    }
871}