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