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