Debian Codegraph @

third_party/rust/libc/src/unix/redox/mod.rs

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