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 SA_ONSTACK: ::c_int = 0x0001;
258 pub const SA_SIGINFO: ::c_int = 0x0040;
259 pub const SA_RESTART: ::c_int = 0x0002;
260 pub const SA_RESETHAND: ::c_int = 0x0004;
261 pub const SA_NOCLDSTOP: ::c_int = 0x0008;
262 pub const SA_NODEFER: ::c_int = 0x0010;
263 pub const SA_NOCLDWAIT: ::c_int = 0x0020;
264 
265 pub const SS_ONSTACK: ::c_int = 1;
266 pub const SS_DISABLE: ::c_int = 4;
267 
268 pub const SIGCHLD: ::c_int = 20;
269 pub const SIGBUS: ::c_int = 10;
270 pub const SIGUSR1: ::c_int = 30;
271 pub const SIGUSR2: ::c_int = 31;
272 pub const SIGCONT: ::c_int = 19;
273 pub const SIGSTOP: ::c_int = 17;
274 pub const SIGTSTP: ::c_int = 18;
275 pub const SIGURG: ::c_int = 16;
276 pub const SIGIO: ::c_int = 23;
277 pub const SIGSYS: ::c_int = 12;
278 pub const SIGTTIN: ::c_int = 21;
279 pub const SIGTTOU: ::c_int = 22;
280 pub const SIGXCPU: ::c_int = 24;
281 pub const SIGXFSZ: ::c_int = 25;
282 pub const SIGVTALRM: ::c_int = 26;
283 pub const SIGPROF: ::c_int = 27;
284 pub const SIGWINCH: ::c_int = 28;
285 pub const SIGINFO: ::c_int = 29;
286 
287 pub const SIG_SETMASK: ::c_int = 3;
288 pub const SIG_BLOCK: ::c_int = 0x1;
289 pub const SIG_UNBLOCK: ::c_int = 0x2;
290 
291 pub const IP_TOS: ::c_int = 3;
292 pub const IP_MULTICAST_IF: ::c_int = 9;
293 pub const IP_MULTICAST_TTL: ::c_int = 10;
294 pub const IP_MULTICAST_LOOP: ::c_int = 11;
295 
296 pub const IPV6_UNICAST_HOPS: ::c_int = 4;
297 pub const IPV6_MULTICAST_IF: ::c_int = 9;
298 pub const IPV6_MULTICAST_HOPS: ::c_int = 10;
299 pub const IPV6_MULTICAST_LOOP: ::c_int = 11;
300 pub const IPV6_V6ONLY: ::c_int = 27;
301 
302 pub const IPTOS_ECN_NOTECT: u8 = 0x00;
303 pub const IPTOS_ECN_MASK: u8 = 0x03;
304 pub const IPTOS_ECN_ECT1: u8 = 0x01;
305 pub const IPTOS_ECN_ECT0: u8 = 0x02;
306 pub const IPTOS_ECN_CE: u8 = 0x03;
307 
308 pub const ST_RDONLY: ::c_ulong = 1;
309 
310 pub const SCM_RIGHTS: ::c_int = 0x01;
311 
312 pub const NCCS: usize = 20;
313 
314 pub const O_ACCMODE: ::c_int = 0x3;
315 pub const O_RDONLY: ::c_int = 0;
316 pub const O_WRONLY: ::c_int = 1;
317 pub const O_RDWR: ::c_int = 2;
318 pub const O_APPEND: ::c_int = 8;
319 pub const O_CREAT: ::c_int = 512;
320 pub const O_TRUNC: ::c_int = 1024;
321 pub const O_EXCL: ::c_int = 2048;
322 pub const O_ASYNC: ::c_int = 0x40;
323 pub const O_SYNC: ::c_int = 0x80;
324 pub const O_NONBLOCK: ::c_int = 0x4;
325 pub const O_NOFOLLOW: ::c_int = 0x100;
326 pub const O_SHLOCK: ::c_int = 0x10;
327 pub const O_EXLOCK: ::c_int = 0x20;
328 pub const O_FSYNC: ::c_int = O_SYNC;
329 pub const O_NDELAY: ::c_int = O_NONBLOCK;
330 
331 pub const F_GETOWN: ::c_int = 5;
332 pub const F_SETOWN: ::c_int = 6;
333 
334 pub const F_RDLCK: ::c_short = 1;
335 pub const F_UNLCK: ::c_short = 2;
336 pub const F_WRLCK: ::c_short = 3;
337 
338 pub const MNT_FORCE: ::c_int = 0x80000;
339 
340 pub const Q_SYNC: ::c_int = 0x600;
341 pub const Q_QUOTAON: ::c_int = 0x100;
342 pub const Q_QUOTAOFF: ::c_int = 0x200;
343 
344 pub const TCIOFF: ::c_int = 3;
345 pub const TCION: ::c_int = 4;
346 pub const TCOOFF: ::c_int = 1;
347 pub const TCOON: ::c_int = 2;
348 pub const TCIFLUSH: ::c_int = 1;
349 pub const TCOFLUSH: ::c_int = 2;
350 pub const TCIOFLUSH: ::c_int = 3;
351 pub const TCSANOW: ::c_int = 0;
352 pub const TCSADRAIN: ::c_int = 1;
353 pub const TCSAFLUSH: ::c_int = 2;
354 pub const VEOF: usize = 0;
355 pub const VEOL: usize = 1;
356 pub const VEOL2: usize = 2;
357 pub const VERASE: usize = 3;
358 pub const VWERASE: usize = 4;
359 pub const VKILL: usize = 5;
360 pub const VREPRINT: usize = 6;
361 pub const VINTR: usize = 8;
362 pub const VQUIT: usize = 9;
363 pub const VSUSP: usize = 10;
364 pub const VDSUSP: usize = 11;
365 pub const VSTART: usize = 12;
366 pub const VSTOP: usize = 13;
367 pub const VLNEXT: usize = 14;
368 pub const VDISCARD: usize = 15;
369 pub const VMIN: usize = 16;
370 pub const VTIME: usize = 17;
371 pub const VSTATUS: usize = 18;
372 pub const _POSIX_VDISABLE: ::cc_t = 0xff;
373 pub const IGNBRK: ::tcflag_t = 0x00000001;
374 pub const BRKINT: ::tcflag_t = 0x00000002;
375 pub const IGNPAR: ::tcflag_t = 0x00000004;
376 pub const PARMRK: ::tcflag_t = 0x00000008;
377 pub const INPCK: ::tcflag_t = 0x00000010;
378 pub const ISTRIP: ::tcflag_t = 0x00000020;
379 pub const INLCR: ::tcflag_t = 0x00000040;
380 pub const IGNCR: ::tcflag_t = 0x00000080;
381 pub const ICRNL: ::tcflag_t = 0x00000100;
382 pub const IXON: ::tcflag_t = 0x00000200;
383 pub const IXOFF: ::tcflag_t = 0x00000400;
384 pub const IXANY: ::tcflag_t = 0x00000800;
385 pub const IMAXBEL: ::tcflag_t = 0x00002000;
386 pub const OPOST: ::tcflag_t = 0x1;
387 pub const ONLCR: ::tcflag_t = 0x2;
388 pub const OXTABS: ::tcflag_t = 0x4;
389 pub const ONOEOT: ::tcflag_t = 0x8;
390 pub const CIGNORE: ::tcflag_t = 0x00000001;
391 pub const CSIZE: ::tcflag_t = 0x00000300;
392 pub const CS5: ::tcflag_t = 0x00000000;
393 pub const CS6: ::tcflag_t = 0x00000100;
394 pub const CS7: ::tcflag_t = 0x00000200;
395 pub const CS8: ::tcflag_t = 0x00000300;
396 pub const CSTOPB: ::tcflag_t = 0x00000400;
397 pub const CREAD: ::tcflag_t = 0x00000800;
398 pub const PARENB: ::tcflag_t = 0x00001000;
399 pub const PARODD: ::tcflag_t = 0x00002000;
400 pub const HUPCL: ::tcflag_t = 0x00004000;
401 pub const CLOCAL: ::tcflag_t = 0x00008000;
402 pub const ECHOKE: ::tcflag_t = 0x00000001;
403 pub const ECHOE: ::tcflag_t = 0x00000002;
404 pub const ECHOK: ::tcflag_t = 0x00000004;
405 pub const ECHO: ::tcflag_t = 0x00000008;
406 pub const ECHONL: ::tcflag_t = 0x00000010;
407 pub const ECHOPRT: ::tcflag_t = 0x00000020;
408 pub const ECHOCTL: ::tcflag_t = 0x00000040;
409 pub const ISIG: ::tcflag_t = 0x00000080;
410 pub const ICANON: ::tcflag_t = 0x00000100;
411 pub const ALTWERASE: ::tcflag_t = 0x00000200;
412 pub const IEXTEN: ::tcflag_t = 0x00000400;
413 pub const EXTPROC: ::tcflag_t = 0x00000800;
414 pub const TOSTOP: ::tcflag_t = 0x00400000;
415 pub const FLUSHO: ::tcflag_t = 0x00800000;
416 pub const NOKERNINFO: ::tcflag_t = 0x02000000;
417 pub const PENDIN: ::tcflag_t = 0x20000000;
418 pub const NOFLSH: ::tcflag_t = 0x80000000;
419 pub const MDMBUF: ::tcflag_t = 0x00100000;
420 
421 pub const WNOHANG: ::c_int = 0x00000001;
422 pub const WUNTRACED: ::c_int = 0x00000002;
423 
424 pub const RTLD_LAZY: ::c_int = 0x1;
425 pub const RTLD_NOW: ::c_int = 0x2;
426 pub const RTLD_NEXT: *mut ::c_void = -1isize as *mut ::c_void;
427 pub const RTLD_DEFAULT: *mut ::c_void = -2isize as *mut ::c_void;
428 pub const RTLD_SELF: *mut ::c_void = -3isize as *mut ::c_void;
429 
430 pub const LOG_CRON: ::c_int = 9 << 3;
431 pub const LOG_AUTHPRIV: ::c_int = 10 << 3;
432 pub const LOG_FTP: ::c_int = 11 << 3;
433 pub const LOG_PERROR: ::c_int = 0x20;
434 
435 pub const TCP_NODELAY: ::c_int = 1;
436 pub const TCP_MAXSEG: ::c_int = 2;
437 
438 pub const PIPE_BUF: usize = 512;
439 
440 pub const POLLIN: ::c_short = 0x1;
441 pub const POLLPRI: ::c_short = 0x2;
442 pub const POLLOUT: ::c_short = 0x4;
443 pub const POLLERR: ::c_short = 0x8;
444 pub const POLLHUP: ::c_short = 0x10;
445 pub const POLLNVAL: ::c_short = 0x20;
446 pub const POLLRDNORM: ::c_short = 0x040;
447 pub const POLLWRNORM: ::c_short = 0x004;
448 pub const POLLRDBAND: ::c_short = 0x080;
449 pub const POLLWRBAND: ::c_short = 0x100;
450 
451 pub const BIOCGBLEN: ::c_ulong = 0x40044266;
452 pub const BIOCSBLEN: ::c_ulong = 0xc0044266;
453 pub const BIOCFLUSH: ::c_uint = 0x20004268;
454 pub const BIOCPROMISC: ::c_uint = 0x20004269;
455 pub const BIOCGDLT: ::c_ulong = 0x4004426a;
456 pub const BIOCGETIF: ::c_ulong = 0x4020426b;
457 pub const BIOCSETIF: ::c_ulong = 0x8020426c;
458 pub const BIOCGSTATS: ::c_ulong = 0x4008426f;
459 pub const BIOCIMMEDIATE: ::c_ulong = 0x80044270;
460 pub const BIOCVERSION: ::c_ulong = 0x40044271;
461 pub const BIOCGHDRCMPLT: ::c_ulong = 0x40044274;
462 pub const BIOCSHDRCMPLT: ::c_ulong = 0x80044275;
463 pub const SIOCGIFADDR: ::c_ulong = 0xc0206921;
464 
465 pub const REG_BASIC: ::c_int = 0o0000;
466 pub const REG_EXTENDED: ::c_int = 0o0001;
467 pub const REG_ICASE: ::c_int = 0o0002;
468 pub const REG_NOSUB: ::c_int = 0o0004;
469 pub const REG_NEWLINE: ::c_int = 0o0010;
470 pub const REG_NOSPEC: ::c_int = 0o0020;
471 pub const REG_PEND: ::c_int = 0o0040;
472 pub const REG_DUMP: ::c_int = 0o0200;
473 
474 pub const REG_NOMATCH: ::c_int = 1;
475 pub const REG_BADPAT: ::c_int = 2;
476 pub const REG_ECOLLATE: ::c_int = 3;
477 pub const REG_ECTYPE: ::c_int = 4;
478 pub const REG_EESCAPE: ::c_int = 5;
479 pub const REG_ESUBREG: ::c_int = 6;
480 pub const REG_EBRACK: ::c_int = 7;
481 pub const REG_EPAREN: ::c_int = 8;
482 pub const REG_EBRACE: ::c_int = 9;
483 pub const REG_BADBR: ::c_int = 10;
484 pub const REG_ERANGE: ::c_int = 11;
485 pub const REG_ESPACE: ::c_int = 12;
486 pub const REG_BADRPT: ::c_int = 13;
487 pub const REG_EMPTY: ::c_int = 14;
488 pub const REG_ASSERT: ::c_int = 15;
489 pub const REG_INVARG: ::c_int = 16;
490 pub const REG_ATOI: ::c_int = 255;
491 pub const REG_ITOA: ::c_int = 0o0400;
492 
493 pub const REG_NOTBOL: ::c_int = 0o00001;
494 pub const REG_NOTEOL: ::c_int = 0o00002;
495 pub const REG_STARTEND: ::c_int = 0o00004;
496 pub const REG_TRACE: ::c_int = 0o00400;
497 pub const REG_LARGE: ::c_int = 0o01000;
498 pub const REG_BACKR: ::c_int = 0o02000;
499 
500 pub const TIOCCBRK: ::c_uint = 0x2000747a;
501 pub const TIOCSBRK: ::c_uint = 0x2000747b;
502 
503 pub const PRIO_PROCESS: ::c_int = 0;
504 pub const PRIO_PGRP: ::c_int = 1;
505 pub const PRIO_USER: ::c_int = 2;
506 
507 f! {
508     pub fn CMSG_FIRSTHDR(mhdr: *const ::msghdr) -> *mut ::cmsghdr {
509         if (*mhdr).msg_controllen as usize >= ::mem::size_of::<::cmsghdr>() {
510             (*mhdr).msg_control as *mut ::cmsghdr
511         } else {
512             0 as *mut ::cmsghdr
513         }
514     }
515 
516     pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
517         let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8;
518         let fd = fd as usize;
519         (*set).fds_bits[fd / bits] &= !(1 << (fd % bits));
520         return
521     }
522 
523     pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool {
524         let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8;
525         let fd = fd as usize;
526         return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0
527     }
528 
529     pub fn FD_SET(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_ZERO(set: *mut fd_set) -> () {
537         for slot in (*set).fds_bits.iter_mut() {
538             *slot = 0;
539         }
540     }
541 
542     pub fn WTERMSIG(status: ::c_int) -> ::c_int {
543         status & 0o177
544     }
545 
546     pub fn WIFEXITED(status: ::c_int) -> bool {
547         (status & 0o177) == 0
548     }
549 
550     pub fn WEXITSTATUS(status: ::c_int) -> ::c_int {
551         status >> 8
552     }
553 
554     pub fn WCOREDUMP(status: ::c_int) -> bool {
555         (status & 0o200) != 0
556     }
557 
558     pub fn QCMD(cmd: ::c_int, type_: ::c_int) -> ::c_int {
559         (cmd << 8) | (type_ & 0x00ff)
560     }
561 }
562 
563 extern "C" {
564     #[cfg_attr(
565         all(target_os = "macos", target_arch = "x86"),
566         link_name = "getrlimit$UNIX2003"
567     )]
getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int568     pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int;
569     #[cfg_attr(
570         all(target_os = "macos", target_arch = "x86"),
571         link_name = "setrlimit$UNIX2003"
572     )]
setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int573     pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int;
574 
strerror_r( errnum: ::c_int, buf: *mut c_char, buflen: ::size_t, ) -> ::c_int575     pub fn strerror_r(
576         errnum: ::c_int,
577         buf: *mut c_char,
578         buflen: ::size_t,
579     ) -> ::c_int;
abs(i: ::c_int) -> ::c_int580     pub fn abs(i: ::c_int) -> ::c_int;
atof(s: *const ::c_char) -> ::c_double581     pub fn atof(s: *const ::c_char) -> ::c_double;
labs(i: ::c_long) -> ::c_long582     pub fn labs(i: ::c_long) -> ::c_long;
583     #[cfg_attr(
584         all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)),
585         link_name = "rand@FBSD_1.0"
586     )]
rand() -> ::c_int587     pub fn rand() -> ::c_int;
588     #[cfg_attr(
589         all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)),
590         link_name = "srand@FBSD_1.0"
591     )]
srand(seed: ::c_uint)592     pub fn srand(seed: ::c_uint);
593 
getifaddrs(ifap: *mut *mut ::ifaddrs) -> ::c_int594     pub fn getifaddrs(ifap: *mut *mut ::ifaddrs) -> ::c_int;
freeifaddrs(ifa: *mut ::ifaddrs)595     pub fn freeifaddrs(ifa: *mut ::ifaddrs);
setgroups(ngroups: ::c_int, ptr: *const ::gid_t) -> ::c_int596     pub fn setgroups(ngroups: ::c_int, ptr: *const ::gid_t) -> ::c_int;
ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int597     pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int;
kqueue() -> ::c_int598     pub fn kqueue() -> ::c_int;
unmount(target: *const ::c_char, arg: ::c_int) -> ::c_int599     pub fn unmount(target: *const ::c_char, arg: ::c_int) -> ::c_int;
syscall(num: ::c_int, ...) -> ::c_int600     pub fn syscall(num: ::c_int, ...) -> ::c_int;
601     #[cfg_attr(target_os = "netbsd", link_name = "__getpwent50")]
getpwent() -> *mut passwd602     pub fn getpwent() -> *mut passwd;
setpwent()603     pub fn setpwent();
endpwent()604     pub fn endpwent();
endgrent()605     pub fn endgrent();
getgrent() -> *mut ::group606     pub fn getgrent() -> *mut ::group;
607 
getprogname() -> *const ::c_char608     pub fn getprogname() -> *const ::c_char;
setprogname(name: *const ::c_char)609     pub fn setprogname(name: *const ::c_char);
getloadavg(loadavg: *mut ::c_double, nelem: ::c_int) -> ::c_int610     pub fn getloadavg(loadavg: *mut ::c_double, nelem: ::c_int) -> ::c_int;
if_nameindex() -> *mut if_nameindex611     pub fn if_nameindex() -> *mut if_nameindex;
if_freenameindex(ptr: *mut if_nameindex)612     pub fn if_freenameindex(ptr: *mut if_nameindex);
613 
getpeereid( socket: ::c_int, euid: *mut ::uid_t, egid: *mut ::gid_t, ) -> ::c_int614     pub fn getpeereid(
615         socket: ::c_int,
616         euid: *mut ::uid_t,
617         egid: *mut ::gid_t,
618     ) -> ::c_int;
619 
620     #[cfg_attr(target_os = "macos", link_name = "glob$INODE64")]
621     #[cfg_attr(target_os = "netbsd", link_name = "__glob30")]
622     #[cfg_attr(
623         all(target_os = "freebsd", any(freebsd11, freebsd10)),
624         link_name = "glob@FBSD_1.0"
625     )]
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_int626     pub fn glob(
627         pattern: *const ::c_char,
628         flags: ::c_int,
629         errfunc: ::Option<
630             extern "C" fn(epath: *const ::c_char, errno: ::c_int) -> ::c_int,
631         >,
632         pglob: *mut ::glob_t,
633     ) -> ::c_int;
634     #[cfg_attr(target_os = "netbsd", link_name = "__globfree30")]
635     #[cfg_attr(
636         all(target_os = "freebsd", any(freebsd11, freebsd10)),
637         link_name = "globfree@FBSD_1.0"
638     )]
globfree(pglob: *mut ::glob_t)639     pub fn globfree(pglob: *mut ::glob_t);
640 
posix_madvise( addr: *mut ::c_void, len: ::size_t, advice: ::c_int, ) -> ::c_int641     pub fn posix_madvise(
642         addr: *mut ::c_void,
643         len: ::size_t,
644         advice: ::c_int,
645     ) -> ::c_int;
646 
shm_unlink(name: *const ::c_char) -> ::c_int647     pub fn shm_unlink(name: *const ::c_char) -> ::c_int;
648 
649     #[cfg_attr(
650         all(target_os = "macos", target_arch = "x86_64"),
651         link_name = "seekdir$INODE64"
652     )]
653     #[cfg_attr(
654         all(target_os = "macos", target_arch = "x86"),
655         link_name = "seekdir$INODE64$UNIX2003"
656     )]
seekdir(dirp: *mut ::DIR, loc: ::c_long)657     pub fn seekdir(dirp: *mut ::DIR, loc: ::c_long);
658 
659     #[cfg_attr(
660         all(target_os = "macos", target_arch = "x86_64"),
661         link_name = "telldir$INODE64"
662     )]
663     #[cfg_attr(
664         all(target_os = "macos", target_arch = "x86"),
665         link_name = "telldir$INODE64$UNIX2003"
666     )]
telldir(dirp: *mut ::DIR) -> ::c_long667     pub fn telldir(dirp: *mut ::DIR) -> ::c_long;
madvise( addr: *mut ::c_void, len: ::size_t, advice: ::c_int, ) -> ::c_int668     pub fn madvise(
669         addr: *mut ::c_void,
670         len: ::size_t,
671         advice: ::c_int,
672     ) -> ::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(
680         addr: *mut ::c_void,
681         len: ::size_t,
682         flags: ::c_int,
683     ) -> ::c_int;
684 
685     #[cfg_attr(
686         all(target_os = "macos", target_arch = "x86"),
687         link_name = "recvfrom$UNIX2003"
688     )]
recvfrom( socket: ::c_int, buf: *mut ::c_void, len: ::size_t, flags: ::c_int, addr: *mut ::sockaddr, addrlen: *mut ::socklen_t, ) -> ::ssize_t689     pub fn recvfrom(
690         socket: ::c_int,
691         buf: *mut ::c_void,
692         len: ::size_t,
693         flags: ::c_int,
694         addr: *mut ::sockaddr,
695         addrlen: *mut ::socklen_t,
696     ) -> ::ssize_t;
mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int697     pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int;
698     #[cfg_attr(target_os = "netbsd", link_name = "__futimes50")]
futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int699     pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int;
nl_langinfo(item: ::nl_item) -> *mut ::c_char700     pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char;
701 
702     #[cfg_attr(
703         all(target_os = "macos", target_arch = "x86"),
704         link_name = "bind$UNIX2003"
705     )]
bind( socket: ::c_int, address: *const ::sockaddr, address_len: ::socklen_t, ) -> ::c_int706     pub fn bind(
707         socket: ::c_int,
708         address: *const ::sockaddr,
709         address_len: ::socklen_t,
710     ) -> ::c_int;
711 
712     #[cfg_attr(
713         all(target_os = "macos", target_arch = "x86"),
714         link_name = "writev$UNIX2003"
715     )]
writev( fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int, ) -> ::ssize_t716     pub fn writev(
717         fd: ::c_int,
718         iov: *const ::iovec,
719         iovcnt: ::c_int,
720     ) -> ::ssize_t;
721     #[cfg_attr(
722         all(target_os = "macos", target_arch = "x86"),
723         link_name = "readv$UNIX2003"
724     )]
readv( fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int, ) -> ::ssize_t725     pub fn readv(
726         fd: ::c_int,
727         iov: *const ::iovec,
728         iovcnt: ::c_int,
729     ) -> ::ssize_t;
730 
731     #[cfg_attr(
732         all(target_os = "macos", target_arch = "x86"),
733         link_name = "sendmsg$UNIX2003"
734     )]
sendmsg( fd: ::c_int, msg: *const ::msghdr, flags: ::c_int, ) -> ::ssize_t735     pub fn sendmsg(
736         fd: ::c_int,
737         msg: *const ::msghdr,
738         flags: ::c_int,
739     ) -> ::ssize_t;
740     #[cfg_attr(
741         all(target_os = "macos", target_arch = "x86"),
742         link_name = "recvmsg$UNIX2003"
743     )]
recvmsg( fd: ::c_int, msg: *mut ::msghdr, flags: ::c_int, ) -> ::ssize_t744     pub fn recvmsg(
745         fd: ::c_int,
746         msg: *mut ::msghdr,
747         flags: ::c_int,
748     ) -> ::ssize_t;
749 
sync()750     pub fn sync();
getgrgid_r( gid: ::gid_t, grp: *mut ::group, buf: *mut ::c_char, buflen: ::size_t, result: *mut *mut ::group, ) -> ::c_int751     pub fn getgrgid_r(
752         gid: ::gid_t,
753         grp: *mut ::group,
754         buf: *mut ::c_char,
755         buflen: ::size_t,
756         result: *mut *mut ::group,
757     ) -> ::c_int;
758     #[cfg_attr(
759         all(target_os = "macos", target_arch = "x86"),
760         link_name = "sigaltstack$UNIX2003"
761     )]
762     #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")]
sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int763     pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int;
sem_close(sem: *mut sem_t) -> ::c_int764     pub fn sem_close(sem: *mut sem_t) -> ::c_int;
getdtablesize() -> ::c_int765     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_int766     pub fn getgrnam_r(
767         name: *const ::c_char,
768         grp: *mut ::group,
769         buf: *mut ::c_char,
770         buflen: ::size_t,
771         result: *mut *mut ::group,
772     ) -> ::c_int;
773     #[cfg_attr(
774         all(target_os = "macos", target_arch = "x86"),
775         link_name = "pthread_sigmask$UNIX2003"
776     )]
pthread_sigmask( how: ::c_int, set: *const sigset_t, oldset: *mut sigset_t, ) -> ::c_int777     pub fn pthread_sigmask(
778         how: ::c_int,
779         set: *const sigset_t,
780         oldset: *mut sigset_t,
781     ) -> ::c_int;
sem_open(name: *const ::c_char, oflag: ::c_int, ...) -> *mut sem_t782     pub fn sem_open(name: *const ::c_char, oflag: ::c_int, ...) -> *mut sem_t;
getgrnam(name: *const ::c_char) -> *mut ::group783     pub fn getgrnam(name: *const ::c_char) -> *mut ::group;
784     #[cfg_attr(
785         all(target_os = "macos", target_arch = "x86"),
786         link_name = "pthread_cancel$UNIX2003"
787     )]
pthread_cancel(thread: ::pthread_t) -> ::c_int788     pub fn pthread_cancel(thread: ::pthread_t) -> ::c_int;
pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int789     pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int;
sem_unlink(name: *const ::c_char) -> ::c_int790     pub fn sem_unlink(name: *const ::c_char) -> ::c_int;
791     #[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_int792     pub fn getpwnam_r(
793         name: *const ::c_char,
794         pwd: *mut passwd,
795         buf: *mut ::c_char,
796         buflen: ::size_t,
797         result: *mut *mut passwd,
798     ) -> ::c_int;
799     #[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_int800     pub fn getpwuid_r(
801         uid: ::uid_t,
802         pwd: *mut passwd,
803         buf: *mut ::c_char,
804         buflen: ::size_t,
805         result: *mut *mut passwd,
806     ) -> ::c_int;
807     #[cfg_attr(
808         all(target_os = "macos", target_arch = "x86"),
809         link_name = "sigwait$UNIX2003"
810     )]
sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int811     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_int812     pub fn pthread_atfork(
813         prepare: ::Option<unsafe extern "C" fn()>,
814         parent: ::Option<unsafe extern "C" fn()>,
815         child: ::Option<unsafe extern "C" fn()>,
816     ) -> ::c_int;
getgrgid(gid: ::gid_t) -> *mut ::group817     pub fn getgrgid(gid: ::gid_t) -> *mut ::group;
818     #[cfg_attr(
819         all(target_os = "macos", target_arch = "x86"),
820         link_name = "popen$UNIX2003"
821     )]
popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE822     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_int823     pub fn faccessat(
824         dirfd: ::c_int,
825         pathname: *const ::c_char,
826         mode: ::c_int,
827         flags: ::c_int,
828     ) -> ::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_int829     pub fn pthread_create(
830         native: *mut ::pthread_t,
831         attr: *const ::pthread_attr_t,
832         f: extern "C" fn(*mut ::c_void) -> *mut ::c_void,
833         value: *mut ::c_void,
834     ) -> ::c_int;
acct(filename: *const ::c_char) -> ::c_int835     pub fn acct(filename: *const ::c_char) -> ::c_int;
836     #[cfg_attr(
837         all(target_os = "macos", target_arch = "x86"),
838         link_name = "wait4$UNIX2003"
839     )]
840     #[cfg_attr(
841         all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)),
842         link_name = "wait4@FBSD_1.0"
843     )]
wait4( pid: ::pid_t, status: *mut ::c_int, options: ::c_int, rusage: *mut ::rusage, ) -> ::pid_t844     pub fn wait4(
845         pid: ::pid_t,
846         status: *mut ::c_int,
847         options: ::c_int,
848         rusage: *mut ::rusage,
849     ) -> ::pid_t;
850 
regcomp( preg: *mut regex_t, pattern: *const ::c_char, cflags: ::c_int, ) -> ::c_int851     pub fn regcomp(
852         preg: *mut regex_t,
853         pattern: *const ::c_char,
854         cflags: ::c_int,
855     ) -> ::c_int;
856 
regexec( preg: *const regex_t, input: *const ::c_char, nmatch: ::size_t, pmatch: *mut regmatch_t, eflags: ::c_int, ) -> ::c_int857     pub fn regexec(
858         preg: *const regex_t,
859         input: *const ::c_char,
860         nmatch: ::size_t,
861         pmatch: *mut regmatch_t,
862         eflags: ::c_int,
863     ) -> ::c_int;
864 
regerror( errcode: ::c_int, preg: *const regex_t, errbuf: *mut ::c_char, errbuf_size: ::size_t, ) -> ::size_t865     pub fn regerror(
866         errcode: ::c_int,
867         preg: *const regex_t,
868         errbuf: *mut ::c_char,
869         errbuf_size: ::size_t,
870     ) -> ::size_t;
871 
regfree(preg: *mut regex_t)872     pub fn regfree(preg: *mut regex_t);
873 }
874 
875 cfg_if! {
876     if #[cfg(any(target_os = "macos", target_os = "ios"))] {
877         mod apple;
878         pub use self::apple::*;
879     } else if #[cfg(any(target_os = "openbsd", target_os = "netbsd"))] {
880         mod netbsdlike;
881         pub use self::netbsdlike::*;
882     } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] {
883         mod freebsdlike;
884         pub use self::freebsdlike::*;
885     } else {
886         // Unknown target_os
887     }
888 }
889