1 use crate::prelude::*;
2 
3 pub type sa_family_t = u16;
4 pub type speed_t = c_uint;
5 pub type tcflag_t = c_uint;
6 pub type clockid_t = c_int;
7 pub type timer_t = *mut c_void;
8 pub type key_t = c_int;
9 pub type id_t = c_uint;
10 
11 missing! {
12     #[cfg_attr(feature = "extra_traits", derive(Debug))]
13     pub enum timezone {}
14 }
15 
16 s! {
17     pub struct in_addr {
18         pub s_addr: crate::in_addr_t,
19     }
20 
21     pub struct ip_mreq {
22         pub imr_multiaddr: in_addr,
23         pub imr_interface: in_addr,
24     }
25 
26     pub struct ip_mreqn {
27         pub imr_multiaddr: in_addr,
28         pub imr_address: in_addr,
29         pub imr_ifindex: c_int,
30     }
31 
32     pub struct ip_mreq_source {
33         pub imr_multiaddr: in_addr,
34         pub imr_interface: in_addr,
35         pub imr_sourceaddr: in_addr,
36     }
37 
38     pub struct sockaddr {
39         pub sa_family: sa_family_t,
40         pub sa_data: [c_char; 14],
41     }
42 
43     pub struct sockaddr_in {
44         pub sin_family: sa_family_t,
45         pub sin_port: crate::in_port_t,
46         pub sin_addr: crate::in_addr,
47         pub sin_zero: [u8; 8],
48     }
49 
50     pub struct sockaddr_in6 {
51         pub sin6_family: sa_family_t,
52         pub sin6_port: crate::in_port_t,
53         pub sin6_flowinfo: u32,
54         pub sin6_addr: crate::in6_addr,
55         pub sin6_scope_id: u32,
56     }
57 
58     // The order of the `ai_addr` field in this struct is crucial
59     // for converting between the Rust and C types.
60     pub struct addrinfo {
61         pub ai_flags: c_int,
62         pub ai_family: c_int,
63         pub ai_socktype: c_int,
64         pub ai_protocol: c_int,
65         pub ai_addrlen: socklen_t,
66 
67         #[cfg(any(target_os = "linux", target_os = "emscripten"))]
68         pub ai_addr: *mut crate::sockaddr,
69 
70         pub ai_canonname: *mut c_char,
71 
72         #[cfg(target_os = "android")]
73         pub ai_addr: *mut crate::sockaddr,
74 
75         pub ai_next: *mut addrinfo,
76     }
77 
78     pub struct sockaddr_ll {
79         pub sll_family: c_ushort,
80         pub sll_protocol: c_ushort,
81         pub sll_ifindex: c_int,
82         pub sll_hatype: c_ushort,
83         pub sll_pkttype: c_uchar,
84         pub sll_halen: c_uchar,
85         pub sll_addr: [c_uchar; 8],
86     }
87 
88     pub struct fd_set {
89         fds_bits: [c_ulong; FD_SETSIZE as usize / ULONG_SIZE],
90     }
91 
92     pub struct tm {
93         pub tm_sec: c_int,
94         pub tm_min: c_int,
95         pub tm_hour: c_int,
96         pub tm_mday: c_int,
97         pub tm_mon: c_int,
98         pub tm_year: c_int,
99         pub tm_wday: c_int,
100         pub tm_yday: c_int,
101         pub tm_isdst: c_int,
102         pub tm_gmtoff: c_long,
103         pub tm_zone: *const c_char,
104     }
105 
106     pub struct sched_param {
107         pub sched_priority: c_int,
108         #[cfg(any(target_env = "musl", target_os = "emscripten", target_env = "ohos"))]
109         pub sched_ss_low_priority: c_int,
110         #[cfg(any(target_env = "musl", target_os = "emscripten", target_env = "ohos"))]
111         pub sched_ss_repl_period: crate::timespec,
112         #[cfg(any(target_env = "musl", target_os = "emscripten", target_env = "ohos"))]
113         pub sched_ss_init_budget: crate::timespec,
114         #[cfg(any(target_env = "musl", target_os = "emscripten", target_env = "ohos"))]
115         pub sched_ss_max_repl: c_int,
116     }
117 
118     pub struct Dl_info {
119         pub dli_fname: *const c_char,
120         pub dli_fbase: *mut c_void,
121         pub dli_sname: *const c_char,
122         pub dli_saddr: *mut c_void,
123     }
124 
125     pub struct lconv {
126         pub decimal_point: *mut c_char,
127         pub thousands_sep: *mut c_char,
128         pub grouping: *mut c_char,
129         pub int_curr_symbol: *mut c_char,
130         pub currency_symbol: *mut c_char,
131         pub mon_decimal_point: *mut c_char,
132         pub mon_thousands_sep: *mut c_char,
133         pub mon_grouping: *mut c_char,
134         pub positive_sign: *mut c_char,
135         pub negative_sign: *mut c_char,
136         pub int_frac_digits: c_char,
137         pub frac_digits: c_char,
138         pub p_cs_precedes: c_char,
139         pub p_sep_by_space: c_char,
140         pub n_cs_precedes: c_char,
141         pub n_sep_by_space: c_char,
142         pub p_sign_posn: c_char,
143         pub n_sign_posn: c_char,
144         pub int_p_cs_precedes: c_char,
145         pub int_p_sep_by_space: c_char,
146         pub int_n_cs_precedes: c_char,
147         pub int_n_sep_by_space: c_char,
148         pub int_p_sign_posn: c_char,
149         pub int_n_sign_posn: c_char,
150     }
151 
152     pub struct in_pktinfo {
153         pub ipi_ifindex: c_int,
154         pub ipi_spec_dst: crate::in_addr,
155         pub ipi_addr: crate::in_addr,
156     }
157 
158     pub struct ifaddrs {
159         pub ifa_next: *mut ifaddrs,
160         pub ifa_name: *mut c_char,
161         pub ifa_flags: c_uint,
162         pub ifa_addr: *mut crate::sockaddr,
163         pub ifa_netmask: *mut crate::sockaddr,
164         pub ifa_ifu: *mut crate::sockaddr, // FIXME(union) This should be a union
165         pub ifa_data: *mut c_void,
166     }
167 
168     pub struct in6_rtmsg {
169         rtmsg_dst: crate::in6_addr,
170         rtmsg_src: crate::in6_addr,
171         rtmsg_gateway: crate::in6_addr,
172         rtmsg_type: u32,
173         rtmsg_dst_len: u16,
174         rtmsg_src_len: u16,
175         rtmsg_metric: u32,
176         rtmsg_info: c_ulong,
177         rtmsg_flags: u32,
178         rtmsg_ifindex: c_int,
179     }
180 
181     pub struct arpreq {
182         pub arp_pa: crate::sockaddr,
183         pub arp_ha: crate::sockaddr,
184         pub arp_flags: c_int,
185         pub arp_netmask: crate::sockaddr,
186         pub arp_dev: [c_char; 16],
187     }
188 
189     pub struct arpreq_old {
190         pub arp_pa: crate::sockaddr,
191         pub arp_ha: crate::sockaddr,
192         pub arp_flags: c_int,
193         pub arp_netmask: crate::sockaddr,
194     }
195 
196     pub struct arphdr {
197         pub ar_hrd: u16,
198         pub ar_pro: u16,
199         pub ar_hln: u8,
200         pub ar_pln: u8,
201         pub ar_op: u16,
202     }
203 
204     pub struct mmsghdr {
205         pub msg_hdr: crate::msghdr,
206         pub msg_len: c_uint,
207     }
208 }
209 
210 cfg_if! {
211     if #[cfg(not(target_os = "emscripten"))] {
212         s! {
213             pub struct file_clone_range {
214                 pub src_fd: crate::__s64,
215                 pub src_offset: crate::__u64,
216                 pub src_length: crate::__u64,
217                 pub dest_offset: crate::__u64,
218             }
219 
220             // linux/filter.h
221             pub struct sock_filter {
222                 pub code: __u16,
223                 pub jt: __u8,
224                 pub jf: __u8,
225                 pub k: __u32,
226             }
227 
228             pub struct sock_fprog {
229                 pub len: c_ushort,
230                 pub filter: *mut sock_filter,
231             }
232         }
233     }
234 }
235 
236 cfg_if! {
237     if #[cfg(any(target_env = "gnu", target_os = "android"))] {
238         s! {
239             pub struct statx {
240                 pub stx_mask: crate::__u32,
241                 pub stx_blksize: crate::__u32,
242                 pub stx_attributes: crate::__u64,
243                 pub stx_nlink: crate::__u32,
244                 pub stx_uid: crate::__u32,
245                 pub stx_gid: crate::__u32,
246                 pub stx_mode: crate::__u16,
247                 __statx_pad1: [crate::__u16; 1],
248                 pub stx_ino: crate::__u64,
249                 pub stx_size: crate::__u64,
250                 pub stx_blocks: crate::__u64,
251                 pub stx_attributes_mask: crate::__u64,
252                 pub stx_atime: statx_timestamp,
253                 pub stx_btime: statx_timestamp,
254                 pub stx_ctime: statx_timestamp,
255                 pub stx_mtime: statx_timestamp,
256                 pub stx_rdev_major: crate::__u32,
257                 pub stx_rdev_minor: crate::__u32,
258                 pub stx_dev_major: crate::__u32,
259                 pub stx_dev_minor: crate::__u32,
260                 pub stx_mnt_id: crate::__u64,
261                 pub stx_dio_mem_align: crate::__u32,
262                 pub stx_dio_offset_align: crate::__u32,
263                 __statx_pad3: [crate::__u64; 12],
264             }
265 
266             pub struct statx_timestamp {
267                 pub tv_sec: crate::__s64,
268                 pub tv_nsec: crate::__u32,
269                 __statx_timestamp_pad1: [crate::__s32; 1],
270             }
271         }
272     }
273 }
274 
275 s_no_extra_traits! {
276     #[cfg_attr(
277         any(
278             all(
279                 target_arch = "x86",
280                 not(target_env = "musl"),
281                 not(target_os = "android")
282             ),
283             target_arch = "x86_64"
284         ),
285         repr(packed)
286     )]
287     pub struct epoll_event {
288         pub events: u32,
289         pub u64: u64,
290     }
291 
292     pub struct sockaddr_un {
293         pub sun_family: sa_family_t,
294         pub sun_path: [c_char; 108],
295     }
296 
297     pub struct sockaddr_storage {
298         pub ss_family: sa_family_t,
299         #[cfg(target_pointer_width = "32")]
300         __ss_pad2: [u8; 128 - 2 - 4],
301         #[cfg(target_pointer_width = "64")]
302         __ss_pad2: [u8; 128 - 2 - 8],
303         __ss_align: size_t,
304     }
305 
306     pub struct utsname {
307         pub sysname: [c_char; 65],
308         pub nodename: [c_char; 65],
309         pub release: [c_char; 65],
310         pub version: [c_char; 65],
311         pub machine: [c_char; 65],
312         pub domainname: [c_char; 65],
313     }
314 
315     pub struct sigevent {
316         pub sigev_value: crate::sigval,
317         pub sigev_signo: c_int,
318         pub sigev_notify: c_int,
319         // Actually a union.  We only expose sigev_notify_thread_id because it's
320         // the most useful member
321         pub sigev_notify_thread_id: c_int,
322         #[cfg(target_pointer_width = "64")]
323         __unused1: [c_int; 11],
324         #[cfg(target_pointer_width = "32")]
325         __unused1: [c_int; 12],
326     }
327 }
328 
329 cfg_if! {
330     if #[cfg(feature = "extra_traits")] {
331         impl PartialEq for epoll_event {
332             fn eq(&self, other: &epoll_event) -> bool {
333                 self.events == other.events && self.u64 == other.u64
334             }
335         }
336         impl Eq for epoll_event {}
337         impl hash::Hash for epoll_event {
338             fn hash<H: hash::Hasher>(&self, state: &mut H) {
339                 let events = self.events;
340                 let u64 = self.u64;
341                 events.hash(state);
342                 u64.hash(state);
343             }
344         }
345 
346         impl PartialEq for sockaddr_un {
347             fn eq(&self, other: &sockaddr_un) -> bool {
348                 self.sun_family == other.sun_family
349                     && self
350                         .sun_path
351                         .iter()
352                         .zip(other.sun_path.iter())
353                         .all(|(a, b)| a == b)
354             }
355         }
356         impl Eq for sockaddr_un {}
357         impl hash::Hash for sockaddr_un {
358             fn hash<H: hash::Hasher>(&self, state: &mut H) {
359                 self.sun_family.hash(state);
360                 self.sun_path.hash(state);
361             }
362         }
363 
364         impl PartialEq for sockaddr_storage {
365             fn eq(&self, other: &sockaddr_storage) -> bool {
366                 self.ss_family == other.ss_family
367                     && self
368                         .__ss_pad2
369                         .iter()
370                         .zip(other.__ss_pad2.iter())
371                         .all(|(a, b)| a == b)
372             }
373         }
374 
375         impl Eq for sockaddr_storage {}
376 
377         impl hash::Hash for sockaddr_storage {
378             fn hash<H: hash::Hasher>(&self, state: &mut H) {
379                 self.ss_family.hash(state);
380                 self.__ss_pad2.hash(state);
381             }
382         }
383 
384         impl PartialEq for utsname {
385             fn eq(&self, other: &utsname) -> bool {
386                 self.sysname
387                     .iter()
388                     .zip(other.sysname.iter())
389                     .all(|(a, b)| a == b)
390                     && self
391                         .nodename
392                         .iter()
393                         .zip(other.nodename.iter())
394                         .all(|(a, b)| a == b)
395                     && self
396                         .release
397                         .iter()
398                         .zip(other.release.iter())
399                         .all(|(a, b)| a == b)
400                     && self
401                         .version
402                         .iter()
403                         .zip(other.version.iter())
404                         .all(|(a, b)| a == b)
405                     && self
406                         .machine
407                         .iter()
408                         .zip(other.machine.iter())
409                         .all(|(a, b)| a == b)
410                     && self
411                         .domainname
412                         .iter()
413                         .zip(other.domainname.iter())
414                         .all(|(a, b)| a == b)
415             }
416         }
417 
418         impl Eq for utsname {}
419 
420         impl hash::Hash for utsname {
421             fn hash<H: hash::Hasher>(&self, state: &mut H) {
422                 self.sysname.hash(state);
423                 self.nodename.hash(state);
424                 self.release.hash(state);
425                 self.version.hash(state);
426                 self.machine.hash(state);
427                 self.domainname.hash(state);
428             }
429         }
430 
431         impl PartialEq for sigevent {
432             fn eq(&self, other: &sigevent) -> bool {
433                 self.sigev_value == other.sigev_value
434                     && self.sigev_signo == other.sigev_signo
435                     && self.sigev_notify == other.sigev_notify
436                     && self.sigev_notify_thread_id == other.sigev_notify_thread_id
437             }
438         }
439         impl Eq for sigevent {}
440         impl hash::Hash for sigevent {
441             fn hash<H: hash::Hasher>(&self, state: &mut H) {
442                 self.sigev_value.hash(state);
443                 self.sigev_signo.hash(state);
444                 self.sigev_notify.hash(state);
445                 self.sigev_notify_thread_id.hash(state);
446             }
447         }
448     }
449 }
450 
451 // intentionally not public, only used for fd_set
452 cfg_if! {
453     if #[cfg(target_pointer_width = "32")] {
454         const ULONG_SIZE: usize = 32;
455     } else if #[cfg(target_pointer_width = "64")] {
456         const ULONG_SIZE: usize = 64;
457     } else {
458         // Unknown target_pointer_width
459     }
460 }
461 
462 pub const EXIT_FAILURE: c_int = 1;
463 pub const EXIT_SUCCESS: c_int = 0;
464 pub const RAND_MAX: c_int = 2147483647;
465 pub const EOF: c_int = -1;
466 pub const SEEK_SET: c_int = 0;
467 pub const SEEK_CUR: c_int = 1;
468 pub const SEEK_END: c_int = 2;
469 pub const _IOFBF: c_int = 0;
470 pub const _IONBF: c_int = 2;
471 pub const _IOLBF: c_int = 1;
472 
473 pub const F_DUPFD: c_int = 0;
474 pub const F_GETFD: c_int = 1;
475 pub const F_SETFD: c_int = 2;
476 pub const F_GETFL: c_int = 3;
477 pub const F_SETFL: c_int = 4;
478 
479 // Linux-specific fcntls
480 pub const F_SETLEASE: c_int = 1024;
481 pub const F_GETLEASE: c_int = 1025;
482 pub const F_NOTIFY: c_int = 1026;
483 pub const F_CANCELLK: c_int = 1029;
484 pub const F_DUPFD_CLOEXEC: c_int = 1030;
485 pub const F_SETPIPE_SZ: c_int = 1031;
486 pub const F_GETPIPE_SZ: c_int = 1032;
487 pub const F_ADD_SEALS: c_int = 1033;
488 pub const F_GET_SEALS: c_int = 1034;
489 
490 pub const F_SEAL_SEAL: c_int = 0x0001;
491 pub const F_SEAL_SHRINK: c_int = 0x0002;
492 pub const F_SEAL_GROW: c_int = 0x0004;
493 pub const F_SEAL_WRITE: c_int = 0x0008;
494 
495 // FIXME(#235): Include file sealing fcntls once we have a way to verify them.
496 
497 pub const SIGTRAP: c_int = 5;
498 
499 pub const PTHREAD_CREATE_JOINABLE: c_int = 0;
500 pub const PTHREAD_CREATE_DETACHED: c_int = 1;
501 
502 pub const CLOCK_REALTIME: crate::clockid_t = 0;
503 pub const CLOCK_MONOTONIC: crate::clockid_t = 1;
504 pub const CLOCK_PROCESS_CPUTIME_ID: crate::clockid_t = 2;
505 pub const CLOCK_THREAD_CPUTIME_ID: crate::clockid_t = 3;
506 pub const CLOCK_MONOTONIC_RAW: crate::clockid_t = 4;
507 pub const CLOCK_REALTIME_COARSE: crate::clockid_t = 5;
508 pub const CLOCK_MONOTONIC_COARSE: crate::clockid_t = 6;
509 pub const CLOCK_BOOTTIME: crate::clockid_t = 7;
510 pub const CLOCK_REALTIME_ALARM: crate::clockid_t = 8;
511 pub const CLOCK_BOOTTIME_ALARM: crate::clockid_t = 9;
512 pub const CLOCK_TAI: crate::clockid_t = 11;
513 pub const TIMER_ABSTIME: c_int = 1;
514 
515 pub const RUSAGE_SELF: c_int = 0;
516 
517 pub const O_RDONLY: c_int = 0;
518 pub const O_WRONLY: c_int = 1;
519 pub const O_RDWR: c_int = 2;
520 
521 pub const SOCK_CLOEXEC: c_int = O_CLOEXEC;
522 
523 pub const S_IFIFO: mode_t = 0o1_0000;
524 pub const S_IFCHR: mode_t = 0o2_0000;
525 pub const S_IFBLK: mode_t = 0o6_0000;
526 pub const S_IFDIR: mode_t = 0o4_0000;
527 pub const S_IFREG: mode_t = 0o10_0000;
528 pub const S_IFLNK: mode_t = 0o12_0000;
529 pub const S_IFSOCK: mode_t = 0o14_0000;
530 pub const S_IFMT: mode_t = 0o17_0000;
531 pub const S_IRWXU: mode_t = 0o0700;
532 pub const S_IXUSR: mode_t = 0o0100;
533 pub const S_IWUSR: mode_t = 0o0200;
534 pub const S_IRUSR: mode_t = 0o0400;
535 pub const S_IRWXG: mode_t = 0o0070;
536 pub const S_IXGRP: mode_t = 0o0010;
537 pub const S_IWGRP: mode_t = 0o0020;
538 pub const S_IRGRP: mode_t = 0o0040;
539 pub const S_IRWXO: mode_t = 0o0007;
540 pub const S_IXOTH: mode_t = 0o0001;
541 pub const S_IWOTH: mode_t = 0o0002;
542 pub const S_IROTH: mode_t = 0o0004;
543 pub const F_OK: c_int = 0;
544 pub const R_OK: c_int = 4;
545 pub const W_OK: c_int = 2;
546 pub const X_OK: c_int = 1;
547 pub const STDIN_FILENO: c_int = 0;
548 pub const STDOUT_FILENO: c_int = 1;
549 pub const STDERR_FILENO: c_int = 2;
550 pub const SIGHUP: c_int = 1;
551 pub const SIGINT: c_int = 2;
552 pub const SIGQUIT: c_int = 3;
553 pub const SIGILL: c_int = 4;
554 pub const SIGABRT: c_int = 6;
555 pub const SIGFPE: c_int = 8;
556 pub const SIGKILL: c_int = 9;
557 pub const SIGSEGV: c_int = 11;
558 pub const SIGPIPE: c_int = 13;
559 pub const SIGALRM: c_int = 14;
560 pub const SIGTERM: c_int = 15;
561 
562 pub const PROT_NONE: c_int = 0;
563 pub const PROT_READ: c_int = 1;
564 pub const PROT_WRITE: c_int = 2;
565 pub const PROT_EXEC: c_int = 4;
566 
567 pub const XATTR_CREATE: c_int = 0x1;
568 pub const XATTR_REPLACE: c_int = 0x2;
569 
570 cfg_if! {
571     if #[cfg(target_os = "android")] {
572         pub const RLIM64_INFINITY: c_ulonglong = !0;
573     } else {
574         pub const RLIM64_INFINITY: crate::rlim64_t = !0;
575     }
576 }
577 
578 cfg_if! {
579     if #[cfg(target_env = "ohos")] {
580         pub const LC_CTYPE: c_int = 0;
581         pub const LC_NUMERIC: c_int = 1;
582         pub const LC_TIME: c_int = 2;
583         pub const LC_COLLATE: c_int = 3;
584         pub const LC_MONETARY: c_int = 4;
585         pub const LC_MESSAGES: c_int = 5;
586         pub const LC_PAPER: c_int = 6;
587         pub const LC_NAME: c_int = 7;
588         pub const LC_ADDRESS: c_int = 8;
589         pub const LC_TELEPHONE: c_int = 9;
590         pub const LC_MEASUREMENT: c_int = 10;
591         pub const LC_IDENTIFICATION: c_int = 11;
592         pub const LC_ALL: c_int = 12;
593     } else if #[cfg(not(target_env = "uclibc"))] {
594         pub const LC_CTYPE: c_int = 0;
595         pub const LC_NUMERIC: c_int = 1;
596         pub const LC_TIME: c_int = 2;
597         pub const LC_COLLATE: c_int = 3;
598         pub const LC_MONETARY: c_int = 4;
599         pub const LC_MESSAGES: c_int = 5;
600         pub const LC_ALL: c_int = 6;
601     }
602 }
603 
604 pub const LC_CTYPE_MASK: c_int = 1 << LC_CTYPE;
605 pub const LC_NUMERIC_MASK: c_int = 1 << LC_NUMERIC;
606 pub const LC_TIME_MASK: c_int = 1 << LC_TIME;
607 pub const LC_COLLATE_MASK: c_int = 1 << LC_COLLATE;
608 pub const LC_MONETARY_MASK: c_int = 1 << LC_MONETARY;
609 pub const LC_MESSAGES_MASK: c_int = 1 << LC_MESSAGES;
610 // LC_ALL_MASK defined per platform
611 
612 pub const MAP_FILE: c_int = 0x0000;
613 pub const MAP_SHARED: c_int = 0x0001;
614 pub const MAP_PRIVATE: c_int = 0x0002;
615 pub const MAP_FIXED: c_int = 0x0010;
616 
617 pub const MAP_FAILED: *mut c_void = !0 as *mut c_void;
618 
619 // MS_ flags for msync(2)
620 pub const MS_ASYNC: c_int = 0x0001;
621 pub const MS_INVALIDATE: c_int = 0x0002;
622 pub const MS_SYNC: c_int = 0x0004;
623 
624 // MS_ flags for mount(2)
625 pub const MS_RDONLY: c_ulong = 0x01;
626 pub const MS_NOSUID: c_ulong = 0x02;
627 pub const MS_NODEV: c_ulong = 0x04;
628 pub const MS_NOEXEC: c_ulong = 0x08;
629 pub const MS_SYNCHRONOUS: c_ulong = 0x10;
630 pub const MS_REMOUNT: c_ulong = 0x20;
631 pub const MS_MANDLOCK: c_ulong = 0x40;
632 pub const MS_DIRSYNC: c_ulong = 0x80;
633 pub const MS_NOATIME: c_ulong = 0x0400;
634 pub const MS_NODIRATIME: c_ulong = 0x0800;
635 pub const MS_BIND: c_ulong = 0x1000;
636 pub const MS_MOVE: c_ulong = 0x2000;
637 pub const MS_REC: c_ulong = 0x4000;
638 pub const MS_SILENT: c_ulong = 0x8000;
639 pub const MS_POSIXACL: c_ulong = 0x010000;
640 pub const MS_UNBINDABLE: c_ulong = 0x020000;
641 pub const MS_PRIVATE: c_ulong = 0x040000;
642 pub const MS_SLAVE: c_ulong = 0x080000;
643 pub const MS_SHARED: c_ulong = 0x100000;
644 pub const MS_RELATIME: c_ulong = 0x200000;
645 pub const MS_KERNMOUNT: c_ulong = 0x400000;
646 pub const MS_I_VERSION: c_ulong = 0x800000;
647 pub const MS_STRICTATIME: c_ulong = 0x1000000;
648 pub const MS_LAZYTIME: c_ulong = 0x2000000;
649 pub const MS_ACTIVE: c_ulong = 0x40000000;
650 pub const MS_MGC_VAL: c_ulong = 0xc0ed0000;
651 pub const MS_MGC_MSK: c_ulong = 0xffff0000;
652 
653 pub const SCM_RIGHTS: c_int = 0x01;
654 pub const SCM_CREDENTIALS: c_int = 0x02;
655 
656 pub const PROT_GROWSDOWN: c_int = 0x1000000;
657 pub const PROT_GROWSUP: c_int = 0x2000000;
658 
659 pub const MAP_TYPE: c_int = 0x000f;
660 
661 pub const MADV_NORMAL: c_int = 0;
662 pub const MADV_RANDOM: c_int = 1;
663 pub const MADV_SEQUENTIAL: c_int = 2;
664 pub const MADV_WILLNEED: c_int = 3;
665 pub const MADV_DONTNEED: c_int = 4;
666 pub const MADV_FREE: c_int = 8;
667 pub const MADV_REMOVE: c_int = 9;
668 pub const MADV_DONTFORK: c_int = 10;
669 pub const MADV_DOFORK: c_int = 11;
670 pub const MADV_MERGEABLE: c_int = 12;
671 pub const MADV_UNMERGEABLE: c_int = 13;
672 pub const MADV_HUGEPAGE: c_int = 14;
673 pub const MADV_NOHUGEPAGE: c_int = 15;
674 pub const MADV_DONTDUMP: c_int = 16;
675 pub const MADV_DODUMP: c_int = 17;
676 pub const MADV_WIPEONFORK: c_int = 18;
677 pub const MADV_KEEPONFORK: c_int = 19;
678 pub const MADV_COLD: c_int = 20;
679 pub const MADV_PAGEOUT: c_int = 21;
680 pub const MADV_HWPOISON: c_int = 100;
681 cfg_if! {
682     if #[cfg(not(target_os = "emscripten"))] {
683         pub const MADV_POPULATE_READ: c_int = 22;
684         pub const MADV_POPULATE_WRITE: c_int = 23;
685         pub const MADV_DONTNEED_LOCKED: c_int = 24;
686     }
687 }
688 
689 pub const IFF_UP: c_int = 0x1;
690 pub const IFF_BROADCAST: c_int = 0x2;
691 pub const IFF_DEBUG: c_int = 0x4;
692 pub const IFF_LOOPBACK: c_int = 0x8;
693 pub const IFF_POINTOPOINT: c_int = 0x10;
694 pub const IFF_NOTRAILERS: c_int = 0x20;
695 pub const IFF_RUNNING: c_int = 0x40;
696 pub const IFF_NOARP: c_int = 0x80;
697 pub const IFF_PROMISC: c_int = 0x100;
698 pub const IFF_ALLMULTI: c_int = 0x200;
699 pub const IFF_MASTER: c_int = 0x400;
700 pub const IFF_SLAVE: c_int = 0x800;
701 pub const IFF_MULTICAST: c_int = 0x1000;
702 pub const IFF_PORTSEL: c_int = 0x2000;
703 pub const IFF_AUTOMEDIA: c_int = 0x4000;
704 pub const IFF_DYNAMIC: c_int = 0x8000;
705 
706 pub const SOL_IP: c_int = 0;
707 pub const SOL_TCP: c_int = 6;
708 pub const SOL_UDP: c_int = 17;
709 pub const SOL_IPV6: c_int = 41;
710 pub const SOL_ICMPV6: c_int = 58;
711 pub const SOL_RAW: c_int = 255;
712 pub const SOL_DECNET: c_int = 261;
713 pub const SOL_X25: c_int = 262;
714 pub const SOL_PACKET: c_int = 263;
715 pub const SOL_ATM: c_int = 264;
716 pub const SOL_AAL: c_int = 265;
717 pub const SOL_IRDA: c_int = 266;
718 pub const SOL_NETBEUI: c_int = 267;
719 pub const SOL_LLC: c_int = 268;
720 pub const SOL_DCCP: c_int = 269;
721 pub const SOL_NETLINK: c_int = 270;
722 pub const SOL_TIPC: c_int = 271;
723 pub const SOL_BLUETOOTH: c_int = 274;
724 pub const SOL_ALG: c_int = 279;
725 
726 pub const AF_UNSPEC: c_int = 0;
727 pub const AF_UNIX: c_int = 1;
728 pub const AF_LOCAL: c_int = 1;
729 pub const AF_INET: c_int = 2;
730 pub const AF_AX25: c_int = 3;
731 pub const AF_IPX: c_int = 4;
732 pub const AF_APPLETALK: c_int = 5;
733 pub const AF_NETROM: c_int = 6;
734 pub const AF_BRIDGE: c_int = 7;
735 pub const AF_ATMPVC: c_int = 8;
736 pub const AF_X25: c_int = 9;
737 pub const AF_INET6: c_int = 10;
738 pub const AF_ROSE: c_int = 11;
739 pub const AF_DECnet: c_int = 12;
740 pub const AF_NETBEUI: c_int = 13;
741 pub const AF_SECURITY: c_int = 14;
742 pub const AF_KEY: c_int = 15;
743 pub const AF_NETLINK: c_int = 16;
744 pub const AF_ROUTE: c_int = AF_NETLINK;
745 pub const AF_PACKET: c_int = 17;
746 pub const AF_ASH: c_int = 18;
747 pub const AF_ECONET: c_int = 19;
748 pub const AF_ATMSVC: c_int = 20;
749 pub const AF_RDS: c_int = 21;
750 pub const AF_SNA: c_int = 22;
751 pub const AF_IRDA: c_int = 23;
752 pub const AF_PPPOX: c_int = 24;
753 pub const AF_WANPIPE: c_int = 25;
754 pub const AF_LLC: c_int = 26;
755 pub const AF_CAN: c_int = 29;
756 pub const AF_TIPC: c_int = 30;
757 pub const AF_BLUETOOTH: c_int = 31;
758 pub const AF_IUCV: c_int = 32;
759 pub const AF_RXRPC: c_int = 33;
760 pub const AF_ISDN: c_int = 34;
761 pub const AF_PHONET: c_int = 35;
762 pub const AF_IEEE802154: c_int = 36;
763 pub const AF_CAIF: c_int = 37;
764 pub const AF_ALG: c_int = 38;
765 
766 pub const PF_UNSPEC: c_int = AF_UNSPEC;
767 pub const PF_UNIX: c_int = AF_UNIX;
768 pub const PF_LOCAL: c_int = AF_LOCAL;
769 pub const PF_INET: c_int = AF_INET;
770 pub const PF_AX25: c_int = AF_AX25;
771 pub const PF_IPX: c_int = AF_IPX;
772 pub const PF_APPLETALK: c_int = AF_APPLETALK;
773 pub const PF_NETROM: c_int = AF_NETROM;
774 pub const PF_BRIDGE: c_int = AF_BRIDGE;
775 pub const PF_ATMPVC: c_int = AF_ATMPVC;
776 pub const PF_X25: c_int = AF_X25;
777 pub const PF_INET6: c_int = AF_INET6;
778 pub const PF_ROSE: c_int = AF_ROSE;
779 pub const PF_DECnet: c_int = AF_DECnet;
780 pub const PF_NETBEUI: c_int = AF_NETBEUI;
781 pub const PF_SECURITY: c_int = AF_SECURITY;
782 pub const PF_KEY: c_int = AF_KEY;
783 pub const PF_NETLINK: c_int = AF_NETLINK;
784 pub const PF_ROUTE: c_int = AF_ROUTE;
785 pub const PF_PACKET: c_int = AF_PACKET;
786 pub const PF_ASH: c_int = AF_ASH;
787 pub const PF_ECONET: c_int = AF_ECONET;
788 pub const PF_ATMSVC: c_int = AF_ATMSVC;
789 pub const PF_RDS: c_int = AF_RDS;
790 pub const PF_SNA: c_int = AF_SNA;
791 pub const PF_IRDA: c_int = AF_IRDA;
792 pub const PF_PPPOX: c_int = AF_PPPOX;
793 pub const PF_WANPIPE: c_int = AF_WANPIPE;
794 pub const PF_LLC: c_int = AF_LLC;
795 pub const PF_CAN: c_int = AF_CAN;
796 pub const PF_TIPC: c_int = AF_TIPC;
797 pub const PF_BLUETOOTH: c_int = AF_BLUETOOTH;
798 pub const PF_IUCV: c_int = AF_IUCV;
799 pub const PF_RXRPC: c_int = AF_RXRPC;
800 pub const PF_ISDN: c_int = AF_ISDN;
801 pub const PF_PHONET: c_int = AF_PHONET;
802 pub const PF_IEEE802154: c_int = AF_IEEE802154;
803 pub const PF_CAIF: c_int = AF_CAIF;
804 pub const PF_ALG: c_int = AF_ALG;
805 
806 pub const MSG_OOB: c_int = 1;
807 pub const MSG_PEEK: c_int = 2;
808 pub const MSG_DONTROUTE: c_int = 4;
809 pub const MSG_CTRUNC: c_int = 8;
810 pub const MSG_TRUNC: c_int = 0x20;
811 pub const MSG_DONTWAIT: c_int = 0x40;
812 pub const MSG_EOR: c_int = 0x80;
813 pub const MSG_WAITALL: c_int = 0x100;
814 pub const MSG_FIN: c_int = 0x200;
815 pub const MSG_SYN: c_int = 0x400;
816 pub const MSG_CONFIRM: c_int = 0x800;
817 pub const MSG_RST: c_int = 0x1000;
818 pub const MSG_ERRQUEUE: c_int = 0x2000;
819 pub const MSG_NOSIGNAL: c_int = 0x4000;
820 pub const MSG_MORE: c_int = 0x8000;
821 pub const MSG_WAITFORONE: c_int = 0x10000;
822 pub const MSG_FASTOPEN: c_int = 0x20000000;
823 pub const MSG_CMSG_CLOEXEC: c_int = 0x40000000;
824 
825 pub const SCM_TIMESTAMP: c_int = SO_TIMESTAMP;
826 
827 pub const SOCK_RAW: c_int = 3;
828 pub const SOCK_RDM: c_int = 4;
829 pub const IP_TOS: c_int = 1;
830 pub const IP_TTL: c_int = 2;
831 pub const IP_HDRINCL: c_int = 3;
832 pub const IP_OPTIONS: c_int = 4;
833 pub const IP_ROUTER_ALERT: c_int = 5;
834 pub const IP_RECVOPTS: c_int = 6;
835 pub const IP_RETOPTS: c_int = 7;
836 pub const IP_PKTINFO: c_int = 8;
837 pub const IP_PKTOPTIONS: c_int = 9;
838 pub const IP_MTU_DISCOVER: c_int = 10;
839 pub const IP_RECVERR: c_int = 11;
840 pub const IP_RECVTTL: c_int = 12;
841 pub const IP_RECVTOS: c_int = 13;
842 pub const IP_MTU: c_int = 14;
843 pub const IP_FREEBIND: c_int = 15;
844 pub const IP_IPSEC_POLICY: c_int = 16;
845 pub const IP_XFRM_POLICY: c_int = 17;
846 pub const IP_PASSSEC: c_int = 18;
847 pub const IP_TRANSPARENT: c_int = 19;
848 pub const IP_ORIGDSTADDR: c_int = 20;
849 pub const IP_RECVORIGDSTADDR: c_int = IP_ORIGDSTADDR;
850 pub const IP_MINTTL: c_int = 21;
851 pub const IP_NODEFRAG: c_int = 22;
852 pub const IP_CHECKSUM: c_int = 23;
853 pub const IP_BIND_ADDRESS_NO_PORT: c_int = 24;
854 pub const IP_MULTICAST_IF: c_int = 32;
855 pub const IP_MULTICAST_TTL: c_int = 33;
856 pub const IP_MULTICAST_LOOP: c_int = 34;
857 pub const IP_ADD_MEMBERSHIP: c_int = 35;
858 pub const IP_DROP_MEMBERSHIP: c_int = 36;
859 pub const IP_UNBLOCK_SOURCE: c_int = 37;
860 pub const IP_BLOCK_SOURCE: c_int = 38;
861 pub const IP_ADD_SOURCE_MEMBERSHIP: c_int = 39;
862 pub const IP_DROP_SOURCE_MEMBERSHIP: c_int = 40;
863 pub const IP_MSFILTER: c_int = 41;
864 pub const IP_MULTICAST_ALL: c_int = 49;
865 pub const IP_UNICAST_IF: c_int = 50;
866 
867 pub const IP_DEFAULT_MULTICAST_TTL: c_int = 1;
868 pub const IP_DEFAULT_MULTICAST_LOOP: c_int = 1;
869 
870 pub const IP_PMTUDISC_DONT: c_int = 0;
871 pub const IP_PMTUDISC_WANT: c_int = 1;
872 pub const IP_PMTUDISC_DO: c_int = 2;
873 pub const IP_PMTUDISC_PROBE: c_int = 3;
874 pub const IP_PMTUDISC_INTERFACE: c_int = 4;
875 pub const IP_PMTUDISC_OMIT: c_int = 5;
876 
877 // IPPROTO_IP defined in src/unix/mod.rs
878 /// Hop-by-hop option header
879 pub const IPPROTO_HOPOPTS: c_int = 0;
880 // IPPROTO_ICMP defined in src/unix/mod.rs
881 /// group mgmt protocol
882 pub const IPPROTO_IGMP: c_int = 2;
883 /// for compatibility
884 pub const IPPROTO_IPIP: c_int = 4;
885 // IPPROTO_TCP defined in src/unix/mod.rs
886 /// exterior gateway protocol
887 pub const IPPROTO_EGP: c_int = 8;
888 /// pup
889 pub const IPPROTO_PUP: c_int = 12;
890 // IPPROTO_UDP defined in src/unix/mod.rs
891 /// xns idp
892 pub const IPPROTO_IDP: c_int = 22;
893 /// tp-4 w/ class negotiation
894 pub const IPPROTO_TP: c_int = 29;
895 /// DCCP
896 pub const IPPROTO_DCCP: c_int = 33;
897 // IPPROTO_IPV6 defined in src/unix/mod.rs
898 /// IP6 routing header
899 pub const IPPROTO_ROUTING: c_int = 43;
900 /// IP6 fragmentation header
901 pub const IPPROTO_FRAGMENT: c_int = 44;
902 /// resource reservation
903 pub const IPPROTO_RSVP: c_int = 46;
904 /// General Routing Encap.
905 pub const IPPROTO_GRE: c_int = 47;
906 /// IP6 Encap Sec. Payload
907 pub const IPPROTO_ESP: c_int = 50;
908 /// IP6 Auth Header
909 pub const IPPROTO_AH: c_int = 51;
910 // IPPROTO_ICMPV6 defined in src/unix/mod.rs
911 /// IP6 no next header
912 pub const IPPROTO_NONE: c_int = 59;
913 /// IP6 destination option
914 pub const IPPROTO_DSTOPTS: c_int = 60;
915 pub const IPPROTO_MTP: c_int = 92;
916 /// encapsulation header
917 pub const IPPROTO_ENCAP: c_int = 98;
918 /// Protocol indep. multicast
919 pub const IPPROTO_PIM: c_int = 103;
920 /// IP Payload Comp. Protocol
921 pub const IPPROTO_COMP: c_int = 108;
922 /// SCTP
923 pub const IPPROTO_SCTP: c_int = 132;
924 pub const IPPROTO_MH: c_int = 135;
925 pub const IPPROTO_UDPLITE: c_int = 136;
926 /// raw IP packet
927 pub const IPPROTO_RAW: c_int = 255;
928 pub const IPPROTO_BEETPH: c_int = 94;
929 pub const IPPROTO_MPLS: c_int = 137;
930 /// Multipath TCP
931 pub const IPPROTO_MPTCP: c_int = 262;
932 /// Ethernet-within-IPv6 encapsulation.
933 pub const IPPROTO_ETHERNET: c_int = 143;
934 
935 pub const MCAST_EXCLUDE: c_int = 0;
936 pub const MCAST_INCLUDE: c_int = 1;
937 pub const MCAST_JOIN_GROUP: c_int = 42;
938 pub const MCAST_BLOCK_SOURCE: c_int = 43;
939 pub const MCAST_UNBLOCK_SOURCE: c_int = 44;
940 pub const MCAST_LEAVE_GROUP: c_int = 45;
941 pub const MCAST_JOIN_SOURCE_GROUP: c_int = 46;
942 pub const MCAST_LEAVE_SOURCE_GROUP: c_int = 47;
943 pub const MCAST_MSFILTER: c_int = 48;
944 
945 pub const IPV6_ADDRFORM: c_int = 1;
946 pub const IPV6_2292PKTINFO: c_int = 2;
947 pub const IPV6_2292HOPOPTS: c_int = 3;
948 pub const IPV6_2292DSTOPTS: c_int = 4;
949 pub const IPV6_2292RTHDR: c_int = 5;
950 pub const IPV6_2292PKTOPTIONS: c_int = 6;
951 pub const IPV6_CHECKSUM: c_int = 7;
952 pub const IPV6_2292HOPLIMIT: c_int = 8;
953 pub const IPV6_NEXTHOP: c_int = 9;
954 pub const IPV6_AUTHHDR: c_int = 10;
955 pub const IPV6_UNICAST_HOPS: c_int = 16;
956 pub const IPV6_MULTICAST_IF: c_int = 17;
957 pub const IPV6_MULTICAST_HOPS: c_int = 18;
958 pub const IPV6_MULTICAST_LOOP: c_int = 19;
959 pub const IPV6_ADD_MEMBERSHIP: c_int = 20;
960 pub const IPV6_DROP_MEMBERSHIP: c_int = 21;
961 pub const IPV6_ROUTER_ALERT: c_int = 22;
962 pub const IPV6_MTU_DISCOVER: c_int = 23;
963 pub const IPV6_MTU: c_int = 24;
964 pub const IPV6_RECVERR: c_int = 25;
965 pub const IPV6_V6ONLY: c_int = 26;
966 pub const IPV6_JOIN_ANYCAST: c_int = 27;
967 pub const IPV6_LEAVE_ANYCAST: c_int = 28;
968 pub const IPV6_IPSEC_POLICY: c_int = 34;
969 pub const IPV6_XFRM_POLICY: c_int = 35;
970 pub const IPV6_HDRINCL: c_int = 36;
971 pub const IPV6_RECVPKTINFO: c_int = 49;
972 pub const IPV6_PKTINFO: c_int = 50;
973 pub const IPV6_RECVHOPLIMIT: c_int = 51;
974 pub const IPV6_HOPLIMIT: c_int = 52;
975 pub const IPV6_RECVHOPOPTS: c_int = 53;
976 pub const IPV6_HOPOPTS: c_int = 54;
977 pub const IPV6_RTHDRDSTOPTS: c_int = 55;
978 pub const IPV6_RECVRTHDR: c_int = 56;
979 pub const IPV6_RTHDR: c_int = 57;
980 pub const IPV6_RECVDSTOPTS: c_int = 58;
981 pub const IPV6_DSTOPTS: c_int = 59;
982 pub const IPV6_RECVPATHMTU: c_int = 60;
983 pub const IPV6_PATHMTU: c_int = 61;
984 pub const IPV6_DONTFRAG: c_int = 62;
985 pub const IPV6_RECVTCLASS: c_int = 66;
986 pub const IPV6_TCLASS: c_int = 67;
987 pub const IPV6_AUTOFLOWLABEL: c_int = 70;
988 pub const IPV6_ADDR_PREFERENCES: c_int = 72;
989 pub const IPV6_MINHOPCOUNT: c_int = 73;
990 pub const IPV6_ORIGDSTADDR: c_int = 74;
991 pub const IPV6_RECVORIGDSTADDR: c_int = IPV6_ORIGDSTADDR;
992 pub const IPV6_TRANSPARENT: c_int = 75;
993 pub const IPV6_UNICAST_IF: c_int = 76;
994 pub const IPV6_PREFER_SRC_TMP: c_int = 0x0001;
995 pub const IPV6_PREFER_SRC_PUBLIC: c_int = 0x0002;
996 pub const IPV6_PREFER_SRC_PUBTMP_DEFAULT: c_int = 0x0100;
997 pub const IPV6_PREFER_SRC_COA: c_int = 0x0004;
998 pub const IPV6_PREFER_SRC_HOME: c_int = 0x0400;
999 pub const IPV6_PREFER_SRC_CGA: c_int = 0x0008;
1000 pub const IPV6_PREFER_SRC_NONCGA: c_int = 0x0800;
1001 
1002 pub const IPV6_PMTUDISC_DONT: c_int = 0;
1003 pub const IPV6_PMTUDISC_WANT: c_int = 1;
1004 pub const IPV6_PMTUDISC_DO: c_int = 2;
1005 pub const IPV6_PMTUDISC_PROBE: c_int = 3;
1006 pub const IPV6_PMTUDISC_INTERFACE: c_int = 4;
1007 pub const IPV6_PMTUDISC_OMIT: c_int = 5;
1008 
1009 pub const TCP_NODELAY: c_int = 1;
1010 pub const TCP_MAXSEG: c_int = 2;
1011 pub const TCP_CORK: c_int = 3;
1012 pub const TCP_KEEPIDLE: c_int = 4;
1013 pub const TCP_KEEPINTVL: c_int = 5;
1014 pub const TCP_KEEPCNT: c_int = 6;
1015 pub const TCP_SYNCNT: c_int = 7;
1016 pub const TCP_LINGER2: c_int = 8;
1017 pub const TCP_DEFER_ACCEPT: c_int = 9;
1018 pub const TCP_WINDOW_CLAMP: c_int = 10;
1019 pub const TCP_INFO: c_int = 11;
1020 pub const TCP_QUICKACK: c_int = 12;
1021 pub const TCP_CONGESTION: c_int = 13;
1022 pub const TCP_MD5SIG: c_int = 14;
1023 cfg_if! {
1024     if #[cfg(all(
1025         target_os = "linux",
1026         any(target_env = "gnu", target_env = "musl", target_env = "ohos")
1027     ))] {
1028         // WARN: deprecated
1029         pub const TCP_COOKIE_TRANSACTIONS: c_int = 15;
1030     }
1031 }
1032 pub const TCP_THIN_LINEAR_TIMEOUTS: c_int = 16;
1033 pub const TCP_THIN_DUPACK: c_int = 17;
1034 pub const TCP_USER_TIMEOUT: c_int = 18;
1035 pub const TCP_REPAIR: c_int = 19;
1036 pub const TCP_REPAIR_QUEUE: c_int = 20;
1037 pub const TCP_QUEUE_SEQ: c_int = 21;
1038 pub const TCP_REPAIR_OPTIONS: c_int = 22;
1039 pub const TCP_FASTOPEN: c_int = 23;
1040 pub const TCP_TIMESTAMP: c_int = 24;
1041 pub const TCP_NOTSENT_LOWAT: c_int = 25;
1042 pub const TCP_CC_INFO: c_int = 26;
1043 pub const TCP_SAVE_SYN: c_int = 27;
1044 pub const TCP_SAVED_SYN: c_int = 28;
1045 cfg_if! {
1046     if #[cfg(not(target_os = "emscripten"))] {
1047         // NOTE: emscripten doesn't support these options yet.
1048 
1049         pub const TCP_REPAIR_WINDOW: c_int = 29;
1050         pub const TCP_FASTOPEN_CONNECT: c_int = 30;
1051         pub const TCP_ULP: c_int = 31;
1052         pub const TCP_MD5SIG_EXT: c_int = 32;
1053         pub const TCP_FASTOPEN_KEY: c_int = 33;
1054         pub const TCP_FASTOPEN_NO_COOKIE: c_int = 34;
1055         pub const TCP_ZEROCOPY_RECEIVE: c_int = 35;
1056         pub const TCP_INQ: c_int = 36;
1057         pub const TCP_CM_INQ: c_int = TCP_INQ;
1058         // NOTE: Some CI images doesn't have this option yet.
1059         // pub const TCP_TX_DELAY: c_int = 37;
1060         pub const TCP_MD5SIG_MAXKEYLEN: usize = 80;
1061     }
1062 }
1063 
1064 pub const SO_DEBUG: c_int = 1;
1065 
1066 pub const SHUT_RD: c_int = 0;
1067 pub const SHUT_WR: c_int = 1;
1068 pub const SHUT_RDWR: c_int = 2;
1069 
1070 pub const LOCK_SH: c_int = 1;
1071 pub const LOCK_EX: c_int = 2;
1072 pub const LOCK_NB: c_int = 4;
1073 pub const LOCK_UN: c_int = 8;
1074 
1075 pub const SS_ONSTACK: c_int = 1;
1076 pub const SS_DISABLE: c_int = 2;
1077 
1078 pub const PATH_MAX: c_int = 4096;
1079 
1080 pub const UIO_MAXIOV: c_int = 1024;
1081 
1082 pub const FD_SETSIZE: usize = 1024;
1083 
1084 pub const EPOLLIN: c_int = 0x1;
1085 pub const EPOLLPRI: c_int = 0x2;
1086 pub const EPOLLOUT: c_int = 0x4;
1087 pub const EPOLLERR: c_int = 0x8;
1088 pub const EPOLLHUP: c_int = 0x10;
1089 pub const EPOLLRDNORM: c_int = 0x40;
1090 pub const EPOLLRDBAND: c_int = 0x80;
1091 pub const EPOLLWRNORM: c_int = 0x100;
1092 pub const EPOLLWRBAND: c_int = 0x200;
1093 pub const EPOLLMSG: c_int = 0x400;
1094 pub const EPOLLRDHUP: c_int = 0x2000;
1095 pub const EPOLLEXCLUSIVE: c_int = 0x10000000;
1096 pub const EPOLLWAKEUP: c_int = 0x20000000;
1097 pub const EPOLLONESHOT: c_int = 0x40000000;
1098 pub const EPOLLET: c_int = 0x80000000;
1099 
1100 pub const EPOLL_CTL_ADD: c_int = 1;
1101 pub const EPOLL_CTL_MOD: c_int = 3;
1102 pub const EPOLL_CTL_DEL: c_int = 2;
1103 
1104 pub const MNT_FORCE: c_int = 0x1;
1105 pub const MNT_DETACH: c_int = 0x2;
1106 pub const MNT_EXPIRE: c_int = 0x4;
1107 pub const UMOUNT_NOFOLLOW: c_int = 0x8;
1108 
1109 pub const Q_GETFMT: c_int = 0x800004;
1110 pub const Q_GETINFO: c_int = 0x800005;
1111 pub const Q_SETINFO: c_int = 0x800006;
1112 pub const QIF_BLIMITS: u32 = 1;
1113 pub const QIF_SPACE: u32 = 2;
1114 pub const QIF_ILIMITS: u32 = 4;
1115 pub const QIF_INODES: u32 = 8;
1116 pub const QIF_BTIME: u32 = 16;
1117 pub const QIF_ITIME: u32 = 32;
1118 pub const QIF_LIMITS: u32 = 5;
1119 pub const QIF_USAGE: u32 = 10;
1120 pub const QIF_TIMES: u32 = 48;
1121 pub const QIF_ALL: u32 = 63;
1122 
1123 pub const Q_SYNC: c_int = 0x800001;
1124 pub const Q_QUOTAON: c_int = 0x800002;
1125 pub const Q_QUOTAOFF: c_int = 0x800003;
1126 pub const Q_GETQUOTA: c_int = 0x800007;
1127 pub const Q_SETQUOTA: c_int = 0x800008;
1128 
1129 pub const TCIOFF: c_int = 2;
1130 pub const TCION: c_int = 3;
1131 pub const TCOOFF: c_int = 0;
1132 pub const TCOON: c_int = 1;
1133 pub const TCIFLUSH: c_int = 0;
1134 pub const TCOFLUSH: c_int = 1;
1135 pub const TCIOFLUSH: c_int = 2;
1136 pub const NL0: crate::tcflag_t = 0x00000000;
1137 pub const NL1: crate::tcflag_t = 0x00000100;
1138 pub const TAB0: crate::tcflag_t = 0x00000000;
1139 pub const CR0: crate::tcflag_t = 0x00000000;
1140 pub const FF0: crate::tcflag_t = 0x00000000;
1141 pub const BS0: crate::tcflag_t = 0x00000000;
1142 pub const VT0: crate::tcflag_t = 0x00000000;
1143 pub const VERASE: usize = 2;
1144 pub const VKILL: usize = 3;
1145 pub const VINTR: usize = 0;
1146 pub const VQUIT: usize = 1;
1147 pub const VLNEXT: usize = 15;
1148 pub const IGNBRK: crate::tcflag_t = 0x00000001;
1149 pub const BRKINT: crate::tcflag_t = 0x00000002;
1150 pub const IGNPAR: crate::tcflag_t = 0x00000004;
1151 pub const PARMRK: crate::tcflag_t = 0x00000008;
1152 pub const INPCK: crate::tcflag_t = 0x00000010;
1153 pub const ISTRIP: crate::tcflag_t = 0x00000020;
1154 pub const INLCR: crate::tcflag_t = 0x00000040;
1155 pub const IGNCR: crate::tcflag_t = 0x00000080;
1156 pub const ICRNL: crate::tcflag_t = 0x00000100;
1157 pub const IXANY: crate::tcflag_t = 0x00000800;
1158 pub const IMAXBEL: crate::tcflag_t = 0x00002000;
1159 pub const OPOST: crate::tcflag_t = 0x1;
1160 pub const CS5: crate::tcflag_t = 0x00000000;
1161 pub const CRTSCTS: crate::tcflag_t = 0x80000000;
1162 pub const ECHO: crate::tcflag_t = 0x00000008;
1163 pub const OCRNL: crate::tcflag_t = 0o000010;
1164 pub const ONOCR: crate::tcflag_t = 0o000020;
1165 pub const ONLRET: crate::tcflag_t = 0o000040;
1166 pub const OFILL: crate::tcflag_t = 0o000100;
1167 pub const OFDEL: crate::tcflag_t = 0o000200;
1168 
1169 pub const CLONE_VM: c_int = 0x100;
1170 pub const CLONE_FS: c_int = 0x200;
1171 pub const CLONE_FILES: c_int = 0x400;
1172 pub const CLONE_SIGHAND: c_int = 0x800;
1173 pub const CLONE_PTRACE: c_int = 0x2000;
1174 pub const CLONE_VFORK: c_int = 0x4000;
1175 pub const CLONE_PARENT: c_int = 0x8000;
1176 pub const CLONE_THREAD: c_int = 0x10000;
1177 pub const CLONE_NEWNS: c_int = 0x20000;
1178 pub const CLONE_SYSVSEM: c_int = 0x40000;
1179 pub const CLONE_SETTLS: c_int = 0x80000;
1180 pub const CLONE_PARENT_SETTID: c_int = 0x100000;
1181 pub const CLONE_CHILD_CLEARTID: c_int = 0x200000;
1182 pub const CLONE_DETACHED: c_int = 0x400000;
1183 pub const CLONE_UNTRACED: c_int = 0x800000;
1184 pub const CLONE_CHILD_SETTID: c_int = 0x01000000;
1185 pub const CLONE_NEWCGROUP: c_int = 0x02000000;
1186 pub const CLONE_NEWUTS: c_int = 0x04000000;
1187 pub const CLONE_NEWIPC: c_int = 0x08000000;
1188 pub const CLONE_NEWUSER: c_int = 0x10000000;
1189 pub const CLONE_NEWPID: c_int = 0x20000000;
1190 pub const CLONE_NEWNET: c_int = 0x40000000;
1191 pub const CLONE_IO: c_int = 0x80000000;
1192 
1193 pub const WNOHANG: c_int = 0x00000001;
1194 pub const WUNTRACED: c_int = 0x00000002;
1195 pub const WSTOPPED: c_int = WUNTRACED;
1196 pub const WEXITED: c_int = 0x00000004;
1197 pub const WCONTINUED: c_int = 0x00000008;
1198 pub const WNOWAIT: c_int = 0x01000000;
1199 
1200 // Options for personality(2).
1201 pub const ADDR_NO_RANDOMIZE: c_int = 0x0040000;
1202 pub const MMAP_PAGE_ZERO: c_int = 0x0100000;
1203 pub const ADDR_COMPAT_LAYOUT: c_int = 0x0200000;
1204 pub const READ_IMPLIES_EXEC: c_int = 0x0400000;
1205 pub const ADDR_LIMIT_32BIT: c_int = 0x0800000;
1206 pub const SHORT_INODE: c_int = 0x1000000;
1207 pub const WHOLE_SECONDS: c_int = 0x2000000;
1208 pub const STICKY_TIMEOUTS: c_int = 0x4000000;
1209 pub const ADDR_LIMIT_3GB: c_int = 0x8000000;
1210 
1211 // Options set using PTRACE_SETOPTIONS.
1212 pub const PTRACE_O_TRACESYSGOOD: c_int = 0x00000001;
1213 pub const PTRACE_O_TRACEFORK: c_int = 0x00000002;
1214 pub const PTRACE_O_TRACEVFORK: c_int = 0x00000004;
1215 pub const PTRACE_O_TRACECLONE: c_int = 0x00000008;
1216 pub const PTRACE_O_TRACEEXEC: c_int = 0x00000010;
1217 pub const PTRACE_O_TRACEVFORKDONE: c_int = 0x00000020;
1218 pub const PTRACE_O_TRACEEXIT: c_int = 0x00000040;
1219 pub const PTRACE_O_TRACESECCOMP: c_int = 0x00000080;
1220 pub const PTRACE_O_SUSPEND_SECCOMP: c_int = 0x00200000;
1221 pub const PTRACE_O_EXITKILL: c_int = 0x00100000;
1222 pub const PTRACE_O_MASK: c_int = 0x003000ff;
1223 
1224 // Wait extended result codes for the above trace options.
1225 pub const PTRACE_EVENT_FORK: c_int = 1;
1226 pub const PTRACE_EVENT_VFORK: c_int = 2;
1227 pub const PTRACE_EVENT_CLONE: c_int = 3;
1228 pub const PTRACE_EVENT_EXEC: c_int = 4;
1229 pub const PTRACE_EVENT_VFORK_DONE: c_int = 5;
1230 pub const PTRACE_EVENT_EXIT: c_int = 6;
1231 pub const PTRACE_EVENT_SECCOMP: c_int = 7;
1232 
1233 pub const __WNOTHREAD: c_int = 0x20000000;
1234 pub const __WALL: c_int = 0x40000000;
1235 pub const __WCLONE: c_int = 0x80000000;
1236 
1237 pub const SPLICE_F_MOVE: c_uint = 0x01;
1238 pub const SPLICE_F_NONBLOCK: c_uint = 0x02;
1239 pub const SPLICE_F_MORE: c_uint = 0x04;
1240 pub const SPLICE_F_GIFT: c_uint = 0x08;
1241 
1242 pub const RTLD_LOCAL: c_int = 0;
1243 pub const RTLD_LAZY: c_int = 1;
1244 
1245 pub const POSIX_FADV_NORMAL: c_int = 0;
1246 pub const POSIX_FADV_RANDOM: c_int = 1;
1247 pub const POSIX_FADV_SEQUENTIAL: c_int = 2;
1248 pub const POSIX_FADV_WILLNEED: c_int = 3;
1249 
1250 pub const AT_FDCWD: c_int = -100;
1251 pub const AT_SYMLINK_NOFOLLOW: c_int = 0x100;
1252 pub const AT_REMOVEDIR: c_int = 0x200;
1253 pub const AT_SYMLINK_FOLLOW: c_int = 0x400;
1254 pub const AT_NO_AUTOMOUNT: c_int = 0x800;
1255 pub const AT_EMPTY_PATH: c_int = 0x1000;
1256 pub const AT_RECURSIVE: c_int = 0x8000;
1257 
1258 pub const LOG_CRON: c_int = 9 << 3;
1259 pub const LOG_AUTHPRIV: c_int = 10 << 3;
1260 pub const LOG_FTP: c_int = 11 << 3;
1261 pub const LOG_PERROR: c_int = 0x20;
1262 
1263 pub const PIPE_BUF: usize = 4096;
1264 
1265 pub const SI_LOAD_SHIFT: c_uint = 16;
1266 
1267 // si_code values
1268 pub const SI_USER: c_int = 0;
1269 pub const SI_KERNEL: c_int = 0x80;
1270 pub const SI_QUEUE: c_int = -1;
1271 cfg_if! {
1272     if #[cfg(not(any(target_arch = "mips", target_arch = "mips32r6")))] {
1273         pub const SI_TIMER: c_int = -2;
1274         pub const SI_MESGQ: c_int = -3;
1275         pub const SI_ASYNCIO: c_int = -4;
1276     } else {
1277         pub const SI_TIMER: c_int = -3;
1278         pub const SI_MESGQ: c_int = -4;
1279         pub const SI_ASYNCIO: c_int = -2;
1280     }
1281 }
1282 pub const SI_SIGIO: c_int = -5;
1283 pub const SI_TKILL: c_int = -6;
1284 pub const SI_ASYNCNL: c_int = -60;
1285 
1286 // si_code values for SIGBUS signal
1287 pub const BUS_ADRALN: c_int = 1;
1288 pub const BUS_ADRERR: c_int = 2;
1289 pub const BUS_OBJERR: c_int = 3;
1290 // Linux-specific si_code values for SIGBUS signal
1291 pub const BUS_MCEERR_AR: c_int = 4;
1292 pub const BUS_MCEERR_AO: c_int = 5;
1293 
1294 // si_code values for SIGTRAP
1295 pub const TRAP_BRKPT: c_int = 1;
1296 pub const TRAP_TRACE: c_int = 2;
1297 pub const TRAP_BRANCH: c_int = 3;
1298 pub const TRAP_HWBKPT: c_int = 4;
1299 pub const TRAP_UNK: c_int = 5;
1300 
1301 // si_code values for SIGCHLD signal
1302 pub const CLD_EXITED: c_int = 1;
1303 pub const CLD_KILLED: c_int = 2;
1304 pub const CLD_DUMPED: c_int = 3;
1305 pub const CLD_TRAPPED: c_int = 4;
1306 pub const CLD_STOPPED: c_int = 5;
1307 pub const CLD_CONTINUED: c_int = 6;
1308 
1309 pub const SIGEV_SIGNAL: c_int = 0;
1310 pub const SIGEV_NONE: c_int = 1;
1311 pub const SIGEV_THREAD: c_int = 2;
1312 
1313 pub const P_ALL: idtype_t = 0;
1314 pub const P_PID: idtype_t = 1;
1315 pub const P_PGID: idtype_t = 2;
1316 cfg_if! {
1317     if #[cfg(not(target_os = "emscripten"))] {
1318         pub const P_PIDFD: idtype_t = 3;
1319     }
1320 }
1321 
1322 pub const UTIME_OMIT: c_long = 1073741822;
1323 pub const UTIME_NOW: c_long = 1073741823;
1324 
1325 pub const POLLIN: c_short = 0x1;
1326 pub const POLLPRI: c_short = 0x2;
1327 pub const POLLOUT: c_short = 0x4;
1328 pub const POLLERR: c_short = 0x8;
1329 pub const POLLHUP: c_short = 0x10;
1330 pub const POLLNVAL: c_short = 0x20;
1331 pub const POLLRDNORM: c_short = 0x040;
1332 pub const POLLRDBAND: c_short = 0x080;
1333 #[cfg(not(any(target_arch = "sparc", target_arch = "sparc64")))]
1334 pub const POLLRDHUP: c_short = 0x2000;
1335 #[cfg(any(target_arch = "sparc", target_arch = "sparc64"))]
1336 pub const POLLRDHUP: c_short = 0x800;
1337 
1338 pub const IPTOS_LOWDELAY: u8 = 0x10;
1339 pub const IPTOS_THROUGHPUT: u8 = 0x08;
1340 pub const IPTOS_RELIABILITY: u8 = 0x04;
1341 pub const IPTOS_MINCOST: u8 = 0x02;
1342 
1343 pub const IPTOS_PREC_NETCONTROL: u8 = 0xe0;
1344 pub const IPTOS_PREC_INTERNETCONTROL: u8 = 0xc0;
1345 pub const IPTOS_PREC_CRITIC_ECP: u8 = 0xa0;
1346 pub const IPTOS_PREC_FLASHOVERRIDE: u8 = 0x80;
1347 pub const IPTOS_PREC_FLASH: u8 = 0x60;
1348 pub const IPTOS_PREC_IMMEDIATE: u8 = 0x40;
1349 pub const IPTOS_PREC_PRIORITY: u8 = 0x20;
1350 pub const IPTOS_PREC_ROUTINE: u8 = 0x00;
1351 
1352 pub const IPTOS_ECN_MASK: u8 = 0x03;
1353 pub const IPTOS_ECN_ECT1: u8 = 0x01;
1354 pub const IPTOS_ECN_ECT0: u8 = 0x02;
1355 pub const IPTOS_ECN_CE: u8 = 0x03;
1356 
1357 pub const IPOPT_COPY: u8 = 0x80;
1358 pub const IPOPT_CLASS_MASK: u8 = 0x60;
1359 pub const IPOPT_NUMBER_MASK: u8 = 0x1f;
1360 
1361 pub const IPOPT_CONTROL: u8 = 0x00;
1362 pub const IPOPT_RESERVED1: u8 = 0x20;
1363 pub const IPOPT_MEASUREMENT: u8 = 0x40;
1364 pub const IPOPT_RESERVED2: u8 = 0x60;
1365 pub const IPOPT_END: u8 = 0 | IPOPT_CONTROL;
1366 pub const IPOPT_NOOP: u8 = 1 | IPOPT_CONTROL;
1367 pub const IPOPT_SEC: u8 = 2 | IPOPT_CONTROL | IPOPT_COPY;
1368 pub const IPOPT_LSRR: u8 = 3 | IPOPT_CONTROL | IPOPT_COPY;
1369 pub const IPOPT_TIMESTAMP: u8 = 4 | IPOPT_MEASUREMENT;
1370 pub const IPOPT_RR: u8 = 7 | IPOPT_CONTROL;
1371 pub const IPOPT_SID: u8 = 8 | IPOPT_CONTROL | IPOPT_COPY;
1372 pub const IPOPT_SSRR: u8 = 9 | IPOPT_CONTROL | IPOPT_COPY;
1373 pub const IPOPT_RA: u8 = 20 | IPOPT_CONTROL | IPOPT_COPY;
1374 pub const IPVERSION: u8 = 4;
1375 pub const MAXTTL: u8 = 255;
1376 pub const IPDEFTTL: u8 = 64;
1377 pub const IPOPT_OPTVAL: u8 = 0;
1378 pub const IPOPT_OLEN: u8 = 1;
1379 pub const IPOPT_OFFSET: u8 = 2;
1380 pub const IPOPT_MINOFF: u8 = 4;
1381 pub const MAX_IPOPTLEN: u8 = 40;
1382 pub const IPOPT_NOP: u8 = IPOPT_NOOP;
1383 pub const IPOPT_EOL: u8 = IPOPT_END;
1384 pub const IPOPT_TS: u8 = IPOPT_TIMESTAMP;
1385 pub const IPOPT_TS_TSONLY: u8 = 0;
1386 pub const IPOPT_TS_TSANDADDR: u8 = 1;
1387 pub const IPOPT_TS_PRESPEC: u8 = 3;
1388 
1389 pub const ARPOP_RREQUEST: u16 = 3;
1390 pub const ARPOP_RREPLY: u16 = 4;
1391 pub const ARPOP_InREQUEST: u16 = 8;
1392 pub const ARPOP_InREPLY: u16 = 9;
1393 pub const ARPOP_NAK: u16 = 10;
1394 
1395 pub const ATF_NETMASK: c_int = 0x20;
1396 pub const ATF_DONTPUB: c_int = 0x40;
1397 
1398 pub const ARPHRD_NETROM: u16 = 0;
1399 pub const ARPHRD_ETHER: u16 = 1;
1400 pub const ARPHRD_EETHER: u16 = 2;
1401 pub const ARPHRD_AX25: u16 = 3;
1402 pub const ARPHRD_PRONET: u16 = 4;
1403 pub const ARPHRD_CHAOS: u16 = 5;
1404 pub const ARPHRD_IEEE802: u16 = 6;
1405 pub const ARPHRD_ARCNET: u16 = 7;
1406 pub const ARPHRD_APPLETLK: u16 = 8;
1407 pub const ARPHRD_DLCI: u16 = 15;
1408 pub const ARPHRD_ATM: u16 = 19;
1409 pub const ARPHRD_METRICOM: u16 = 23;
1410 pub const ARPHRD_IEEE1394: u16 = 24;
1411 pub const ARPHRD_EUI64: u16 = 27;
1412 pub const ARPHRD_INFINIBAND: u16 = 32;
1413 
1414 pub const ARPHRD_SLIP: u16 = 256;
1415 pub const ARPHRD_CSLIP: u16 = 257;
1416 pub const ARPHRD_SLIP6: u16 = 258;
1417 pub const ARPHRD_CSLIP6: u16 = 259;
1418 pub const ARPHRD_RSRVD: u16 = 260;
1419 pub const ARPHRD_ADAPT: u16 = 264;
1420 pub const ARPHRD_ROSE: u16 = 270;
1421 pub const ARPHRD_X25: u16 = 271;
1422 pub const ARPHRD_HWX25: u16 = 272;
1423 pub const ARPHRD_CAN: u16 = 280;
1424 pub const ARPHRD_PPP: u16 = 512;
1425 pub const ARPHRD_CISCO: u16 = 513;
1426 pub const ARPHRD_HDLC: u16 = ARPHRD_CISCO;
1427 pub const ARPHRD_LAPB: u16 = 516;
1428 pub const ARPHRD_DDCMP: u16 = 517;
1429 pub const ARPHRD_RAWHDLC: u16 = 518;
1430 
1431 pub const ARPHRD_TUNNEL: u16 = 768;
1432 pub const ARPHRD_TUNNEL6: u16 = 769;
1433 pub const ARPHRD_FRAD: u16 = 770;
1434 pub const ARPHRD_SKIP: u16 = 771;
1435 pub const ARPHRD_LOOPBACK: u16 = 772;
1436 pub const ARPHRD_LOCALTLK: u16 = 773;
1437 pub const ARPHRD_FDDI: u16 = 774;
1438 pub const ARPHRD_BIF: u16 = 775;
1439 pub const ARPHRD_SIT: u16 = 776;
1440 pub const ARPHRD_IPDDP: u16 = 777;
1441 pub const ARPHRD_IPGRE: u16 = 778;
1442 pub const ARPHRD_PIMREG: u16 = 779;
1443 pub const ARPHRD_HIPPI: u16 = 780;
1444 pub const ARPHRD_ASH: u16 = 781;
1445 pub const ARPHRD_ECONET: u16 = 782;
1446 pub const ARPHRD_IRDA: u16 = 783;
1447 pub const ARPHRD_FCPP: u16 = 784;
1448 pub const ARPHRD_FCAL: u16 = 785;
1449 pub const ARPHRD_FCPL: u16 = 786;
1450 pub const ARPHRD_FCFABRIC: u16 = 787;
1451 pub const ARPHRD_IEEE802_TR: u16 = 800;
1452 pub const ARPHRD_IEEE80211: u16 = 801;
1453 pub const ARPHRD_IEEE80211_PRISM: u16 = 802;
1454 pub const ARPHRD_IEEE80211_RADIOTAP: u16 = 803;
1455 pub const ARPHRD_IEEE802154: u16 = 804;
1456 
1457 pub const ARPHRD_VOID: u16 = 0xFFFF;
1458 pub const ARPHRD_NONE: u16 = 0xFFFE;
1459 
1460 cfg_if! {
1461     if #[cfg(not(target_os = "emscripten"))] {
1462         // linux/if_tun.h
1463         /* TUNSETIFF ifr flags */
1464         pub const IFF_TUN: c_int = 0x0001;
1465         pub const IFF_TAP: c_int = 0x0002;
1466         pub const IFF_NAPI: c_int = 0x0010;
1467         pub const IFF_NAPI_FRAGS: c_int = 0x0020;
1468         // Used in TUNSETIFF to bring up tun/tap without carrier
1469         pub const IFF_NO_CARRIER: c_int = 0x0040;
1470         pub const IFF_NO_PI: c_int = 0x1000;
1471         // Read queue size
1472         pub const TUN_READQ_SIZE: c_short = 500;
1473         // TUN device type flags: deprecated. Use IFF_TUN/IFF_TAP instead.
1474         pub const TUN_TUN_DEV: c_short = crate::IFF_TUN as c_short;
1475         pub const TUN_TAP_DEV: c_short = crate::IFF_TAP as c_short;
1476         pub const TUN_TYPE_MASK: c_short = 0x000f;
1477         // This flag has no real effect
1478         pub const IFF_ONE_QUEUE: c_int = 0x2000;
1479         pub const IFF_VNET_HDR: c_int = 0x4000;
1480         pub const IFF_TUN_EXCL: c_int = 0x8000;
1481         pub const IFF_MULTI_QUEUE: c_int = 0x0100;
1482         pub const IFF_ATTACH_QUEUE: c_int = 0x0200;
1483         pub const IFF_DETACH_QUEUE: c_int = 0x0400;
1484         // read-only flag
1485         pub const IFF_PERSIST: c_int = 0x0800;
1486         pub const IFF_NOFILTER: c_int = 0x1000;
1487         // Socket options
1488         pub const TUN_TX_TIMESTAMP: c_int = 1;
1489         // Features for GSO (TUNSETOFFLOAD)
1490         pub const TUN_F_CSUM: c_uint = 0x01;
1491         pub const TUN_F_TSO4: c_uint = 0x02;
1492         pub const TUN_F_TSO6: c_uint = 0x04;
1493         pub const TUN_F_TSO_ECN: c_uint = 0x08;
1494         pub const TUN_F_UFO: c_uint = 0x10;
1495         pub const TUN_F_USO4: c_uint = 0x20;
1496         pub const TUN_F_USO6: c_uint = 0x40;
1497         // Protocol info prepended to the packets (when IFF_NO_PI is not set)
1498         pub const TUN_PKT_STRIP: c_int = 0x0001;
1499         // Accept all multicast packets
1500         pub const TUN_FLT_ALLMULTI: c_int = 0x0001;
1501         // Ioctl operation codes
1502         const T_TYPE: u32 = b'T' as u32;
1503         pub const TUNSETNOCSUM: Ioctl = _IOW::<c_int>(T_TYPE, 200);
1504         pub const TUNSETDEBUG: Ioctl = _IOW::<c_int>(T_TYPE, 201);
1505         pub const TUNSETIFF: Ioctl = _IOW::<c_int>(T_TYPE, 202);
1506         pub const TUNSETPERSIST: Ioctl = _IOW::<c_int>(T_TYPE, 203);
1507         pub const TUNSETOWNER: Ioctl = _IOW::<c_int>(T_TYPE, 204);
1508         pub const TUNSETLINK: Ioctl = _IOW::<c_int>(T_TYPE, 205);
1509         pub const TUNSETGROUP: Ioctl = _IOW::<c_int>(T_TYPE, 206);
1510         pub const TUNGETFEATURES: Ioctl = _IOR::<c_int>(T_TYPE, 207);
1511         pub const TUNSETOFFLOAD: Ioctl = _IOW::<c_int>(T_TYPE, 208);
1512         pub const TUNSETTXFILTER: Ioctl = _IOW::<c_int>(T_TYPE, 209);
1513         pub const TUNGETIFF: Ioctl = _IOR::<c_int>(T_TYPE, 210);
1514         pub const TUNGETSNDBUF: Ioctl = _IOR::<c_int>(T_TYPE, 211);
1515         pub const TUNSETSNDBUF: Ioctl = _IOW::<c_int>(T_TYPE, 212);
1516         pub const TUNATTACHFILTER: Ioctl = _IOW::<sock_fprog>(T_TYPE, 213);
1517         pub const TUNDETACHFILTER: Ioctl = _IOW::<sock_fprog>(T_TYPE, 214);
1518         pub const TUNGETVNETHDRSZ: Ioctl = _IOR::<c_int>(T_TYPE, 215);
1519         pub const TUNSETVNETHDRSZ: Ioctl = _IOW::<c_int>(T_TYPE, 216);
1520         pub const TUNSETQUEUE: Ioctl = _IOW::<c_int>(T_TYPE, 217);
1521         pub const TUNSETIFINDEX: Ioctl = _IOW::<c_int>(T_TYPE, 218);
1522         pub const TUNGETFILTER: Ioctl = _IOR::<sock_fprog>(T_TYPE, 219);
1523         pub const TUNSETVNETLE: Ioctl = _IOW::<c_int>(T_TYPE, 220);
1524         pub const TUNGETVNETLE: Ioctl = _IOR::<c_int>(T_TYPE, 221);
1525         pub const TUNSETVNETBE: Ioctl = _IOW::<c_int>(T_TYPE, 222);
1526         pub const TUNGETVNETBE: Ioctl = _IOR::<c_int>(T_TYPE, 223);
1527         pub const TUNSETSTEERINGEBPF: Ioctl = _IOR::<c_int>(T_TYPE, 224);
1528         pub const TUNSETFILTEREBPF: Ioctl = _IOR::<c_int>(T_TYPE, 225);
1529         pub const TUNSETCARRIER: Ioctl = _IOW::<c_int>(T_TYPE, 226);
1530         pub const TUNGETDEVNETNS: Ioctl = _IO(T_TYPE, 227);
1531 
1532         // linux/fs.h
1533         pub const FS_IOC_GETFLAGS: Ioctl = _IOR::<c_long>('f' as u32, 1);
1534         pub const FS_IOC_SETFLAGS: Ioctl = _IOW::<c_long>('f' as u32, 2);
1535         pub const FS_IOC_GETVERSION: Ioctl = _IOR::<c_long>('v' as u32, 1);
1536         pub const FS_IOC_SETVERSION: Ioctl = _IOW::<c_long>('v' as u32, 2);
1537         pub const FS_IOC32_GETFLAGS: Ioctl = _IOR::<c_int>('f' as u32, 1);
1538         pub const FS_IOC32_SETFLAGS: Ioctl = _IOW::<c_int>('f' as u32, 2);
1539         pub const FS_IOC32_GETVERSION: Ioctl = _IOR::<c_int>('v' as u32, 1);
1540         pub const FS_IOC32_SETVERSION: Ioctl = _IOW::<c_int>('v' as u32, 2);
1541 
1542         pub const FICLONE: Ioctl = _IOW::<c_int>(0x94, 9);
1543         pub const FICLONERANGE: Ioctl = _IOW::<crate::file_clone_range>(0x94, 13);
1544     }
1545 }
1546 
1547 cfg_if! {
1548     if #[cfg(target_os = "emscripten")] {
1549         // Emscripten does not define any `*_SUPER_MAGIC` constants.
1550     } else if #[cfg(not(target_arch = "s390x"))] {
1551         pub const ADFS_SUPER_MAGIC: c_long = 0x0000adf5;
1552         pub const AFFS_SUPER_MAGIC: c_long = 0x0000adff;
1553         pub const AFS_SUPER_MAGIC: c_long = 0x5346414f;
1554         pub const AUTOFS_SUPER_MAGIC: c_long = 0x0187;
1555         pub const BPF_FS_MAGIC: c_long = 0xcafe4a11;
1556         pub const BTRFS_SUPER_MAGIC: c_long = 0x9123683e;
1557         pub const CGROUP2_SUPER_MAGIC: c_long = 0x63677270;
1558         pub const CGROUP_SUPER_MAGIC: c_long = 0x27e0eb;
1559         pub const CODA_SUPER_MAGIC: c_long = 0x73757245;
1560         pub const CRAMFS_MAGIC: c_long = 0x28cd3d45;
1561         pub const DEBUGFS_MAGIC: c_long = 0x64626720;
1562         pub const DEVPTS_SUPER_MAGIC: c_long = 0x1cd1;
1563         pub const ECRYPTFS_SUPER_MAGIC: c_long = 0xf15f;
1564         pub const EFS_SUPER_MAGIC: c_long = 0x00414a53;
1565         pub const EXT2_SUPER_MAGIC: c_long = 0x0000ef53;
1566         pub const EXT3_SUPER_MAGIC: c_long = 0x0000ef53;
1567         pub const EXT4_SUPER_MAGIC: c_long = 0x0000ef53;
1568         pub const F2FS_SUPER_MAGIC: c_long = 0xf2f52010;
1569         pub const FUSE_SUPER_MAGIC: c_long = 0x65735546;
1570         pub const FUTEXFS_SUPER_MAGIC: c_long = 0xbad1dea;
1571         pub const HOSTFS_SUPER_MAGIC: c_long = 0x00c0ffee;
1572         pub const HPFS_SUPER_MAGIC: c_long = 0xf995e849;
1573         pub const HUGETLBFS_MAGIC: c_long = 0x958458f6;
1574         pub const ISOFS_SUPER_MAGIC: c_long = 0x00009660;
1575         pub const JFFS2_SUPER_MAGIC: c_long = 0x000072b6;
1576         pub const MINIX2_SUPER_MAGIC2: c_long = 0x00002478;
1577         pub const MINIX2_SUPER_MAGIC: c_long = 0x00002468;
1578         pub const MINIX3_SUPER_MAGIC: c_long = 0x4d5a;
1579         pub const MINIX_SUPER_MAGIC2: c_long = 0x0000138f;
1580         pub const MINIX_SUPER_MAGIC: c_long = 0x0000137f;
1581         pub const MSDOS_SUPER_MAGIC: c_long = 0x00004d44;
1582         pub const NCP_SUPER_MAGIC: c_long = 0x0000564c;
1583         pub const NFS_SUPER_MAGIC: c_long = 0x00006969;
1584         pub const NILFS_SUPER_MAGIC: c_long = 0x3434;
1585         pub const OCFS2_SUPER_MAGIC: c_long = 0x7461636f;
1586         pub const OPENPROM_SUPER_MAGIC: c_long = 0x00009fa1;
1587         pub const OVERLAYFS_SUPER_MAGIC: c_long = 0x794c7630;
1588         pub const PROC_SUPER_MAGIC: c_long = 0x00009fa0;
1589         pub const QNX4_SUPER_MAGIC: c_long = 0x0000002f;
1590         pub const QNX6_SUPER_MAGIC: c_long = 0x68191122;
1591         pub const RDTGROUP_SUPER_MAGIC: c_long = 0x7655821;
1592         pub const REISERFS_SUPER_MAGIC: c_long = 0x52654973;
1593         pub const SECURITYFS_MAGIC: c_long = 0x73636673;
1594         pub const SELINUX_MAGIC: c_long = 0xf97cff8c;
1595         pub const SMACK_MAGIC: c_long = 0x43415d53;
1596         pub const SMB_SUPER_MAGIC: c_long = 0x0000517b;
1597         pub const SYSFS_MAGIC: c_long = 0x62656572;
1598         pub const TMPFS_MAGIC: c_long = 0x01021994;
1599         pub const TRACEFS_MAGIC: c_long = 0x74726163;
1600         pub const UDF_SUPER_MAGIC: c_long = 0x15013346;
1601         pub const USBDEVICE_SUPER_MAGIC: c_long = 0x00009fa2;
1602         pub const XENFS_SUPER_MAGIC: c_long = 0xabba1974;
1603         pub const NSFS_MAGIC: c_long = 0x6e736673;
1604     } else if #[cfg(target_arch = "s390x")] {
1605         pub const ADFS_SUPER_MAGIC: c_uint = 0x0000adf5;
1606         pub const AFFS_SUPER_MAGIC: c_uint = 0x0000adff;
1607         pub const AFS_SUPER_MAGIC: c_uint = 0x5346414f;
1608         pub const AUTOFS_SUPER_MAGIC: c_uint = 0x0187;
1609         pub const BPF_FS_MAGIC: c_uint = 0xcafe4a11;
1610         pub const BTRFS_SUPER_MAGIC: c_uint = 0x9123683e;
1611         pub const CGROUP2_SUPER_MAGIC: c_uint = 0x63677270;
1612         pub const CGROUP_SUPER_MAGIC: c_uint = 0x27e0eb;
1613         pub const CODA_SUPER_MAGIC: c_uint = 0x73757245;
1614         pub const CRAMFS_MAGIC: c_uint = 0x28cd3d45;
1615         pub const DEBUGFS_MAGIC: c_uint = 0x64626720;
1616         pub const DEVPTS_SUPER_MAGIC: c_uint = 0x1cd1;
1617         pub const ECRYPTFS_SUPER_MAGIC: c_uint = 0xf15f;
1618         pub const EFS_SUPER_MAGIC: c_uint = 0x00414a53;
1619         pub const EXT2_SUPER_MAGIC: c_uint = 0x0000ef53;
1620         pub const EXT3_SUPER_MAGIC: c_uint = 0x0000ef53;
1621         pub const EXT4_SUPER_MAGIC: c_uint = 0x0000ef53;
1622         pub const F2FS_SUPER_MAGIC: c_uint = 0xf2f52010;
1623         pub const FUSE_SUPER_MAGIC: c_uint = 0x65735546;
1624         pub const FUTEXFS_SUPER_MAGIC: c_uint = 0xbad1dea;
1625         pub const HOSTFS_SUPER_MAGIC: c_uint = 0x00c0ffee;
1626         pub const HPFS_SUPER_MAGIC: c_uint = 0xf995e849;
1627         pub const HUGETLBFS_MAGIC: c_uint = 0x958458f6;
1628         pub const ISOFS_SUPER_MAGIC: c_uint = 0x00009660;
1629         pub const JFFS2_SUPER_MAGIC: c_uint = 0x000072b6;
1630         pub const MINIX2_SUPER_MAGIC2: c_uint = 0x00002478;
1631         pub const MINIX2_SUPER_MAGIC: c_uint = 0x00002468;
1632         pub const MINIX3_SUPER_MAGIC: c_uint = 0x4d5a;
1633         pub const MINIX_SUPER_MAGIC2: c_uint = 0x0000138f;
1634         pub const MINIX_SUPER_MAGIC: c_uint = 0x0000137f;
1635         pub const MSDOS_SUPER_MAGIC: c_uint = 0x00004d44;
1636         pub const NCP_SUPER_MAGIC: c_uint = 0x0000564c;
1637         pub const NFS_SUPER_MAGIC: c_uint = 0x00006969;
1638         pub const NILFS_SUPER_MAGIC: c_uint = 0x3434;
1639         pub const OCFS2_SUPER_MAGIC: c_uint = 0x7461636f;
1640         pub const OPENPROM_SUPER_MAGIC: c_uint = 0x00009fa1;
1641         pub const OVERLAYFS_SUPER_MAGIC: c_uint = 0x794c7630;
1642         pub const PROC_SUPER_MAGIC: c_uint = 0x00009fa0;
1643         pub const QNX4_SUPER_MAGIC: c_uint = 0x0000002f;
1644         pub const QNX6_SUPER_MAGIC: c_uint = 0x68191122;
1645         pub const RDTGROUP_SUPER_MAGIC: c_uint = 0x7655821;
1646         pub const REISERFS_SUPER_MAGIC: c_uint = 0x52654973;
1647         pub const SECURITYFS_MAGIC: c_uint = 0x73636673;
1648         pub const SELINUX_MAGIC: c_uint = 0xf97cff8c;
1649         pub const SMACK_MAGIC: c_uint = 0x43415d53;
1650         pub const SMB_SUPER_MAGIC: c_uint = 0x0000517b;
1651         pub const SYSFS_MAGIC: c_uint = 0x62656572;
1652         pub const TMPFS_MAGIC: c_uint = 0x01021994;
1653         pub const TRACEFS_MAGIC: c_uint = 0x74726163;
1654         pub const UDF_SUPER_MAGIC: c_uint = 0x15013346;
1655         pub const USBDEVICE_SUPER_MAGIC: c_uint = 0x00009fa2;
1656         pub const XENFS_SUPER_MAGIC: c_uint = 0xabba1974;
1657         pub const NSFS_MAGIC: c_uint = 0x6e736673;
1658     }
1659 }
1660 
1661 cfg_if! {
1662     if #[cfg(any(target_env = "gnu", target_os = "android"))] {
1663         pub const AT_STATX_SYNC_TYPE: c_int = 0x6000;
1664         pub const AT_STATX_SYNC_AS_STAT: c_int = 0x0000;
1665         pub const AT_STATX_FORCE_SYNC: c_int = 0x2000;
1666         pub const AT_STATX_DONT_SYNC: c_int = 0x4000;
1667         pub const STATX_TYPE: c_uint = 0x0001;
1668         pub const STATX_MODE: c_uint = 0x0002;
1669         pub const STATX_NLINK: c_uint = 0x0004;
1670         pub const STATX_UID: c_uint = 0x0008;
1671         pub const STATX_GID: c_uint = 0x0010;
1672         pub const STATX_ATIME: c_uint = 0x0020;
1673         pub const STATX_MTIME: c_uint = 0x0040;
1674         pub const STATX_CTIME: c_uint = 0x0080;
1675         pub const STATX_INO: c_uint = 0x0100;
1676         pub const STATX_SIZE: c_uint = 0x0200;
1677         pub const STATX_BLOCKS: c_uint = 0x0400;
1678         pub const STATX_BASIC_STATS: c_uint = 0x07ff;
1679         pub const STATX_BTIME: c_uint = 0x0800;
1680         pub const STATX_ALL: c_uint = 0x0fff;
1681         pub const STATX_MNT_ID: c_uint = 0x1000;
1682         pub const STATX_DIOALIGN: c_uint = 0x2000;
1683         pub const STATX__RESERVED: c_int = 0x80000000;
1684         pub const STATX_ATTR_COMPRESSED: c_int = 0x0004;
1685         pub const STATX_ATTR_IMMUTABLE: c_int = 0x0010;
1686         pub const STATX_ATTR_APPEND: c_int = 0x0020;
1687         pub const STATX_ATTR_NODUMP: c_int = 0x0040;
1688         pub const STATX_ATTR_ENCRYPTED: c_int = 0x0800;
1689         pub const STATX_ATTR_AUTOMOUNT: c_int = 0x1000;
1690         pub const STATX_ATTR_MOUNT_ROOT: c_int = 0x2000;
1691         pub const STATX_ATTR_VERITY: c_int = 0x100000;
1692         pub const STATX_ATTR_DAX: c_int = 0x200000;
1693     }
1694 }
1695 
1696 // https://github.com/search?q=repo%3Atorvalds%2Flinux+%22%23define+_IOC_NONE%22&type=code
1697 cfg_if! {
1698     if #[cfg(not(target_os = "emscripten"))] {
1699         const _IOC_NRBITS: u32 = 8;
1700         const _IOC_TYPEBITS: u32 = 8;
1701 
1702         cfg_if! {
1703             if #[cfg(any(
1704                 any(target_arch = "powerpc", target_arch = "powerpc64"),
1705                 any(target_arch = "sparc", target_arch = "sparc64"),
1706                 any(target_arch = "mips", target_arch = "mips64"),
1707             ))] {
1708                 // https://github.com/torvalds/linux/blob/b311c1b497e51a628aa89e7cb954481e5f9dced2/arch/powerpc/include/uapi/asm/ioctl.h
1709                 // https://github.com/torvalds/linux/blob/b311c1b497e51a628aa89e7cb954481e5f9dced2/arch/sparc/include/uapi/asm/ioctl.h
1710                 // https://github.com/torvalds/linux/blob/b311c1b497e51a628aa89e7cb954481e5f9dced2/arch/mips/include/uapi/asm/ioctl.h
1711 
1712                 const _IOC_SIZEBITS: u32 = 13;
1713                 const _IOC_DIRBITS: u32 = 3;
1714 
1715                 const _IOC_NONE: u32 = 1;
1716                 const _IOC_READ: u32 = 2;
1717                 const _IOC_WRITE: u32 = 4;
1718             } else {
1719                 // https://github.com/torvalds/linux/blob/b311c1b497e51a628aa89e7cb954481e5f9dced2/include/uapi/asm-generic/ioctl.h
1720 
1721                 const _IOC_SIZEBITS: u32 = 14;
1722                 const _IOC_DIRBITS: u32 = 2;
1723 
1724                 const _IOC_NONE: u32 = 0;
1725                 const _IOC_WRITE: u32 = 1;
1726                 const _IOC_READ: u32 = 2;
1727             }
1728         }
1729         const _IOC_NRMASK: u32 = (1 << _IOC_NRBITS) - 1;
1730         const _IOC_TYPEMASK: u32 = (1 << _IOC_TYPEBITS) - 1;
1731         const _IOC_SIZEMASK: u32 = (1 << _IOC_SIZEBITS) - 1;
1732         const _IOC_DIRMASK: u32 = (1 << _IOC_DIRBITS) - 1;
1733 
1734         const _IOC_NRSHIFT: u32 = 0;
1735         const _IOC_TYPESHIFT: u32 = _IOC_NRSHIFT + _IOC_NRBITS;
1736         const _IOC_SIZESHIFT: u32 = _IOC_TYPESHIFT + _IOC_TYPEBITS;
1737         const _IOC_DIRSHIFT: u32 = _IOC_SIZESHIFT + _IOC_SIZEBITS;
1738 
1739         // adapted from https://github.com/torvalds/linux/blob/8a696a29c6905594e4abf78eaafcb62165ac61f1/rust/kernel/ioctl.rs
1740 
1741         /// Build an ioctl number, analogous to the C macro of the same name.
1742         const fn _IOC(dir: u32, ty: u32, nr: u32, size: usize) -> Ioctl {
1743             // FIXME(ctest) the `garando_syntax` crate (used by ctest in the CI test suite)
1744             // cannot currently parse these `debug_assert!`s
1745             //
1746             // debug_assert!(dir <= _IOC_DIRMASK);
1747             // debug_assert!(ty <= _IOC_TYPEMASK);
1748             // debug_assert!(nr <= _IOC_NRMASK);
1749             // debug_assert!(size <= (_IOC_SIZEMASK as usize));
1750 
1751             ((dir << _IOC_DIRSHIFT)
1752                 | (ty << _IOC_TYPESHIFT)
1753                 | (nr << _IOC_NRSHIFT)
1754                 | ((size as u32) << _IOC_SIZESHIFT)) as Ioctl
1755         }
1756 
1757         /// Build an ioctl number for an argumentless ioctl.
1758         pub const fn _IO(ty: u32, nr: u32) -> Ioctl {
1759             _IOC(_IOC_NONE, ty, nr, 0)
1760         }
1761 
1762         /// Build an ioctl number for an read-only ioctl.
1763         pub const fn _IOR<T>(ty: u32, nr: u32) -> Ioctl {
1764             _IOC(_IOC_READ, ty, nr, mem::size_of::<T>())
1765         }
1766 
1767         /// Build an ioctl number for an write-only ioctl.
1768         pub const fn _IOW<T>(ty: u32, nr: u32) -> Ioctl {
1769             _IOC(_IOC_WRITE, ty, nr, mem::size_of::<T>())
1770         }
1771 
1772         /// Build an ioctl number for a read-write ioctl.
1773         pub const fn _IOWR<T>(ty: u32, nr: u32) -> Ioctl {
1774             _IOC(_IOC_READ | _IOC_WRITE, ty, nr, mem::size_of::<T>())
1775         }
1776 
1777         extern "C" {
1778             #[cfg_attr(gnu_time_bits64, link_name = "__ioctl_time64")]
1779             pub fn ioctl(fd: c_int, request: Ioctl, ...) -> c_int;
1780         }
1781     }
1782 }
1783 
1784 const_fn! {
1785     {const} fn CMSG_ALIGN(len: usize) -> usize {
1786         (len + mem::size_of::<usize>() - 1) & !(mem::size_of::<usize>() - 1)
1787     }
1788 }
1789 
1790 f! {
1791     pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr {
1792         if (*mhdr).msg_controllen as usize >= mem::size_of::<cmsghdr>() {
1793             (*mhdr).msg_control.cast::<cmsghdr>()
1794         } else {
1795             core::ptr::null_mut::<cmsghdr>()
1796         }
1797     }
1798 
1799     pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
1800         cmsg.offset(1) as *mut c_uchar
1801     }
1802 
1803     pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint {
1804         (CMSG_ALIGN(length as usize) + CMSG_ALIGN(mem::size_of::<cmsghdr>())) as c_uint
1805     }
1806 
1807     pub {const} fn CMSG_LEN(length: c_uint) -> c_uint {
1808         CMSG_ALIGN(mem::size_of::<cmsghdr>()) as c_uint + length
1809     }
1810 
1811     pub fn FD_CLR(fd: c_int, set: *mut fd_set) -> () {
1812         let fd = fd as usize;
1813         let size = mem::size_of_val(&(*set).fds_bits[0]) * 8;
1814         (*set).fds_bits[fd / size] &= !(1 << (fd % size));
1815         return;
1816     }
1817 
1818     pub fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool {
1819         let fd = fd as usize;
1820         let size = mem::size_of_val(&(*set).fds_bits[0]) * 8;
1821         return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0;
1822     }
1823 
1824     pub fn FD_SET(fd: c_int, set: *mut fd_set) -> () {
1825         let fd = fd as usize;
1826         let size = mem::size_of_val(&(*set).fds_bits[0]) * 8;
1827         (*set).fds_bits[fd / size] |= 1 << (fd % size);
1828         return;
1829     }
1830 
1831     pub fn FD_ZERO(set: *mut fd_set) -> () {
1832         for slot in &mut (*set).fds_bits {
1833             *slot = 0;
1834         }
1835     }
1836 }
1837 
1838 safe_f! {
1839     pub fn SIGRTMAX() -> c_int {
1840         unsafe { __libc_current_sigrtmax() }
1841     }
1842 
1843     pub fn SIGRTMIN() -> c_int {
1844         unsafe { __libc_current_sigrtmin() }
1845     }
1846 
1847     pub {const} fn WIFSTOPPED(status: c_int) -> bool {
1848         (status & 0xff) == 0x7f
1849     }
1850 
1851     pub {const} fn WSTOPSIG(status: c_int) -> c_int {
1852         (status >> 8) & 0xff
1853     }
1854 
1855     pub {const} fn WIFCONTINUED(status: c_int) -> bool {
1856         status == 0xffff
1857     }
1858 
1859     pub {const} fn WIFSIGNALED(status: c_int) -> bool {
1860         ((status & 0x7f) + 1) as i8 >= 2
1861     }
1862 
1863     pub {const} fn WTERMSIG(status: c_int) -> c_int {
1864         status & 0x7f
1865     }
1866 
1867     pub {const} fn WIFEXITED(status: c_int) -> bool {
1868         (status & 0x7f) == 0
1869     }
1870 
1871     pub {const} fn WEXITSTATUS(status: c_int) -> c_int {
1872         (status >> 8) & 0xff
1873     }
1874 
1875     pub {const} fn WCOREDUMP(status: c_int) -> bool {
1876         (status & 0x80) != 0
1877     }
1878 
1879     pub {const} fn W_EXITCODE(ret: c_int, sig: c_int) -> c_int {
1880         (ret << 8) | sig
1881     }
1882 
1883     pub {const} fn W_STOPCODE(sig: c_int) -> c_int {
1884         (sig << 8) | 0x7f
1885     }
1886 
1887     pub {const} fn QCMD(cmd: c_int, type_: c_int) -> c_int {
1888         (cmd << 8) | (type_ & 0x00ff)
1889     }
1890 
1891     pub {const} fn IPOPT_COPIED(o: u8) -> u8 {
1892         o & IPOPT_COPY
1893     }
1894 
1895     pub {const} fn IPOPT_CLASS(o: u8) -> u8 {
1896         o & IPOPT_CLASS_MASK
1897     }
1898 
1899     pub {const} fn IPOPT_NUMBER(o: u8) -> u8 {
1900         o & IPOPT_NUMBER_MASK
1901     }
1902 
1903     pub {const} fn IPTOS_ECN(x: u8) -> u8 {
1904         x & crate::IPTOS_ECN_MASK
1905     }
1906 
1907     #[allow(ellipsis_inclusive_range_patterns)]
1908     pub {const} fn KERNEL_VERSION(a: u32, b: u32, c: u32) -> u32 {
1909         ((a << 16) + (b << 8)) + if c > 255 { 255 } else { c }
1910     }
1911 }
1912 
1913 extern "C" {
1914     #[doc(hidden)]
__libc_current_sigrtmax() -> c_int1915     pub fn __libc_current_sigrtmax() -> c_int;
1916     #[doc(hidden)]
__libc_current_sigrtmin() -> c_int1917     pub fn __libc_current_sigrtmin() -> c_int;
1918 
sem_destroy(sem: *mut sem_t) -> c_int1919     pub fn sem_destroy(sem: *mut sem_t) -> c_int;
sem_init(sem: *mut sem_t, pshared: c_int, value: c_uint) -> c_int1920     pub fn sem_init(sem: *mut sem_t, pshared: c_int, value: c_uint) -> c_int;
fdatasync(fd: c_int) -> c_int1921     pub fn fdatasync(fd: c_int) -> c_int;
mincore(addr: *mut c_void, len: size_t, vec: *mut c_uchar) -> c_int1922     pub fn mincore(addr: *mut c_void, len: size_t, vec: *mut c_uchar) -> c_int;
1923 
1924     #[cfg_attr(gnu_time_bits64, link_name = "__clock_getres64")]
clock_getres(clk_id: crate::clockid_t, tp: *mut crate::timespec) -> c_int1925     pub fn clock_getres(clk_id: crate::clockid_t, tp: *mut crate::timespec) -> c_int;
1926     #[cfg_attr(gnu_time_bits64, link_name = "__clock_gettime64")]
clock_gettime(clk_id: crate::clockid_t, tp: *mut crate::timespec) -> c_int1927     pub fn clock_gettime(clk_id: crate::clockid_t, tp: *mut crate::timespec) -> c_int;
1928     #[cfg_attr(gnu_time_bits64, link_name = "__clock_settime64")]
clock_settime(clk_id: crate::clockid_t, tp: *const crate::timespec) -> c_int1929     pub fn clock_settime(clk_id: crate::clockid_t, tp: *const crate::timespec) -> c_int;
clock_getcpuclockid(pid: crate::pid_t, clk_id: *mut crate::clockid_t) -> c_int1930     pub fn clock_getcpuclockid(pid: crate::pid_t, clk_id: *mut crate::clockid_t) -> c_int;
1931 
dirfd(dirp: *mut crate::DIR) -> c_int1932     pub fn dirfd(dirp: *mut crate::DIR) -> c_int;
1933 
pthread_getattr_np(native: crate::pthread_t, attr: *mut crate::pthread_attr_t) -> c_int1934     pub fn pthread_getattr_np(native: crate::pthread_t, attr: *mut crate::pthread_attr_t) -> c_int;
pthread_attr_getstack( attr: *const crate::pthread_attr_t, stackaddr: *mut *mut c_void, stacksize: *mut size_t, ) -> c_int1935     pub fn pthread_attr_getstack(
1936         attr: *const crate::pthread_attr_t,
1937         stackaddr: *mut *mut c_void,
1938         stacksize: *mut size_t,
1939     ) -> c_int;
pthread_attr_setstack( attr: *mut crate::pthread_attr_t, stackaddr: *mut c_void, stacksize: size_t, ) -> c_int1940     pub fn pthread_attr_setstack(
1941         attr: *mut crate::pthread_attr_t,
1942         stackaddr: *mut c_void,
1943         stacksize: size_t,
1944     ) -> c_int;
memalign(align: size_t, size: size_t) -> *mut c_void1945     pub fn memalign(align: size_t, size: size_t) -> *mut c_void;
setgroups(ngroups: size_t, ptr: *const crate::gid_t) -> c_int1946     pub fn setgroups(ngroups: size_t, ptr: *const crate::gid_t) -> c_int;
pipe2(fds: *mut c_int, flags: c_int) -> c_int1947     pub fn pipe2(fds: *mut c_int, flags: c_int) -> c_int;
1948     #[cfg_attr(gnu_file_offset_bits64, link_name = "statfs64")]
statfs(path: *const c_char, buf: *mut statfs) -> c_int1949     pub fn statfs(path: *const c_char, buf: *mut statfs) -> c_int;
1950     #[cfg_attr(gnu_file_offset_bits64, link_name = "fstatfs64")]
fstatfs(fd: c_int, buf: *mut statfs) -> c_int1951     pub fn fstatfs(fd: c_int, buf: *mut statfs) -> c_int;
memrchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void1952     pub fn memrchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
1953     #[cfg_attr(gnu_file_offset_bits64, link_name = "posix_fadvise64")]
posix_fadvise(fd: c_int, offset: off_t, len: off_t, advise: c_int) -> c_int1954     pub fn posix_fadvise(fd: c_int, offset: off_t, len: off_t, advise: c_int) -> c_int;
1955     #[cfg_attr(gnu_time_bits64, link_name = "__futimens64")]
futimens(fd: c_int, times: *const crate::timespec) -> c_int1956     pub fn futimens(fd: c_int, times: *const crate::timespec) -> c_int;
1957     #[cfg_attr(gnu_time_bits64, link_name = "__utimensat64")]
utimensat( dirfd: c_int, path: *const c_char, times: *const crate::timespec, flag: c_int, ) -> c_int1958     pub fn utimensat(
1959         dirfd: c_int,
1960         path: *const c_char,
1961         times: *const crate::timespec,
1962         flag: c_int,
1963     ) -> c_int;
duplocale(base: crate::locale_t) -> crate::locale_t1964     pub fn duplocale(base: crate::locale_t) -> crate::locale_t;
freelocale(loc: crate::locale_t)1965     pub fn freelocale(loc: crate::locale_t);
newlocale(mask: c_int, locale: *const c_char, base: crate::locale_t) -> crate::locale_t1966     pub fn newlocale(mask: c_int, locale: *const c_char, base: crate::locale_t) -> crate::locale_t;
uselocale(loc: crate::locale_t) -> crate::locale_t1967     pub fn uselocale(loc: crate::locale_t) -> crate::locale_t;
mknodat(dirfd: c_int, pathname: *const c_char, mode: mode_t, dev: dev_t) -> c_int1968     pub fn mknodat(dirfd: c_int, pathname: *const c_char, mode: mode_t, dev: dev_t) -> c_int;
pthread_condattr_getclock( attr: *const pthread_condattr_t, clock_id: *mut clockid_t, ) -> c_int1969     pub fn pthread_condattr_getclock(
1970         attr: *const pthread_condattr_t,
1971         clock_id: *mut clockid_t,
1972     ) -> c_int;
pthread_condattr_setclock( attr: *mut pthread_condattr_t, clock_id: crate::clockid_t, ) -> c_int1973     pub fn pthread_condattr_setclock(
1974         attr: *mut pthread_condattr_t,
1975         clock_id: crate::clockid_t,
1976     ) -> c_int;
pthread_condattr_setpshared(attr: *mut pthread_condattr_t, pshared: c_int) -> c_int1977     pub fn pthread_condattr_setpshared(attr: *mut pthread_condattr_t, pshared: c_int) -> c_int;
pthread_mutexattr_setpshared(attr: *mut pthread_mutexattr_t, pshared: c_int) -> c_int1978     pub fn pthread_mutexattr_setpshared(attr: *mut pthread_mutexattr_t, pshared: c_int) -> c_int;
pthread_rwlockattr_getpshared( attr: *const pthread_rwlockattr_t, val: *mut c_int, ) -> c_int1979     pub fn pthread_rwlockattr_getpshared(
1980         attr: *const pthread_rwlockattr_t,
1981         val: *mut c_int,
1982     ) -> c_int;
pthread_rwlockattr_setpshared(attr: *mut pthread_rwlockattr_t, val: c_int) -> c_int1983     pub fn pthread_rwlockattr_setpshared(attr: *mut pthread_rwlockattr_t, val: c_int) -> c_int;
ptsname_r(fd: c_int, buf: *mut c_char, buflen: size_t) -> c_int1984     pub fn ptsname_r(fd: c_int, buf: *mut c_char, buflen: size_t) -> c_int;
clearenv() -> c_int1985     pub fn clearenv() -> c_int;
waitid( idtype: idtype_t, id: id_t, infop: *mut crate::siginfo_t, options: c_int, ) -> c_int1986     pub fn waitid(
1987         idtype: idtype_t,
1988         id: id_t,
1989         infop: *mut crate::siginfo_t,
1990         options: c_int,
1991     ) -> c_int;
getresuid( ruid: *mut crate::uid_t, euid: *mut crate::uid_t, suid: *mut crate::uid_t, ) -> c_int1992     pub fn getresuid(
1993         ruid: *mut crate::uid_t,
1994         euid: *mut crate::uid_t,
1995         suid: *mut crate::uid_t,
1996     ) -> c_int;
getresgid( rgid: *mut crate::gid_t, egid: *mut crate::gid_t, sgid: *mut crate::gid_t, ) -> c_int1997     pub fn getresgid(
1998         rgid: *mut crate::gid_t,
1999         egid: *mut crate::gid_t,
2000         sgid: *mut crate::gid_t,
2001     ) -> c_int;
acct(filename: *const c_char) -> c_int2002     pub fn acct(filename: *const c_char) -> c_int;
brk(addr: *mut c_void) -> c_int2003     pub fn brk(addr: *mut c_void) -> c_int;
sbrk(increment: intptr_t) -> *mut c_void2004     pub fn sbrk(increment: intptr_t) -> *mut c_void;
2005     #[deprecated(
2006         since = "0.2.66",
2007         note = "causes memory corruption, see rust-lang/libc#1596"
2008     )]
vfork() -> crate::pid_t2009     pub fn vfork() -> crate::pid_t;
setresgid(rgid: crate::gid_t, egid: crate::gid_t, sgid: crate::gid_t) -> c_int2010     pub fn setresgid(rgid: crate::gid_t, egid: crate::gid_t, sgid: crate::gid_t) -> c_int;
setresuid(ruid: crate::uid_t, euid: crate::uid_t, suid: crate::uid_t) -> c_int2011     pub fn setresuid(ruid: crate::uid_t, euid: crate::uid_t, suid: crate::uid_t) -> c_int;
2012     #[cfg_attr(gnu_time_bits64, link_name = "__wait4_time64")]
wait4( pid: crate::pid_t, status: *mut c_int, options: c_int, rusage: *mut crate::rusage, ) -> crate::pid_t2013     pub fn wait4(
2014         pid: crate::pid_t,
2015         status: *mut c_int,
2016         options: c_int,
2017         rusage: *mut crate::rusage,
2018     ) -> crate::pid_t;
login_tty(fd: c_int) -> c_int2019     pub fn login_tty(fd: c_int) -> c_int;
2020 
2021     // DIFF(main): changed to `*const *mut` in e77f551de9
execvpe( file: *const c_char, argv: *const *const c_char, envp: *const *const c_char, ) -> c_int2022     pub fn execvpe(
2023         file: *const c_char,
2024         argv: *const *const c_char,
2025         envp: *const *const c_char,
2026     ) -> c_int;
fexecve(fd: c_int, argv: *const *const c_char, envp: *const *const c_char) -> c_int2027     pub fn fexecve(fd: c_int, argv: *const *const c_char, envp: *const *const c_char) -> c_int;
2028 
getifaddrs(ifap: *mut *mut crate::ifaddrs) -> c_int2029     pub fn getifaddrs(ifap: *mut *mut crate::ifaddrs) -> c_int;
freeifaddrs(ifa: *mut crate::ifaddrs)2030     pub fn freeifaddrs(ifa: *mut crate::ifaddrs);
bind( socket: c_int, address: *const crate::sockaddr, address_len: crate::socklen_t, ) -> c_int2031     pub fn bind(
2032         socket: c_int,
2033         address: *const crate::sockaddr,
2034         address_len: crate::socklen_t,
2035     ) -> c_int;
2036 
writev(fd: c_int, iov: *const crate::iovec, iovcnt: c_int) -> ssize_t2037     pub fn writev(fd: c_int, iov: *const crate::iovec, iovcnt: c_int) -> ssize_t;
readv(fd: c_int, iov: *const crate::iovec, iovcnt: c_int) -> ssize_t2038     pub fn readv(fd: c_int, iov: *const crate::iovec, iovcnt: c_int) -> ssize_t;
2039 
2040     #[cfg_attr(gnu_time_bits64, link_name = "__sendmsg64")]
sendmsg(fd: c_int, msg: *const crate::msghdr, flags: c_int) -> ssize_t2041     pub fn sendmsg(fd: c_int, msg: *const crate::msghdr, flags: c_int) -> ssize_t;
2042     #[cfg_attr(gnu_time_bits64, link_name = "__recvmsg64")]
recvmsg(fd: c_int, msg: *mut crate::msghdr, flags: c_int) -> ssize_t2043     pub fn recvmsg(fd: c_int, msg: *mut crate::msghdr, flags: c_int) -> ssize_t;
uname(buf: *mut crate::utsname) -> c_int2044     pub fn uname(buf: *mut crate::utsname) -> c_int;
2045 
strchrnul(s: *const c_char, c: c_int) -> *mut c_char2046     pub fn strchrnul(s: *const c_char, c: c_int) -> *mut c_char;
2047 
strftime( s: *mut c_char, max: size_t, format: *const c_char, tm: *const crate::tm, ) -> size_t2048     pub fn strftime(
2049         s: *mut c_char,
2050         max: size_t,
2051         format: *const c_char,
2052         tm: *const crate::tm,
2053     ) -> size_t;
strftime_l( s: *mut c_char, max: size_t, format: *const c_char, tm: *const crate::tm, locale: crate::locale_t, ) -> size_t2054     pub fn strftime_l(
2055         s: *mut c_char,
2056         max: size_t,
2057         format: *const c_char,
2058         tm: *const crate::tm,
2059         locale: crate::locale_t,
2060     ) -> size_t;
strptime(s: *const c_char, format: *const c_char, tm: *mut crate::tm) -> *mut c_char2061     pub fn strptime(s: *const c_char, format: *const c_char, tm: *mut crate::tm) -> *mut c_char;
2062 
2063     #[cfg_attr(gnu_file_offset_bits64, link_name = "mkostemp64")]
mkostemp(template: *mut c_char, flags: c_int) -> c_int2064     pub fn mkostemp(template: *mut c_char, flags: c_int) -> c_int;
2065     #[cfg_attr(gnu_file_offset_bits64, link_name = "mkostemps64")]
mkostemps(template: *mut c_char, suffixlen: c_int, flags: c_int) -> c_int2066     pub fn mkostemps(template: *mut c_char, suffixlen: c_int, flags: c_int) -> c_int;
2067 
getdomainname(name: *mut c_char, len: size_t) -> c_int2068     pub fn getdomainname(name: *mut c_char, len: size_t) -> c_int;
setdomainname(name: *const c_char, len: size_t) -> c_int2069     pub fn setdomainname(name: *const c_char, len: size_t) -> c_int;
2070 }
2071 
2072 // LFS64 extensions
2073 //
2074 // * musl and Emscripten has 64-bit versions only so aliases the LFS64 symbols to the standard ones
2075 // * ulibc doesn't have preadv64/pwritev64
2076 cfg_if! {
2077     if #[cfg(not(any(target_env = "musl", target_os = "emscripten")))] {
2078         extern "C" {
2079             pub fn fstatfs64(fd: c_int, buf: *mut statfs64) -> c_int;
2080             pub fn statvfs64(path: *const c_char, buf: *mut statvfs64) -> c_int;
2081             pub fn fstatvfs64(fd: c_int, buf: *mut statvfs64) -> c_int;
2082             pub fn statfs64(path: *const c_char, buf: *mut statfs64) -> c_int;
2083             pub fn creat64(path: *const c_char, mode: mode_t) -> c_int;
2084             #[cfg_attr(gnu_time_bits64, link_name = "__fstat64_time64")]
2085             pub fn fstat64(fildes: c_int, buf: *mut stat64) -> c_int;
2086             #[cfg_attr(gnu_time_bits64, link_name = "__fstatat64_time64")]
2087             pub fn fstatat64(
2088                 dirfd: c_int,
2089                 pathname: *const c_char,
2090                 buf: *mut stat64,
2091                 flags: c_int,
2092             ) -> c_int;
2093             pub fn ftruncate64(fd: c_int, length: off64_t) -> c_int;
2094             pub fn lseek64(fd: c_int, offset: off64_t, whence: c_int) -> off64_t;
2095             #[cfg_attr(gnu_time_bits64, link_name = "__lstat64_time64")]
2096             pub fn lstat64(path: *const c_char, buf: *mut stat64) -> c_int;
2097             pub fn mmap64(
2098                 addr: *mut c_void,
2099                 len: size_t,
2100                 prot: c_int,
2101                 flags: c_int,
2102                 fd: c_int,
2103                 offset: off64_t,
2104             ) -> *mut c_void;
2105             pub fn open64(path: *const c_char, oflag: c_int, ...) -> c_int;
2106             pub fn openat64(fd: c_int, path: *const c_char, oflag: c_int, ...) -> c_int;
2107             pub fn posix_fadvise64(
2108                 fd: c_int,
2109                 offset: off64_t,
2110                 len: off64_t,
2111                 advise: c_int,
2112             ) -> c_int;
2113             pub fn pread64(fd: c_int, buf: *mut c_void, count: size_t, offset: off64_t) -> ssize_t;
2114             pub fn pwrite64(
2115                 fd: c_int,
2116                 buf: *const c_void,
2117                 count: size_t,
2118                 offset: off64_t,
2119             ) -> ssize_t;
2120             pub fn readdir64(dirp: *mut crate::DIR) -> *mut crate::dirent64;
2121             pub fn readdir64_r(
2122                 dirp: *mut crate::DIR,
2123                 entry: *mut crate::dirent64,
2124                 result: *mut *mut crate::dirent64,
2125             ) -> c_int;
2126             #[cfg_attr(gnu_time_bits64, link_name = "__stat64_time64")]
2127             pub fn stat64(path: *const c_char, buf: *mut stat64) -> c_int;
2128             pub fn truncate64(path: *const c_char, length: off64_t) -> c_int;
2129         }
2130     }
2131 }
2132 
2133 cfg_if! {
2134     if #[cfg(not(any(
2135         target_env = "uclibc",
2136         target_env = "musl",
2137         target_os = "emscripten"
2138     )))] {
2139         extern "C" {
2140             pub fn preadv64(
2141                 fd: c_int,
2142                 iov: *const crate::iovec,
2143                 iovcnt: c_int,
2144                 offset: off64_t,
2145             ) -> ssize_t;
2146             pub fn pwritev64(
2147                 fd: c_int,
2148                 iov: *const crate::iovec,
2149                 iovcnt: c_int,
2150                 offset: off64_t,
2151             ) -> ssize_t;
2152         }
2153     }
2154 }
2155 
2156 cfg_if! {
2157     if #[cfg(not(target_env = "uclibc"))] {
2158         extern "C" {
2159             // uclibc has separate non-const version of this function
2160             pub fn forkpty(
2161                 amaster: *mut c_int,
2162                 name: *mut c_char,
2163                 termp: *const termios,
2164                 winp: *const crate::winsize,
2165             ) -> crate::pid_t;
2166             // uclibc has separate non-const version of this function
2167             pub fn openpty(
2168                 amaster: *mut c_int,
2169                 aslave: *mut c_int,
2170                 name: *mut c_char,
2171                 termp: *const termios,
2172                 winp: *const crate::winsize,
2173             ) -> c_int;
2174         }
2175     }
2176 }
2177 
2178 // The statx syscall, available on some libcs.
2179 cfg_if! {
2180     if #[cfg(any(target_env = "gnu", target_os = "android"))] {
2181         extern "C" {
2182             pub fn statx(
2183                 dirfd: c_int,
2184                 pathname: *const c_char,
2185                 flags: c_int,
2186                 mask: c_uint,
2187                 statxbuf: *mut statx,
2188             ) -> c_int;
2189         }
2190     }
2191 }
2192 
2193 cfg_if! {
2194     if #[cfg(target_os = "emscripten")] {
2195         mod emscripten;
2196         pub use self::emscripten::*;
2197     } else if #[cfg(target_os = "linux")] {
2198         mod linux;
2199         pub use self::linux::*;
2200     } else if #[cfg(target_os = "l4re")] {
2201         mod linux;
2202         pub use self::linux::*;
2203     } else if #[cfg(target_os = "android")] {
2204         mod android;
2205         pub use self::android::*;
2206     } else {
2207         // Unknown target_os
2208     }
2209 }
2210