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