interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / libc / src / unix / redox / mod.rs

1450 lines · 49551 bytes Raw Blame History
1use crate::prelude::*;
2
3pub type wchar_t = i32;
4
5pub type blkcnt_t = c_longlong;
6pub type blksize_t = c_long;
7pub type clock_t = c_long;
8pub type clockid_t = c_int;
9pub type dev_t = c_ulonglong;
10pub type fsblkcnt_t = c_ulong;
11pub type fsfilcnt_t = c_ulong;
12pub type ino_t = c_ulonglong;
13pub type mode_t = c_int;
14pub type nfds_t = c_ulong;
15pub type nlink_t = c_ulong;
16pub type off_t = c_longlong;
17pub type pthread_t = *mut c_void;
18// Must be usize due to library/std/sys_common/thread_local.rs,
19// should technically be *mut c_void
20pub type pthread_key_t = usize;
21pub type rlim_t = c_ulonglong;
22pub type sa_family_t = u16;
23pub type sem_t = *mut c_void;
24pub type sigset_t = c_ulonglong;
25pub type socklen_t = u32;
26pub type speed_t = u32;
27pub type suseconds_t = c_int;
28pub type tcflag_t = u32;
29pub type time_t = c_longlong;
30pub type id_t = c_uint;
31pub type uid_t = c_int;
32pub type gid_t = c_int;
33
34extern_ty! {
35 pub type timezone;
36}
37
38s! {
39 #[repr(C)]
40 pub struct utsname {
41 pub sysname: [c_char; UTSLENGTH],
42 pub nodename: [c_char; UTSLENGTH],
43 pub release: [c_char; UTSLENGTH],
44 pub version: [c_char; UTSLENGTH],
45 pub machine: [c_char; UTSLENGTH],
46 pub domainname: [c_char; UTSLENGTH],
47 }
48
49 pub struct dirent {
50 pub d_ino: crate::ino_t,
51 pub d_off: off_t,
52 pub d_reclen: c_ushort,
53 pub d_type: c_uchar,
54 pub d_name: [c_char; 256],
55 }
56
57 pub struct sockaddr_un {
58 pub sun_family: crate::sa_family_t,
59 pub sun_path: [c_char; 108],
60 }
61
62 pub struct sockaddr_storage {
63 pub ss_family: crate::sa_family_t,
64 __ss_padding: Padding<[u8; 128 - size_of::<sa_family_t>() - size_of::<c_ulong>()]>,
65 __ss_align: c_ulong,
66 }
67
68 pub struct addrinfo {
69 pub ai_flags: c_int,
70 pub ai_family: c_int,
71 pub ai_socktype: c_int,
72 pub ai_protocol: c_int,
73 pub ai_addrlen: size_t,
74 pub ai_canonname: *mut c_char,
75 pub ai_addr: *mut crate::sockaddr,
76 pub ai_next: *mut crate::addrinfo,
77 }
78
79 pub struct Dl_info {
80 pub dli_fname: *const c_char,
81 pub dli_fbase: *mut c_void,
82 pub dli_sname: *const c_char,
83 pub dli_saddr: *mut c_void,
84 }
85
86 pub struct epoll_event {
87 pub events: u32,
88 pub u64: u64,
89 pub _pad: u64,
90 }
91
92 pub struct fd_set {
93 fds_bits: [c_ulong; crate::FD_SETSIZE as usize / ULONG_SIZE],
94 }
95
96 pub struct in_addr {
97 pub s_addr: crate::in_addr_t,
98 }
99
100 pub struct ip_mreq {
101 pub imr_multiaddr: crate::in_addr,
102 pub imr_interface: crate::in_addr,
103 }
104
105 pub struct lconv {
106 pub currency_symbol: *const c_char,
107 pub decimal_point: *const c_char,
108 pub frac_digits: c_char,
109 pub grouping: *const c_char,
110 pub int_curr_symbol: *const c_char,
111 pub int_frac_digits: c_char,
112 pub mon_decimal_point: *const c_char,
113 pub mon_grouping: *const c_char,
114 pub mon_thousands_sep: *const c_char,
115 pub negative_sign: *const c_char,
116 pub n_cs_precedes: c_char,
117 pub n_sep_by_space: c_char,
118 pub n_sign_posn: c_char,
119 pub positive_sign: *const c_char,
120 pub p_cs_precedes: c_char,
121 pub p_sep_by_space: c_char,
122 pub p_sign_posn: c_char,
123 pub thousands_sep: *const c_char,
124 }
125
126 pub struct msghdr {
127 pub msg_name: *mut c_void,
128 pub msg_namelen: crate::socklen_t,
129 pub msg_iov: *mut crate::iovec,
130 pub msg_iovlen: size_t,
131 pub msg_control: *mut c_void,
132 pub msg_controllen: size_t,
133 pub msg_flags: c_int,
134 }
135
136 pub struct cmsghdr {
137 pub cmsg_len: size_t,
138 pub cmsg_level: c_int,
139 pub cmsg_type: c_int,
140 }
141
142 pub struct passwd {
143 pub pw_name: *mut c_char,
144 pub pw_passwd: *mut c_char,
145 pub pw_uid: crate::uid_t,
146 pub pw_gid: crate::gid_t,
147 pub pw_gecos: *mut c_char,
148 pub pw_dir: *mut c_char,
149 pub pw_shell: *mut c_char,
150 }
151
152 // FIXME(1.0): This should not implement `PartialEq`
153 #[allow(unpredictable_function_pointer_comparisons)]
154 pub struct sigaction {
155 pub sa_sigaction: crate::sighandler_t,
156 pub sa_flags: c_int,
157 pub sa_restorer: Option<extern "C" fn()>,
158 pub sa_mask: crate::sigset_t,
159 }
160
161 pub struct siginfo_t {
162 pub si_signo: c_int,
163 pub si_errno: c_int,
164 pub si_code: c_int,
165 _pad: Padding<[c_int; 29]>,
166 _align: [usize; 0],
167 }
168
169 pub struct sockaddr {
170 pub sa_family: crate::sa_family_t,
171 pub sa_data: [c_char; 14],
172 }
173
174 pub struct sockaddr_in {
175 pub sin_family: crate::sa_family_t,
176 pub sin_port: crate::in_port_t,
177 pub sin_addr: crate::in_addr,
178 pub sin_zero: [c_char; 8],
179 }
180
181 pub struct sockaddr_in6 {
182 pub sin6_family: crate::sa_family_t,
183 pub sin6_port: crate::in_port_t,
184 pub sin6_flowinfo: u32,
185 pub sin6_addr: crate::in6_addr,
186 pub sin6_scope_id: u32,
187 }
188
189 pub struct stat {
190 pub st_dev: crate::dev_t,
191 pub st_ino: crate::ino_t,
192 pub st_nlink: crate::nlink_t,
193 pub st_mode: mode_t,
194 pub st_uid: crate::uid_t,
195 pub st_gid: crate::gid_t,
196 pub st_rdev: crate::dev_t,
197 pub st_size: off_t,
198 pub st_blksize: crate::blksize_t,
199 pub st_blocks: crate::blkcnt_t,
200 pub st_atime: crate::time_t,
201 pub st_atime_nsec: c_long,
202 pub st_mtime: crate::time_t,
203 pub st_mtime_nsec: c_long,
204 pub st_ctime: crate::time_t,
205 pub st_ctime_nsec: c_long,
206 _pad: Padding<[c_char; 24]>,
207 }
208
209 pub struct statvfs {
210 pub f_bsize: c_ulong,
211 pub f_frsize: c_ulong,
212 pub f_blocks: crate::fsblkcnt_t,
213 pub f_bfree: crate::fsblkcnt_t,
214 pub f_bavail: crate::fsblkcnt_t,
215 pub f_files: crate::fsfilcnt_t,
216 pub f_ffree: crate::fsfilcnt_t,
217 pub f_favail: crate::fsfilcnt_t,
218 pub f_fsid: c_ulong,
219 pub f_flag: c_ulong,
220 pub f_namemax: c_ulong,
221 }
222
223 pub struct termios {
224 pub c_iflag: crate::tcflag_t,
225 pub c_oflag: crate::tcflag_t,
226 pub c_cflag: crate::tcflag_t,
227 pub c_lflag: crate::tcflag_t,
228 pub c_line: crate::cc_t,
229 pub c_cc: [crate::cc_t; crate::NCCS],
230 pub c_ispeed: crate::speed_t,
231 pub c_ospeed: crate::speed_t,
232 }
233
234 pub struct tm {
235 pub tm_sec: c_int,
236 pub tm_min: c_int,
237 pub tm_hour: c_int,
238 pub tm_mday: c_int,
239 pub tm_mon: c_int,
240 pub tm_year: c_int,
241 pub tm_wday: c_int,
242 pub tm_yday: c_int,
243 pub tm_isdst: c_int,
244 pub tm_gmtoff: c_long,
245 pub tm_zone: *const c_char,
246 }
247
248 pub struct ucred {
249 pub pid: crate::pid_t,
250 pub uid: uid_t,
251 pub gid: gid_t,
252 }
253
254 #[cfg_attr(target_pointer_width = "32", repr(C, align(4)))]
255 #[cfg_attr(target_pointer_width = "64", repr(C, align(8)))]
256 pub struct pthread_attr_t {
257 bytes: [u8; _PTHREAD_ATTR_SIZE],
258 }
259 #[repr(C)]
260 #[repr(align(4))]
261 pub struct pthread_barrier_t {
262 bytes: [u8; _PTHREAD_BARRIER_SIZE],
263 }
264 #[repr(C)]
265 #[repr(align(4))]
266 pub struct pthread_barrierattr_t {
267 bytes: [u8; _PTHREAD_BARRIERATTR_SIZE],
268 }
269 #[repr(C)]
270 #[repr(align(4))]
271 pub struct pthread_mutex_t {
272 bytes: [u8; _PTHREAD_MUTEX_SIZE],
273 }
274 #[repr(C)]
275 #[repr(align(4))]
276 pub struct pthread_rwlock_t {
277 bytes: [u8; _PTHREAD_RWLOCK_SIZE],
278 }
279 #[repr(C)]
280 #[repr(align(4))]
281 pub struct pthread_mutexattr_t {
282 bytes: [u8; _PTHREAD_MUTEXATTR_SIZE],
283 }
284 #[repr(C)]
285 #[repr(align(1))]
286 pub struct pthread_rwlockattr_t {
287 bytes: [u8; _PTHREAD_RWLOCKATTR_SIZE],
288 }
289 #[repr(C)]
290 #[repr(align(4))]
291 pub struct pthread_cond_t {
292 bytes: [u8; _PTHREAD_COND_SIZE],
293 }
294 #[repr(C)]
295 #[repr(align(4))]
296 pub struct pthread_condattr_t {
297 bytes: [u8; _PTHREAD_CONDATTR_SIZE],
298 }
299 #[repr(C)]
300 #[repr(align(4))]
301 pub struct pthread_once_t {
302 bytes: [u8; _PTHREAD_ONCE_SIZE],
303 }
304 #[repr(C)]
305 #[repr(align(4))]
306 pub struct pthread_spinlock_t {
307 bytes: [u8; _PTHREAD_SPINLOCK_SIZE],
308 }
309}
310const _PTHREAD_ATTR_SIZE: usize = 32;
311const _PTHREAD_RWLOCKATTR_SIZE: usize = 1;
312const _PTHREAD_RWLOCK_SIZE: usize = 4;
313const _PTHREAD_BARRIER_SIZE: usize = 24;
314const _PTHREAD_BARRIERATTR_SIZE: usize = 4;
315const _PTHREAD_CONDATTR_SIZE: usize = 8;
316const _PTHREAD_COND_SIZE: usize = 8;
317const _PTHREAD_MUTEX_SIZE: usize = 12;
318const _PTHREAD_MUTEXATTR_SIZE: usize = 20;
319const _PTHREAD_ONCE_SIZE: usize = 4;
320const _PTHREAD_SPINLOCK_SIZE: usize = 4;
321
322pub const UTSLENGTH: usize = 65;
323
324// intentionally not public, only used for fd_set
325cfg_if! {
326 if #[cfg(target_pointer_width = "32")] {
327 const ULONG_SIZE: usize = 32;
328 } else if #[cfg(target_pointer_width = "64")] {
329 const ULONG_SIZE: usize = 64;
330 } else {
331 // Unknown target_pointer_width
332 }
333}
334
335// limits.h
336/// Constants may change across releases. See the [usage guidelines](crate#usage-guidelines)
337/// for details.
338pub const PATH_MAX: c_int = 4096;
339
340// fcntl.h
341pub const F_GETLK: c_int = 5;
342pub const F_SETLK: c_int = 6;
343pub const F_SETLKW: c_int = 7;
344pub const F_ULOCK: c_int = 0;
345pub const F_LOCK: c_int = 1;
346pub const F_TLOCK: c_int = 2;
347pub const F_TEST: c_int = 3;
348
349pub const AT_FDCWD: c_int = -100;
350pub const AT_SYMLINK_NOFOLLOW: c_int = 0x200;
351pub const AT_REMOVEDIR: c_int = 0x200;
352pub const AT_SYMLINK_FOLLOW: c_int = 0x2000;
353pub const AT_EMPTY_PATH: c_int = 0x4000;
354pub const AT_EACCESS: c_int = 0x400;
355
356// FIXME(redox): relibc {
357pub const RTLD_DEFAULT: *mut c_void = ptr::null_mut();
358// }
359
360// dlfcn.h
361pub const RTLD_LAZY: c_int = 0x0001;
362pub const RTLD_NOW: c_int = 0x0002;
363pub const RTLD_NOLOAD: c_int = 0x0004;
364pub const RTLD_GLOBAL: c_int = 0x0100;
365pub const RTLD_LOCAL: c_int = 0x0000;
366
367// errno.h
368pub const EPERM: c_int = 1; /* Operation not permitted */
369pub const ENOENT: c_int = 2; /* No such file or directory */
370pub const ESRCH: c_int = 3; /* No such process */
371pub const EINTR: c_int = 4; /* Interrupted system call */
372pub const EIO: c_int = 5; /* I/O error */
373pub const ENXIO: c_int = 6; /* No such device or address */
374pub const E2BIG: c_int = 7; /* Argument list too long */
375pub const ENOEXEC: c_int = 8; /* Exec format error */
376pub const EBADF: c_int = 9; /* Bad file number */
377pub const ECHILD: c_int = 10; /* No child processes */
378pub const EAGAIN: c_int = 11; /* Try again */
379pub const ENOMEM: c_int = 12; /* Out of memory */
380pub const EACCES: c_int = 13; /* Permission denied */
381pub const EFAULT: c_int = 14; /* Bad address */
382pub const ENOTBLK: c_int = 15; /* Block device required */
383pub const EBUSY: c_int = 16; /* Device or resource busy */
384pub const EEXIST: c_int = 17; /* File exists */
385pub const EXDEV: c_int = 18; /* Cross-device link */
386pub const ENODEV: c_int = 19; /* No such device */
387pub const ENOTDIR: c_int = 20; /* Not a directory */
388pub const EISDIR: c_int = 21; /* Is a directory */
389pub const EINVAL: c_int = 22; /* Invalid argument */
390pub const ENFILE: c_int = 23; /* File table overflow */
391pub const EMFILE: c_int = 24; /* Too many open files */
392pub const ENOTTY: c_int = 25; /* Not a typewriter */
393pub const ETXTBSY: c_int = 26; /* Text file busy */
394pub const EFBIG: c_int = 27; /* File too large */
395pub const ENOSPC: c_int = 28; /* No space left on device */
396pub const ESPIPE: c_int = 29; /* Illegal seek */
397pub const EROFS: c_int = 30; /* Read-only file system */
398pub const EMLINK: c_int = 31; /* Too many links */
399pub const EPIPE: c_int = 32; /* Broken pipe */
400pub const EDOM: c_int = 33; /* Math argument out of domain of func */
401pub const ERANGE: c_int = 34; /* Math result not representable */
402pub const EDEADLK: c_int = 35; /* Resource deadlock would occur */
403pub const ENAMETOOLONG: c_int = 36; /* File name too long */
404pub const ENOLCK: c_int = 37; /* No record locks available */
405pub const ENOSYS: c_int = 38; /* Function not implemented */
406pub const ENOTEMPTY: c_int = 39; /* Directory not empty */
407pub const ELOOP: c_int = 40; /* Too many symbolic links encountered */
408pub const EWOULDBLOCK: c_int = 41; /* Operation would block */
409pub const ENOMSG: c_int = 42; /* No message of desired type */
410pub const EIDRM: c_int = 43; /* Identifier removed */
411pub const ECHRNG: c_int = 44; /* Channel number out of range */
412pub const EL2NSYNC: c_int = 45; /* Level 2 not synchronized */
413pub const EL3HLT: c_int = 46; /* Level 3 halted */
414pub const EL3RST: c_int = 47; /* Level 3 reset */
415pub const ELNRNG: c_int = 48; /* Link number out of range */
416pub const EUNATCH: c_int = 49; /* Protocol driver not attached */
417pub const ENOCSI: c_int = 50; /* No CSI structure available */
418pub const EL2HLT: c_int = 51; /* Level 2 halted */
419pub const EBADE: c_int = 52; /* Invalid exchange */
420pub const EBADR: c_int = 53; /* Invalid request descriptor */
421pub const EXFULL: c_int = 54; /* Exchange full */
422pub const ENOANO: c_int = 55; /* No anode */
423pub const EBADRQC: c_int = 56; /* Invalid request code */
424pub const EBADSLT: c_int = 57; /* Invalid slot */
425pub const EDEADLOCK: c_int = 58; /* Resource deadlock would occur */
426pub const EBFONT: c_int = 59; /* Bad font file format */
427pub const ENOSTR: c_int = 60; /* Device not a stream */
428pub const ENODATA: c_int = 61; /* No data available */
429pub const ETIME: c_int = 62; /* Timer expired */
430pub const ENOSR: c_int = 63; /* Out of streams resources */
431pub const ENONET: c_int = 64; /* Machine is not on the network */
432pub const ENOPKG: c_int = 65; /* Package not installed */
433pub const EREMOTE: c_int = 66; /* Object is remote */
434pub const ENOLINK: c_int = 67; /* Link has been severed */
435pub const EADV: c_int = 68; /* Advertise error */
436pub const ESRMNT: c_int = 69; /* Srmount error */
437pub const ECOMM: c_int = 70; /* Communication error on send */
438pub const EPROTO: c_int = 71; /* Protocol error */
439pub const EMULTIHOP: c_int = 72; /* Multihop attempted */
440pub const EDOTDOT: c_int = 73; /* RFS specific error */
441pub const EBADMSG: c_int = 74; /* Not a data message */
442pub const EOVERFLOW: c_int = 75; /* Value too large for defined data type */
443pub const ENOTUNIQ: c_int = 76; /* Name not unique on network */
444pub const EBADFD: c_int = 77; /* File descriptor in bad state */
445pub const EREMCHG: c_int = 78; /* Remote address changed */
446pub const ELIBACC: c_int = 79; /* Can not access a needed shared library */
447pub const ELIBBAD: c_int = 80; /* Accessing a corrupted shared library */
448pub const ELIBSCN: c_int = 81; /* .lib section in a.out corrupted */
449/* Attempting to link in too many shared libraries */
450pub const ELIBMAX: c_int = 82;
451pub const ELIBEXEC: c_int = 83; /* Cannot exec a shared library directly */
452pub const EILSEQ: c_int = 84; /* Illegal byte sequence */
453/* Interrupted system call should be restarted */
454pub const ERESTART: c_int = 85;
455pub const ESTRPIPE: c_int = 86; /* Streams pipe error */
456pub const EUSERS: c_int = 87; /* Too many users */
457pub const ENOTSOCK: c_int = 88; /* Socket operation on non-socket */
458pub const EDESTADDRREQ: c_int = 89; /* Destination address required */
459pub const EMSGSIZE: c_int = 90; /* Message too long */
460pub const EPROTOTYPE: c_int = 91; /* Protocol wrong type for socket */
461pub const ENOPROTOOPT: c_int = 92; /* Protocol not available */
462pub const EPROTONOSUPPORT: c_int = 93; /* Protocol not supported */
463pub const ESOCKTNOSUPPORT: c_int = 94; /* Socket type not supported */
464/* Operation not supported on transport endpoint */
465pub const EOPNOTSUPP: c_int = 95;
466pub const ENOTSUP: c_int = EOPNOTSUPP;
467pub const EPFNOSUPPORT: c_int = 96; /* Protocol family not supported */
468/* Address family not supported by protocol */
469pub const EAFNOSUPPORT: c_int = 97;
470pub const EADDRINUSE: c_int = 98; /* Address already in use */
471pub const EADDRNOTAVAIL: c_int = 99; /* Cannot assign requested address */
472pub const ENETDOWN: c_int = 100; /* Network is down */
473pub const ENETUNREACH: c_int = 101; /* Network is unreachable */
474/* Network dropped connection because of reset */
475pub const ENETRESET: c_int = 102;
476pub const ECONNABORTED: c_int = 103; /* Software caused connection abort */
477pub const ECONNRESET: c_int = 104; /* Connection reset by peer */
478pub const ENOBUFS: c_int = 105; /* No buffer space available */
479pub const EISCONN: c_int = 106; /* Transport endpoint is already connected */
480pub const ENOTCONN: c_int = 107; /* Transport endpoint is not connected */
481/* Cannot send after transport endpoint shutdown */
482pub const ESHUTDOWN: c_int = 108;
483pub const ETOOMANYREFS: c_int = 109; /* Too many references: cannot splice */
484pub const ETIMEDOUT: c_int = 110; /* Connection timed out */
485pub const ECONNREFUSED: c_int = 111; /* Connection refused */
486pub const EHOSTDOWN: c_int = 112; /* Host is down */
487pub const EHOSTUNREACH: c_int = 113; /* No route to host */
488pub const EALREADY: c_int = 114; /* Operation already in progress */
489pub const EINPROGRESS: c_int = 115; /* Operation now in progress */
490pub const ESTALE: c_int = 116; /* Stale NFS file handle */
491pub const EUCLEAN: c_int = 117; /* Structure needs cleaning */
492pub const ENOTNAM: c_int = 118; /* Not a XENIX named type file */
493pub const ENAVAIL: c_int = 119; /* No XENIX semaphores available */
494pub const EISNAM: c_int = 120; /* Is a named type file */
495pub const EREMOTEIO: c_int = 121; /* Remote I/O error */
496pub const EDQUOT: c_int = 122; /* Quota exceeded */
497pub const ENOMEDIUM: c_int = 123; /* No medium found */
498pub const EMEDIUMTYPE: c_int = 124; /* Wrong medium type */
499pub const ECANCELED: c_int = 125; /* Operation Canceled */
500pub const ENOKEY: c_int = 126; /* Required key not available */
501pub const EKEYEXPIRED: c_int = 127; /* Key has expired */
502pub const EKEYREVOKED: c_int = 128; /* Key has been revoked */
503pub const EKEYREJECTED: c_int = 129; /* Key was rejected by service */
504pub const EOWNERDEAD: c_int = 130; /* Owner died */
505pub const ENOTRECOVERABLE: c_int = 131; /* State not recoverable */
506
507// fcntl.h
508pub const F_DUPFD: c_int = 0;
509pub const F_GETFD: c_int = 1;
510pub const F_SETFD: c_int = 2;
511pub const F_GETFL: c_int = 3;
512pub const F_SETFL: c_int = 4;
513pub const F_DUPFD_CLOEXEC: c_int = 1030;
514pub const FD_CLOEXEC: c_int = 0x0100_0000;
515pub const O_RDONLY: c_int = 0x0001_0000;
516pub const O_WRONLY: c_int = 0x0002_0000;
517pub const O_RDWR: c_int = 0x0003_0000;
518pub const O_ACCMODE: c_int = 0x0003_0000;
519pub const O_NONBLOCK: c_int = 0x0004_0000;
520pub const O_NDELAY: c_int = O_NONBLOCK;
521pub const O_APPEND: c_int = 0x0008_0000;
522pub const O_SHLOCK: c_int = 0x0010_0000;
523pub const O_EXLOCK: c_int = 0x0020_0000;
524pub const O_ASYNC: c_int = 0x0040_0000;
525pub const O_FSYNC: c_int = 0x0080_0000;
526pub const O_SYNC: c_int = O_FSYNC;
527pub const O_CLOEXEC: c_int = 0x0100_0000;
528pub const O_CREAT: c_int = 0x0200_0000;
529pub const O_TRUNC: c_int = 0x0400_0000;
530pub const O_EXCL: c_int = 0x0800_0000;
531pub const O_DIRECTORY: c_int = 0x1000_0000;
532pub const O_PATH: c_int = 0x2000_0000;
533pub const O_SYMLINK: c_int = 0x4000_0000;
534// Negative to allow it to be used as int
535// FIXME(redox): Fix negative values missing from includes
536pub const O_NOFOLLOW: c_int = -0x8000_0000;
537pub const O_NOCTTY: c_int = 0x00000200;
538
539// locale.h
540pub const LC_COLLATE: c_int = 0;
541pub const LC_CTYPE: c_int = 1;
542pub const LC_MESSAGES: c_int = 2;
543pub const LC_MONETARY: c_int = 3;
544pub const LC_NUMERIC: c_int = 4;
545pub const LC_TIME: c_int = 5;
546pub const LC_ALL: c_int = 6;
547
548// netdb.h
549pub const AI_PASSIVE: c_int = 0x0001;
550pub const AI_CANONNAME: c_int = 0x0002;
551pub const AI_NUMERICHOST: c_int = 0x0004;
552pub const AI_V4MAPPED: c_int = 0x0008;
553pub const AI_ALL: c_int = 0x0010;
554pub const AI_ADDRCONFIG: c_int = 0x0020;
555pub const AI_NUMERICSERV: c_int = 0x0400;
556pub const EAI_BADFLAGS: c_int = -1;
557pub const EAI_NONAME: c_int = -2;
558pub const EAI_AGAIN: c_int = -3;
559pub const EAI_FAIL: c_int = -4;
560pub const EAI_NODATA: c_int = -5;
561pub const EAI_FAMILY: c_int = -6;
562pub const EAI_SOCKTYPE: c_int = -7;
563pub const EAI_SERVICE: c_int = -8;
564pub const EAI_ADDRFAMILY: c_int = -9;
565pub const EAI_MEMORY: c_int = -10;
566pub const EAI_SYSTEM: c_int = -11;
567pub const EAI_OVERFLOW: c_int = -12;
568pub const NI_MAXHOST: c_int = 1025;
569pub const NI_MAXSERV: c_int = 32;
570pub const NI_NUMERICHOST: c_int = 0x0001;
571pub const NI_NUMERICSERV: c_int = 0x0002;
572pub const NI_NOFQDN: c_int = 0x0004;
573pub const NI_NAMEREQD: c_int = 0x0008;
574pub const NI_DGRAM: c_int = 0x0010;
575
576// netinet/in.h
577// FIXME(redox): relibc {
578pub const IP_TTL: c_int = 2;
579pub const IPV6_UNICAST_HOPS: c_int = 16;
580pub const IPV6_MULTICAST_IF: c_int = 17;
581pub const IPV6_MULTICAST_HOPS: c_int = 18;
582pub const IPV6_MULTICAST_LOOP: c_int = 19;
583pub const IPV6_ADD_MEMBERSHIP: c_int = 20;
584pub const IPV6_JOIN_GROUP: c_int = 20;
585pub const IPV6_DROP_MEMBERSHIP: c_int = 21;
586pub const IPV6_LEAVE_GROUP: c_int = 21;
587pub const IPV6_V6ONLY: c_int = 26;
588pub const IP_MULTICAST_IF: c_int = 32;
589pub const IP_MULTICAST_TTL: c_int = 33;
590pub const IP_MULTICAST_LOOP: c_int = 34;
591pub const IP_ADD_MEMBERSHIP: c_int = 35;
592pub const IP_DROP_MEMBERSHIP: c_int = 36;
593pub const IP_TOS: c_int = 1;
594pub const IP_RECVTOS: c_int = 13;
595pub const IPPROTO_IGMP: c_int = 2;
596pub const IPPROTO_PUP: c_int = 12;
597pub const IPPROTO_IDP: c_int = 22;
598pub const IPPROTO_RAW: c_int = 255;
599pub const IPPROTO_MAX: c_int = 255;
600// }
601
602// netinet/tcp.h
603pub const TCP_NODELAY: c_int = 1;
604pub const TCP_MAXSEG: c_int = 2;
605pub const TCP_KEEPIDLE: c_int = 4;
606pub const TCP_KEEPINTVL: c_int = 5;
607pub const TCP_KEEPCNT: c_int = 6;
608
609// poll.h
610pub const POLLIN: c_short = 0x001;
611pub const POLLPRI: c_short = 0x002;
612pub const POLLOUT: c_short = 0x004;
613pub const POLLERR: c_short = 0x008;
614pub const POLLHUP: c_short = 0x010;
615pub const POLLNVAL: c_short = 0x020;
616pub const POLLRDNORM: c_short = 0x040;
617pub const POLLRDBAND: c_short = 0x080;
618pub const POLLWRNORM: c_short = 0x100;
619pub const POLLWRBAND: c_short = 0x200;
620
621// pthread.h
622pub const PTHREAD_MUTEX_DEFAULT: c_int = 0;
623pub const PTHREAD_MUTEX_ERRORCHECK: c_int = 1;
624pub const PTHREAD_MUTEX_NORMAL: c_int = 2;
625pub const PTHREAD_MUTEX_RECURSIVE: c_int = 3;
626
627pub const PTHREAD_MUTEX_ROBUST: c_int = 0;
628pub const PTHREAD_MUTEX_STALLED: c_int = 1;
629
630pub const PTHREAD_MUTEX_INITIALIZER: crate::pthread_mutex_t = crate::pthread_mutex_t {
631 bytes: [0; _PTHREAD_MUTEX_SIZE],
632};
633pub const PTHREAD_COND_INITIALIZER: crate::pthread_cond_t = crate::pthread_cond_t {
634 bytes: [0; _PTHREAD_COND_SIZE],
635};
636pub const PTHREAD_RWLOCK_INITIALIZER: crate::pthread_rwlock_t = crate::pthread_rwlock_t {
637 bytes: [0; _PTHREAD_RWLOCK_SIZE],
638};
639pub const PTHREAD_STACK_MIN: size_t = 4096;
640
641// signal.h
642pub const SIG_BLOCK: c_int = 0;
643pub const SIG_UNBLOCK: c_int = 1;
644pub const SIG_SETMASK: c_int = 2;
645pub const SIGHUP: c_int = 1;
646pub const SIGINT: c_int = 2;
647pub const SIGQUIT: c_int = 3;
648pub const SIGILL: c_int = 4;
649pub const SIGTRAP: c_int = 5;
650pub const SIGABRT: c_int = 6;
651pub const SIGBUS: c_int = 7;
652pub const SIGFPE: c_int = 8;
653pub const SIGKILL: c_int = 9;
654pub const SIGUSR1: c_int = 10;
655pub const SIGSEGV: c_int = 11;
656pub const SIGUSR2: c_int = 12;
657pub const SIGPIPE: c_int = 13;
658pub const SIGALRM: c_int = 14;
659pub const SIGTERM: c_int = 15;
660pub const SIGSTKFLT: c_int = 16;
661pub const SIGCHLD: c_int = 17;
662pub const SIGCONT: c_int = 18;
663pub const SIGSTOP: c_int = 19;
664pub const SIGTSTP: c_int = 20;
665pub const SIGTTIN: c_int = 21;
666pub const SIGTTOU: c_int = 22;
667pub const SIGURG: c_int = 23;
668pub const SIGXCPU: c_int = 24;
669pub const SIGXFSZ: c_int = 25;
670pub const SIGVTALRM: c_int = 26;
671pub const SIGPROF: c_int = 27;
672pub const SIGWINCH: c_int = 28;
673pub const SIGIO: c_int = 29;
674pub const SIGPWR: c_int = 30;
675pub const SIGSYS: c_int = 31;
676pub const NSIG: c_int = 32;
677
678pub const SA_NOCLDWAIT: c_int = 0x0000_0002;
679pub const SA_RESTORER: c_int = 0x0000_0004; // FIXME(redox): remove after relibc removes it
680pub const SA_SIGINFO: c_int = 0x0200_0000;
681pub const SA_ONSTACK: c_int = 0x0400_0000;
682pub const SA_RESTART: c_int = 0x0800_0000;
683pub const SA_NODEFER: c_int = 0x1000_0000;
684pub const SA_RESETHAND: c_int = 0x2000_0000;
685pub const SA_NOCLDSTOP: c_int = 0x4000_0000;
686
687// sys/file.h
688pub const LOCK_SH: c_int = 1;
689pub const LOCK_EX: c_int = 2;
690pub const LOCK_NB: c_int = 4;
691pub const LOCK_UN: c_int = 8;
692
693// sys/epoll.h
694pub const EPOLL_CLOEXEC: c_int = 0x0100_0000;
695pub const EPOLL_CTL_ADD: c_int = 1;
696pub const EPOLL_CTL_DEL: c_int = 2;
697pub const EPOLL_CTL_MOD: c_int = 3;
698pub const EPOLLIN: c_int = 0x001;
699pub const EPOLLPRI: c_int = 0x002;
700pub const EPOLLOUT: c_int = 0x004;
701pub const EPOLLERR: c_int = 0x008;
702pub const EPOLLHUP: c_int = 0x010;
703pub const EPOLLNVAL: c_int = 0x020;
704pub const EPOLLRDNORM: c_int = 0x040;
705pub const EPOLLRDBAND: c_int = 0x080;
706pub const EPOLLWRNORM: c_int = 0x100;
707pub const EPOLLWRBAND: c_int = 0x200;
708pub const EPOLLMSG: c_int = 0x400;
709pub const EPOLLRDHUP: c_int = 0x2000;
710pub const EPOLLEXCLUSIVE: c_int = 1 << 28;
711pub const EPOLLWAKEUP: c_int = 1 << 29;
712pub const EPOLLONESHOT: c_int = 1 << 30;
713pub const EPOLLET: c_int = 1 << 31;
714
715// sys/stat.h
716pub const S_IFMT: c_int = 0o17_0000;
717pub const S_IFDIR: c_int = 0o4_0000;
718pub const S_IFCHR: c_int = 0o2_0000;
719pub const S_IFBLK: c_int = 0o6_0000;
720pub const S_IFREG: c_int = 0o10_0000;
721pub const S_IFIFO: c_int = 0o1_0000;
722pub const S_IFLNK: c_int = 0o12_0000;
723pub const S_IFSOCK: c_int = 0o14_0000;
724pub const S_IRWXU: c_int = 0o0700;
725pub const S_IRUSR: c_int = 0o0400;
726pub const S_IWUSR: c_int = 0o0200;
727pub const S_IXUSR: c_int = 0o0100;
728pub const S_IRWXG: c_int = 0o0070;
729pub const S_IRGRP: c_int = 0o0040;
730pub const S_IWGRP: c_int = 0o0020;
731pub const S_IXGRP: c_int = 0o0010;
732pub const S_IRWXO: c_int = 0o0007;
733pub const S_IROTH: c_int = 0o0004;
734pub const S_IWOTH: c_int = 0o0002;
735pub const S_IXOTH: c_int = 0o0001;
736pub const UTIME_NOW: c_long = u32_cast_long(0xffffffff);
737pub const UTIME_OMIT: c_long = u32_cast_long(0xfffffffe);
738
739// stdlib.h
740pub const EXIT_SUCCESS: c_int = 0;
741pub const EXIT_FAILURE: c_int = 1;
742
743// sys/ioctl.h
744// FIXME(redox): relibc {
745pub const FIONREAD: c_ulong = 0x541B;
746pub const FIONBIO: c_ulong = 0x5421;
747pub const FIOCLEX: c_ulong = 0x5451;
748// }
749pub const TCGETS: c_ulong = 0x5401;
750pub const TCSETS: c_ulong = 0x5402;
751pub const TCFLSH: c_ulong = 0x540B;
752pub const TIOCSCTTY: c_ulong = 0x540E;
753pub const TIOCGPGRP: c_ulong = 0x540F;
754pub const TIOCSPGRP: c_ulong = 0x5410;
755pub const TIOCGWINSZ: c_ulong = 0x5413;
756pub const TIOCSWINSZ: c_ulong = 0x5414;
757
758// sys/mman.h
759pub const PROT_NONE: c_int = 0x0000;
760pub const PROT_READ: c_int = 0x0004;
761pub const PROT_WRITE: c_int = 0x0002;
762pub const PROT_EXEC: c_int = 0x0001;
763
764pub const MADV_NORMAL: c_int = 0;
765pub const MADV_RANDOM: c_int = 1;
766pub const MADV_SEQUENTIAL: c_int = 2;
767pub const MADV_WILLNEED: c_int = 3;
768pub const MADV_DONTNEED: c_int = 4;
769
770pub const MAP_SHARED: c_int = 0x0001;
771pub const MAP_PRIVATE: c_int = 0x0002;
772pub const MAP_ANON: c_int = 0x0020;
773pub const MAP_ANONYMOUS: c_int = MAP_ANON;
774pub const MAP_FIXED: c_int = 0x0004;
775pub const MAP_FAILED: *mut c_void = !0 as _;
776
777pub const MS_ASYNC: c_int = 0x0001;
778pub const MS_INVALIDATE: c_int = 0x0002;
779pub const MS_SYNC: c_int = 0x0004;
780
781// sys/resource.h
782pub const RLIM_INFINITY: rlim_t = !0;
783pub const RLIM_SAVED_CUR: rlim_t = RLIM_INFINITY;
784pub const RLIM_SAVED_MAX: rlim_t = RLIM_INFINITY;
785pub const RLIMIT_CPU: c_int = 0;
786pub const RLIMIT_FSIZE: c_int = 1;
787pub const RLIMIT_DATA: c_int = 2;
788pub const RLIMIT_STACK: c_int = 3;
789pub const RLIMIT_CORE: c_int = 4;
790pub const RLIMIT_RSS: c_int = 5;
791pub const RLIMIT_NPROC: c_int = 6;
792pub const RLIMIT_NOFILE: c_int = 7;
793pub const RLIMIT_MEMLOCK: c_int = 8;
794pub const RLIMIT_AS: c_int = 9;
795pub const RLIMIT_LOCKS: c_int = 10;
796pub const RLIMIT_SIGPENDING: c_int = 11;
797pub const RLIMIT_MSGQUEUE: c_int = 12;
798pub const RLIMIT_NICE: c_int = 13;
799pub const RLIMIT_RTPRIO: c_int = 14;
800pub const RLIMIT_NLIMITS: c_int = 15;
801
802pub const RUSAGE_SELF: c_int = 0;
803pub const RUSAGE_CHILDREN: c_int = -1;
804pub const RUSAGE_BOTH: c_int = -2;
805pub const RUSAGE_THREAD: c_int = 1;
806
807// sys/select.h
808pub const FD_SETSIZE: usize = 1024;
809
810// sys/socket.h
811pub const AF_INET: c_int = 2;
812pub const AF_INET6: c_int = 10;
813pub const AF_UNIX: c_int = 1;
814pub const AF_UNSPEC: c_int = 0;
815pub const PF_INET: c_int = 2;
816pub const PF_INET6: c_int = 10;
817pub const PF_UNIX: c_int = 1;
818pub const PF_UNSPEC: c_int = 0;
819pub const MSG_CTRUNC: c_int = 8;
820pub const MSG_DONTROUTE: c_int = 4;
821pub const MSG_EOR: c_int = 128;
822pub const MSG_OOB: c_int = 1;
823pub const MSG_PEEK: c_int = 2;
824pub const MSG_TRUNC: c_int = 32;
825pub const MSG_DONTWAIT: c_int = 64;
826pub const MSG_WAITALL: c_int = 256;
827pub const SCM_RIGHTS: c_int = 1;
828pub const SHUT_RD: c_int = 0;
829pub const SHUT_WR: c_int = 1;
830pub const SHUT_RDWR: c_int = 2;
831pub const SO_DEBUG: c_int = 1;
832pub const SO_REUSEADDR: c_int = 2;
833pub const SO_TYPE: c_int = 3;
834pub const SO_ERROR: c_int = 4;
835pub const SO_DONTROUTE: c_int = 5;
836pub const SO_BROADCAST: c_int = 6;
837pub const SO_SNDBUF: c_int = 7;
838pub const SO_RCVBUF: c_int = 8;
839pub const SO_KEEPALIVE: c_int = 9;
840pub const SO_OOBINLINE: c_int = 10;
841pub const SO_NO_CHECK: c_int = 11;
842pub const SO_PRIORITY: c_int = 12;
843pub const SO_LINGER: c_int = 13;
844pub const SO_BSDCOMPAT: c_int = 14;
845pub const SO_REUSEPORT: c_int = 15;
846pub const SO_PASSCRED: c_int = 16;
847pub const SO_PEERCRED: c_int = 17;
848pub const SO_RCVLOWAT: c_int = 18;
849pub const SO_SNDLOWAT: c_int = 19;
850pub const SO_RCVTIMEO: c_int = 20;
851pub const SO_SNDTIMEO: c_int = 21;
852pub const SO_ACCEPTCONN: c_int = 30;
853pub const SO_PEERSEC: c_int = 31;
854pub const SO_SNDBUFFORCE: c_int = 32;
855pub const SO_RCVBUFFORCE: c_int = 33;
856pub const SO_PROTOCOL: c_int = 38;
857pub const SO_DOMAIN: c_int = 39;
858pub const SOCK_STREAM: c_int = 1;
859pub const SOCK_DGRAM: c_int = 2;
860pub const SOCK_RAW: c_int = 3;
861pub const SOCK_NONBLOCK: c_int = 0o4_000;
862pub const SOCK_CLOEXEC: c_int = 0o2_000_000;
863pub const SOCK_SEQPACKET: c_int = 5;
864pub const SOL_SOCKET: c_int = 1;
865pub const SOMAXCONN: c_int = 128;
866
867// sys/termios.h
868pub const VEOF: usize = 0;
869pub const VEOL: usize = 1;
870pub const VEOL2: usize = 2;
871pub const VERASE: usize = 3;
872pub const VWERASE: usize = 4;
873pub const VKILL: usize = 5;
874pub const VREPRINT: usize = 6;
875pub const VSWTC: usize = 7;
876pub const VINTR: usize = 8;
877pub const VQUIT: usize = 9;
878pub const VSUSP: usize = 10;
879pub const VSTART: usize = 12;
880pub const VSTOP: usize = 13;
881pub const VLNEXT: usize = 14;
882pub const VDISCARD: usize = 15;
883pub const VMIN: usize = 16;
884pub const VTIME: usize = 17;
885pub const NCCS: usize = 32;
886
887pub const IGNBRK: crate::tcflag_t = 0o000_001;
888pub const BRKINT: crate::tcflag_t = 0o000_002;
889pub const IGNPAR: crate::tcflag_t = 0o000_004;
890pub const PARMRK: crate::tcflag_t = 0o000_010;
891pub const INPCK: crate::tcflag_t = 0o000_020;
892pub const ISTRIP: crate::tcflag_t = 0o000_040;
893pub const INLCR: crate::tcflag_t = 0o000_100;
894pub const IGNCR: crate::tcflag_t = 0o000_200;
895pub const ICRNL: crate::tcflag_t = 0o000_400;
896pub const IXON: crate::tcflag_t = 0o001_000;
897pub const IXOFF: crate::tcflag_t = 0o002_000;
898
899pub const OPOST: crate::tcflag_t = 0o000_001;
900pub const ONLCR: crate::tcflag_t = 0o000_002;
901pub const OLCUC: crate::tcflag_t = 0o000_004;
902pub const OCRNL: crate::tcflag_t = 0o000_010;
903pub const ONOCR: crate::tcflag_t = 0o000_020;
904pub const ONLRET: crate::tcflag_t = 0o000_040;
905pub const OFILL: crate::tcflag_t = 0o0000_100;
906pub const OFDEL: crate::tcflag_t = 0o0000_200;
907
908pub const B0: speed_t = 0o000_000;
909pub const B50: speed_t = 0o000_001;
910pub const B75: speed_t = 0o000_002;
911pub const B110: speed_t = 0o000_003;
912pub const B134: speed_t = 0o000_004;
913pub const B150: speed_t = 0o000_005;
914pub const B200: speed_t = 0o000_006;
915pub const B300: speed_t = 0o000_007;
916pub const B600: speed_t = 0o000_010;
917pub const B1200: speed_t = 0o000_011;
918pub const B1800: speed_t = 0o000_012;
919pub const B2400: speed_t = 0o000_013;
920pub const B4800: speed_t = 0o000_014;
921pub const B9600: speed_t = 0o000_015;
922pub const B19200: speed_t = 0o000_016;
923pub const B38400: speed_t = 0o000_017;
924
925pub const B57600: speed_t = 0o0_020;
926pub const B115200: speed_t = 0o0_021;
927pub const B230400: speed_t = 0o0_022;
928pub const B460800: speed_t = 0o0_023;
929pub const B500000: speed_t = 0o0_024;
930pub const B576000: speed_t = 0o0_025;
931pub const B921600: speed_t = 0o0_026;
932pub const B1000000: speed_t = 0o0_027;
933pub const B1152000: speed_t = 0o0_030;
934pub const B1500000: speed_t = 0o0_031;
935pub const B2000000: speed_t = 0o0_032;
936pub const B2500000: speed_t = 0o0_033;
937pub const B3000000: speed_t = 0o0_034;
938pub const B3500000: speed_t = 0o0_035;
939pub const B4000000: speed_t = 0o0_036;
940
941pub const CSIZE: crate::tcflag_t = 0o001_400;
942pub const CS5: crate::tcflag_t = 0o000_000;
943pub const CS6: crate::tcflag_t = 0o000_400;
944pub const CS7: crate::tcflag_t = 0o001_000;
945pub const CS8: crate::tcflag_t = 0o001_400;
946
947pub const CSTOPB: crate::tcflag_t = 0o002_000;
948pub const CREAD: crate::tcflag_t = 0o004_000;
949pub const PARENB: crate::tcflag_t = 0o010_000;
950pub const PARODD: crate::tcflag_t = 0o020_000;
951pub const HUPCL: crate::tcflag_t = 0o040_000;
952
953pub const CLOCAL: crate::tcflag_t = 0o0100000;
954
955pub const ISIG: crate::tcflag_t = 0x0000_0080;
956pub const ICANON: crate::tcflag_t = 0x0000_0100;
957pub const ECHO: crate::tcflag_t = 0x0000_0008;
958pub const ECHOE: crate::tcflag_t = 0x0000_0002;
959pub const ECHOK: crate::tcflag_t = 0x0000_0004;
960pub const ECHONL: crate::tcflag_t = 0x0000_0010;
961pub const NOFLSH: crate::tcflag_t = 0x8000_0000;
962pub const TOSTOP: crate::tcflag_t = 0x0040_0000;
963pub const IEXTEN: crate::tcflag_t = 0x0000_0400;
964
965pub const TCOOFF: c_int = 0;
966pub const TCOON: c_int = 1;
967pub const TCIOFF: c_int = 2;
968pub const TCION: c_int = 3;
969
970pub const TCIFLUSH: c_int = 0;
971pub const TCOFLUSH: c_int = 1;
972pub const TCIOFLUSH: c_int = 2;
973
974pub const TCSANOW: c_int = 0;
975pub const TCSADRAIN: c_int = 1;
976pub const TCSAFLUSH: c_int = 2;
977
978pub const _POSIX_VDISABLE: crate::cc_t = 0;
979
980// sys/wait.h
981pub const WNOHANG: c_int = 1;
982pub const WUNTRACED: c_int = 2;
983
984pub const WSTOPPED: c_int = 2;
985pub const WEXITED: c_int = 4;
986pub const WCONTINUED: c_int = 8;
987pub const WNOWAIT: c_int = 0x0100_0000;
988
989pub const __WNOTHREAD: c_int = 0x2000_0000;
990pub const __WALL: c_int = 0x4000_0000;
991pub const __WCLONE: c_int = u32_cast_int(0x8000_0000);
992
993// time.h
994pub const CLOCK_REALTIME: c_int = 1;
995pub const CLOCK_MONOTONIC: c_int = 4;
996pub const CLOCK_PROCESS_CPUTIME_ID: crate::clockid_t = 2;
997pub const CLOCKS_PER_SEC: crate::clock_t = 1_000_000;
998
999// unistd.h
1000// POSIX.1 {
1001pub const _SC_ARG_MAX: c_int = 0;
1002pub const _SC_CHILD_MAX: c_int = 1;
1003pub const _SC_CLK_TCK: c_int = 2;
1004pub const _SC_NGROUPS_MAX: c_int = 3;
1005pub const _SC_OPEN_MAX: c_int = 4;
1006pub const _SC_STREAM_MAX: c_int = 5;
1007pub const _SC_TZNAME_MAX: c_int = 6;
1008// ...
1009pub const _SC_VERSION: c_int = 29;
1010pub const _SC_PAGESIZE: c_int = 30;
1011pub const _SC_PAGE_SIZE: c_int = 30;
1012// ...
1013pub const _SC_RE_DUP_MAX: c_int = 44;
1014
1015pub const _SC_NPROCESSORS_CONF: c_int = 57;
1016pub const _SC_NPROCESSORS_ONLN: c_int = 58;
1017
1018// ...
1019pub const _SC_GETGR_R_SIZE_MAX: c_int = 69;
1020pub const _SC_GETPW_R_SIZE_MAX: c_int = 70;
1021pub const _SC_LOGIN_NAME_MAX: c_int = 71;
1022pub const _SC_TTY_NAME_MAX: c_int = 72;
1023// ...
1024pub const _SC_SYMLOOP_MAX: c_int = 173;
1025// ...
1026pub const _SC_HOST_NAME_MAX: c_int = 180;
1027// ...
1028pub const _SC_SIGQUEUE_MAX: c_int = 190;
1029pub const _SC_REALTIME_SIGNALS: c_int = 191;
1030// } POSIX.1
1031
1032// confstr
1033pub const _CS_PATH: c_int = 0;
1034pub const _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS: c_int = 1;
1035pub const _CS_POSIX_V5_WIDTH_RESTRICTED_ENVS: c_int = 4;
1036pub const _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS: c_int = 5;
1037pub const _CS_POSIX_V6_ILP32_OFF32_CFLAGS: c_int = 1116;
1038pub const _CS_POSIX_V6_ILP32_OFF32_LDFLAGS: c_int = 1117;
1039pub const _CS_POSIX_V6_ILP32_OFF32_LIBS: c_int = 1118;
1040pub const _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS: c_int = 1119;
1041pub const _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS: c_int = 1120;
1042pub const _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS: c_int = 1121;
1043pub const _CS_POSIX_V6_ILP32_OFFBIG_LIBS: c_int = 1122;
1044pub const _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS: c_int = 1123;
1045pub const _CS_POSIX_V6_LP64_OFF64_CFLAGS: c_int = 1124;
1046pub const _CS_POSIX_V6_LP64_OFF64_LDFLAGS: c_int = 1125;
1047pub const _CS_POSIX_V6_LP64_OFF64_LIBS: c_int = 1126;
1048pub const _CS_POSIX_V6_LP64_OFF64_LINTFLAGS: c_int = 1127;
1049pub const _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS: c_int = 1128;
1050pub const _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS: c_int = 1129;
1051pub const _CS_POSIX_V6_LPBIG_OFFBIG_LIBS: c_int = 1130;
1052pub const _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS: c_int = 1131;
1053pub const _CS_POSIX_V7_ILP32_OFF32_CFLAGS: c_int = 1132;
1054pub const _CS_POSIX_V7_ILP32_OFF32_LDFLAGS: c_int = 1133;
1055pub const _CS_POSIX_V7_ILP32_OFF32_LIBS: c_int = 1134;
1056pub const _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS: c_int = 1135;
1057pub const _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS: c_int = 1136;
1058pub const _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS: c_int = 1137;
1059pub const _CS_POSIX_V7_ILP32_OFFBIG_LIBS: c_int = 1138;
1060pub const _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS: c_int = 1139;
1061pub const _CS_POSIX_V7_LP64_OFF64_CFLAGS: c_int = 1140;
1062pub const _CS_POSIX_V7_LP64_OFF64_LDFLAGS: c_int = 1141;
1063pub const _CS_POSIX_V7_LP64_OFF64_LIBS: c_int = 1142;
1064pub const _CS_POSIX_V7_LP64_OFF64_LINTFLAGS: c_int = 1143;
1065pub const _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS: c_int = 1144;
1066pub const _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS: c_int = 1145;
1067pub const _CS_POSIX_V7_LPBIG_OFFBIG_LIBS: c_int = 1146;
1068pub const _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS: c_int = 1147;
1069
1070pub const F_OK: c_int = 0;
1071pub const R_OK: c_int = 4;
1072pub const W_OK: c_int = 2;
1073pub const X_OK: c_int = 1;
1074
1075// stdio.h
1076pub const BUFSIZ: c_uint = 1024;
1077pub const _IOFBF: c_int = 0;
1078pub const _IOLBF: c_int = 1;
1079pub const _IONBF: c_int = 2;
1080pub const SEEK_SET: c_int = 0;
1081pub const SEEK_CUR: c_int = 1;
1082pub const SEEK_END: c_int = 2;
1083
1084pub const _PC_LINK_MAX: c_int = 0;
1085pub const _PC_MAX_CANON: c_int = 1;
1086pub const _PC_MAX_INPUT: c_int = 2;
1087pub const _PC_NAME_MAX: c_int = 3;
1088pub const _PC_PATH_MAX: c_int = 4;
1089pub const _PC_PIPE_BUF: c_int = 5;
1090pub const _PC_CHOWN_RESTRICTED: c_int = 6;
1091pub const _PC_NO_TRUNC: c_int = 7;
1092pub const _PC_VDISABLE: c_int = 8;
1093pub const _PC_SYNC_IO: c_int = 9;
1094pub const _PC_ASYNC_IO: c_int = 10;
1095pub const _PC_PRIO_IO: c_int = 11;
1096pub const _PC_SOCK_MAXBUF: c_int = 12;
1097pub const _PC_FILESIZEBITS: c_int = 13;
1098pub const _PC_REC_INCR_XFER_SIZE: c_int = 14;
1099pub const _PC_REC_MAX_XFER_SIZE: c_int = 15;
1100pub const _PC_REC_MIN_XFER_SIZE: c_int = 16;
1101pub const _PC_REC_XFER_ALIGN: c_int = 17;
1102pub const _PC_ALLOC_SIZE_MIN: c_int = 18;
1103pub const _PC_SYMLINK_MAX: c_int = 19;
1104pub const _PC_2_SYMLINKS: c_int = 20;
1105
1106pub const PRIO_PROCESS: c_int = 0;
1107pub const PRIO_PGRP: c_int = 1;
1108pub const PRIO_USER: c_int = 2;
1109
1110pub const RENAME_NOREPLACE: c_uint = 1;
1111
1112f! {
1113 //sys/socket.h
1114 pub const unsafe fn CMSG_ALIGN(len: size_t) -> size_t {
1115 (len + size_of::<size_t>() - 1) & !(size_of::<size_t>() - 1)
1116 }
1117 pub const unsafe fn CMSG_LEN(length: c_uint) -> c_uint {
1118 (CMSG_ALIGN(size_of::<cmsghdr>()) + length as usize) as c_uint
1119 }
1120 pub const unsafe fn CMSG_SPACE(len: c_uint) -> c_uint {
1121 (CMSG_ALIGN(len as size_t) + CMSG_ALIGN(size_of::<cmsghdr>())) as c_uint
1122 }
1123
1124 // wait.h
1125 pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () {
1126 let fd = fd as usize;
1127 let size = size_of_val(&(*set).fds_bits[0]) * 8;
1128 (*set).fds_bits[fd / size] &= !(1 << (fd % size));
1129 return;
1130 }
1131
1132 pub unsafe fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool {
1133 let fd = fd as usize;
1134 let size = size_of_val(&(*set).fds_bits[0]) * 8;
1135 return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0;
1136 }
1137
1138 pub unsafe fn FD_SET(fd: c_int, set: *mut fd_set) -> () {
1139 let fd = fd as usize;
1140 let size = size_of_val(&(*set).fds_bits[0]) * 8;
1141 (*set).fds_bits[fd / size] |= 1 << (fd % size);
1142 return;
1143 }
1144
1145 pub unsafe fn FD_ZERO(set: *mut fd_set) -> () {
1146 (*set).fds_bits.fill(0);
1147 }
1148}
1149
1150safe_f! {
1151 pub const safe fn WIFSTOPPED(status: c_int) -> bool {
1152 (status & 0xff) == 0x7f
1153 }
1154
1155 pub const safe fn WSTOPSIG(status: c_int) -> c_int {
1156 (status >> 8) & 0xff
1157 }
1158
1159 pub const safe fn WIFCONTINUED(status: c_int) -> bool {
1160 status == 0xffff
1161 }
1162
1163 pub const safe fn WIFSIGNALED(status: c_int) -> bool {
1164 ((status & 0x7f) + 1) as i8 >= 2
1165 }
1166
1167 pub const safe fn WTERMSIG(status: c_int) -> c_int {
1168 status & 0x7f
1169 }
1170
1171 pub const safe fn WIFEXITED(status: c_int) -> bool {
1172 (status & 0x7f) == 0
1173 }
1174
1175 pub const safe fn WEXITSTATUS(status: c_int) -> c_int {
1176 (status >> 8) & 0xff
1177 }
1178
1179 pub const safe fn WCOREDUMP(status: c_int) -> bool {
1180 (status & 0x80) != 0
1181 }
1182
1183 pub const safe fn makedev(major: c_uint, minor: c_uint) -> dev_t {
1184 let major = major as dev_t;
1185 let minor = minor as dev_t;
1186 let mut dev = 0;
1187 dev |= (major & 0x00000fff) << 8;
1188 dev |= (major & 0xfffff000) << 32;
1189 dev |= (minor & 0x000000ff) << 0;
1190 dev |= (minor & 0xffffff00) << 12;
1191 dev
1192 }
1193
1194 pub const safe fn major(dev: dev_t) -> c_uint {
1195 let mut major = 0;
1196 major |= (dev & 0x00000000000fff00) >> 8;
1197 major |= (dev & 0xfffff00000000000) >> 32;
1198 major as c_uint
1199 }
1200
1201 pub const safe fn minor(dev: dev_t) -> c_uint {
1202 let mut minor = 0;
1203 minor |= (dev & 0x00000000000000ff) >> 0;
1204 minor |= (dev & 0x00000ffffff00000) >> 12;
1205 minor as c_uint
1206 }
1207}
1208
1209extern "C" {
1210 // errno.h
1211 pub fn __errno_location() -> *mut c_int;
1212 pub fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: size_t) -> c_int;
1213
1214 // dirent.h
1215 pub fn dirfd(dirp: *mut crate::DIR) -> c_int;
1216 pub fn seekdir(dirp: *mut crate::DIR, loc: c_long);
1217
1218 // unistd.h
1219 pub fn faccessat(dirfd: c_int, pathname: *const c_char, mode: c_int, flags: c_int) -> c_int;
1220 pub fn pipe2(fds: *mut c_int, flags: c_int) -> c_int;
1221 pub fn getdtablesize() -> c_int;
1222 pub fn getresgid(
1223 rgid: *mut crate::gid_t,
1224 egid: *mut crate::gid_t,
1225 sgid: *mut crate::gid_t,
1226 ) -> c_int;
1227 pub fn getresuid(
1228 ruid: *mut crate::uid_t,
1229 euid: *mut crate::uid_t,
1230 suid: *mut crate::uid_t,
1231 ) -> c_int;
1232 pub fn setresgid(rgid: crate::gid_t, egid: crate::gid_t, sgid: crate::gid_t) -> c_int;
1233 pub fn setresuid(ruid: crate::uid_t, euid: crate::uid_t, suid: crate::uid_t) -> c_int;
1234
1235 // grp.h
1236 pub fn getgrent() -> *mut crate::group;
1237 pub fn setgrent();
1238 pub fn endgrent();
1239 pub fn getgrgid(gid: crate::gid_t) -> *mut crate::group;
1240 pub fn getgrgid_r(
1241 gid: crate::gid_t,
1242 grp: *mut crate::group,
1243 buf: *mut c_char,
1244 buflen: size_t,
1245 result: *mut *mut crate::group,
1246 ) -> c_int;
1247 pub fn getgrnam(name: *const c_char) -> *mut crate::group;
1248 pub fn getgrnam_r(
1249 name: *const c_char,
1250 grp: *mut crate::group,
1251 buf: *mut c_char,
1252 buflen: size_t,
1253 result: *mut *mut crate::group,
1254 ) -> c_int;
1255 pub fn getgrouplist(
1256 user: *const c_char,
1257 group: crate::gid_t,
1258 groups: *mut crate::gid_t,
1259 ngroups: *mut c_int,
1260 ) -> c_int;
1261
1262 // malloc.h
1263 pub fn memalign(align: size_t, size: size_t) -> *mut c_void;
1264
1265 // netdb.h
1266 pub fn getnameinfo(
1267 addr: *const crate::sockaddr,
1268 addrlen: crate::socklen_t,
1269 host: *mut c_char,
1270 hostlen: crate::socklen_t,
1271 serv: *mut c_char,
1272 servlen: crate::socklen_t,
1273 flags: c_int,
1274 ) -> c_int;
1275
1276 // pthread.h
1277 pub fn pthread_atfork(
1278 prepare: Option<unsafe extern "C" fn()>,
1279 parent: Option<unsafe extern "C" fn()>,
1280 child: Option<unsafe extern "C" fn()>,
1281 ) -> c_int;
1282 pub fn pthread_create(
1283 tid: *mut crate::pthread_t,
1284 attr: *const crate::pthread_attr_t,
1285 start: extern "C" fn(*mut c_void) -> *mut c_void,
1286 arg: *mut c_void,
1287 ) -> c_int;
1288 pub fn pthread_condattr_setclock(
1289 attr: *mut pthread_condattr_t,
1290 clock_id: crate::clockid_t,
1291 ) -> c_int;
1292
1293 //pty.h
1294 pub fn openpty(
1295 amaster: *mut c_int,
1296 aslave: *mut c_int,
1297 name: *mut c_char,
1298 termp: *const termios,
1299 winp: *const crate::winsize,
1300 ) -> c_int;
1301
1302 // pwd.h
1303 pub fn getpwent() -> *mut passwd;
1304 pub fn setpwent();
1305 pub fn endpwent();
1306 pub fn getpwnam_r(
1307 name: *const c_char,
1308 pwd: *mut passwd,
1309 buf: *mut c_char,
1310 buflen: size_t,
1311 result: *mut *mut passwd,
1312 ) -> c_int;
1313 pub fn getpwuid_r(
1314 uid: crate::uid_t,
1315 pwd: *mut passwd,
1316 buf: *mut c_char,
1317 buflen: size_t,
1318 result: *mut *mut passwd,
1319 ) -> c_int;
1320
1321 // semaphore.h
1322 pub fn sem_destroy(sem: *mut sem_t) -> c_int;
1323 pub fn sem_init(sem: *mut sem_t, pshared: c_int, value: c_uint) -> c_int;
1324 pub fn sem_clockwait(
1325 sem: *mut sem_t,
1326 clock_id: clockid_t,
1327 abstime: *const crate::timespec,
1328 ) -> c_int;
1329 pub fn sem_timedwait(sem: *mut sem_t, abstime: *const crate::timespec) -> c_int;
1330 pub fn sem_getvalue(sem: *mut sem_t, sval: *mut c_int) -> c_int;
1331
1332 // signal.h
1333 pub fn pthread_sigmask(
1334 how: c_int,
1335 set: *const crate::sigset_t,
1336 oldset: *mut crate::sigset_t,
1337 ) -> c_int;
1338 pub fn pthread_cancel(thread: crate::pthread_t) -> c_int;
1339 pub fn pthread_kill(thread: crate::pthread_t, sig: c_int) -> c_int;
1340 pub fn sigtimedwait(
1341 set: *const sigset_t,
1342 sig: *mut siginfo_t,
1343 timeout: *const crate::timespec,
1344 ) -> c_int;
1345 pub fn sigwait(set: *const sigset_t, sig: *mut c_int) -> c_int;
1346
1347 // stdlib.h
1348 pub fn getsubopt(
1349 optionp: *mut *mut c_char,
1350 tokens: *const *mut c_char,
1351 valuep: *mut *mut c_char,
1352 ) -> c_int;
1353 pub fn mkostemp(template: *mut c_char, flags: c_int) -> c_int;
1354 pub fn mkostemps(template: *mut c_char, suffixlen: c_int, flags: c_int) -> c_int;
1355 pub fn reallocarray(ptr: *mut c_void, nmemb: size_t, size: size_t) -> *mut c_void;
1356
1357 // stdio.h
1358 pub fn renameat2(
1359 olddirfd: c_int,
1360 oldpath: *const c_char,
1361 newdirfd: c_int,
1362 newpath: *const c_char,
1363 flags: c_uint,
1364 ) -> c_int;
1365
1366 // string.h
1367 pub fn explicit_bzero(p: *mut c_void, len: size_t);
1368 pub fn strlcat(dst: *mut c_char, src: *const c_char, siz: size_t) -> size_t;
1369 pub fn strlcpy(dst: *mut c_char, src: *const c_char, siz: size_t) -> size_t;
1370
1371 // sys/epoll.h
1372 pub fn epoll_create(size: c_int) -> c_int;
1373 pub fn epoll_create1(flags: c_int) -> c_int;
1374 pub fn epoll_wait(
1375 epfd: c_int,
1376 events: *mut crate::epoll_event,
1377 maxevents: c_int,
1378 timeout: c_int,
1379 ) -> c_int;
1380 pub fn epoll_ctl(epfd: c_int, op: c_int, fd: c_int, event: *mut crate::epoll_event) -> c_int;
1381
1382 // sys/ioctl.h
1383 pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int;
1384
1385 // sys/mman.h
1386 pub fn madvise(addr: *mut c_void, len: size_t, advice: c_int) -> c_int;
1387 pub fn msync(addr: *mut c_void, len: size_t, flags: c_int) -> c_int;
1388 pub fn mprotect(addr: *mut c_void, len: size_t, prot: c_int) -> c_int;
1389 pub fn shm_open(name: *const c_char, oflag: c_int, mode: mode_t) -> c_int;
1390 pub fn shm_unlink(name: *const c_char) -> c_int;
1391
1392 // sys/resource.h
1393 pub fn getpriority(which: c_int, who: crate::id_t) -> c_int;
1394 pub fn setpriority(which: c_int, who: crate::id_t, prio: c_int) -> c_int;
1395 pub fn getrlimit(resource: c_int, rlim: *mut crate::rlimit) -> c_int;
1396 pub fn setrlimit(resource: c_int, rlim: *const crate::rlimit) -> c_int;
1397
1398 // sys/socket.h
1399 pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar;
1400 pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr;
1401 pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr;
1402 pub fn bind(
1403 socket: c_int,
1404 address: *const crate::sockaddr,
1405 address_len: crate::socklen_t,
1406 ) -> c_int;
1407 pub fn recvfrom(
1408 socket: c_int,
1409 buf: *mut c_void,
1410 len: size_t,
1411 flags: c_int,
1412 addr: *mut crate::sockaddr,
1413 addrlen: *mut crate::socklen_t,
1414 ) -> ssize_t;
1415 pub fn recvmsg(socket: c_int, msg: *mut msghdr, flags: c_int) -> ssize_t;
1416 pub fn sendmsg(socket: c_int, msg: *const msghdr, flags: c_int) -> ssize_t;
1417
1418 // sys/stat.h
1419 pub fn futimens(fd: c_int, times: *const crate::timespec) -> c_int;
1420 pub fn mknodat(dirfd: c_int, pathname: *const c_char, mode: mode_t, dev: dev_t) -> c_int;
1421 pub fn utimensat(
1422 dirfd: c_int,
1423 path: *const c_char,
1424 times: *const crate::timespec,
1425 flag: c_int,
1426 ) -> c_int;
1427
1428 // sys/uio.h
1429 pub fn preadv(fd: c_int, iov: *const crate::iovec, iovcnt: c_int, offset: off_t) -> ssize_t;
1430 pub fn pwritev(fd: c_int, iov: *const crate::iovec, iovcnt: c_int, offset: off_t) -> ssize_t;
1431 pub fn readv(fd: c_int, iov: *const crate::iovec, iovcnt: c_int) -> ssize_t;
1432 pub fn writev(fd: c_int, iov: *const crate::iovec, iovcnt: c_int) -> ssize_t;
1433
1434 // sys/utsname.h
1435 pub fn uname(utsname: *mut utsname) -> c_int;
1436
1437 // time.h
1438 pub fn gettimeofday(tp: *mut crate::timeval, tz: *mut crate::timezone) -> c_int;
1439 pub fn clock_getres(clk_id: crate::clockid_t, tp: *mut crate::timespec) -> c_int;
1440 pub fn clock_gettime(clk_id: crate::clockid_t, tp: *mut crate::timespec) -> c_int;
1441 pub fn strftime(
1442 s: *mut c_char,
1443 max: size_t,
1444 format: *const c_char,
1445 tm: *const crate::tm,
1446 ) -> size_t;
1447
1448 // utmp.h
1449 pub fn login_tty(fd: c_int) -> c_int;
1450}