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