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