libc/unix/linux_like/
mod.rs

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