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