xref: /rust-libc-0.2.174/src/unix/newlib/mod.rs (revision 66b58759)
1 use crate::prelude::*;
2 
3 pub type blkcnt_t = i32;
4 pub type blksize_t = i32;
5 
6 pub type clockid_t = c_ulong;
7 
8 cfg_if! {
9     if #[cfg(any(target_os = "espidf"))] {
10         pub type dev_t = c_short;
11         pub type ino_t = c_ushort;
12         pub type off_t = c_long;
13     } else if #[cfg(any(target_os = "vita"))] {
14         pub type dev_t = c_short;
15         pub type ino_t = c_ushort;
16         pub type off_t = c_int;
17     } else {
18         pub type dev_t = u32;
19         pub type ino_t = u32;
20         pub type off_t = i64;
21     }
22 }
23 
24 pub type fsblkcnt_t = u64;
25 pub type fsfilcnt_t = u32;
26 pub type id_t = u32;
27 pub type key_t = c_int;
28 pub type loff_t = c_longlong;
29 pub type mode_t = c_uint;
30 pub type nfds_t = u32;
31 pub type nlink_t = c_ushort;
32 pub type pthread_t = c_ulong;
33 pub type pthread_key_t = c_uint;
34 pub type rlim_t = u32;
35 
36 cfg_if! {
37     if #[cfg(target_os = "horizon")] {
38         pub type sa_family_t = u16;
39     } else {
40         pub type sa_family_t = u8;
41     }
42 }
43 
44 pub type socklen_t = u32;
45 pub type speed_t = u32;
46 pub type suseconds_t = i32;
47 cfg_if! {
48     if #[cfg(target_os = "espidf")] {
49         pub type tcflag_t = u16;
50     } else {
51         pub type tcflag_t = c_uint;
52     }
53 }
54 pub type useconds_t = u32;
55 
56 cfg_if! {
57     if #[cfg(any(
58         target_os = "horizon",
59         all(target_os = "espidf", not(espidf_time32))
60     ))] {
61         pub type time_t = c_longlong;
62     } else {
63         pub type time_t = i32;
64     }
65 }
66 
67 cfg_if! {
68     if #[cfg(not(target_os = "horizon"))] {
69         s! {
70             pub struct hostent {
71                 pub h_name: *mut c_char,
72                 pub h_aliases: *mut *mut c_char,
73                 pub h_addrtype: c_int,
74                 pub h_length: c_int,
75                 pub h_addr_list: *mut *mut c_char,
76                 pub h_addr: *mut c_char,
77             }
78         }
79     }
80 }
81 
82 s! {
83     // The order of the `ai_addr` field in this struct is crucial
84     // for converting between the Rust and C types.
85     pub struct addrinfo {
86         pub ai_flags: c_int,
87         pub ai_family: c_int,
88         pub ai_socktype: c_int,
89         pub ai_protocol: c_int,
90         pub ai_addrlen: socklen_t,
91 
92         #[cfg(target_os = "espidf")]
93         pub ai_addr: *mut sockaddr,
94 
95         pub ai_canonname: *mut c_char,
96 
97         #[cfg(not(any(
98             target_os = "espidf",
99             all(target_arch = "powerpc", target_vendor = "nintendo")
100         )))]
101         pub ai_addr: *mut sockaddr,
102 
103         pub ai_next: *mut addrinfo,
104     }
105 
106     pub struct ip_mreq {
107         pub imr_multiaddr: in_addr,
108         pub imr_interface: in_addr,
109     }
110 
111     pub struct linger {
112         pub l_onoff: c_int,
113         pub l_linger: c_int,
114     }
115 
116     pub struct in_addr {
117         pub s_addr: crate::in_addr_t,
118     }
119 
120     pub struct pollfd {
121         pub fd: c_int,
122         pub events: c_int,
123         pub revents: c_int,
124     }
125 
126     pub struct lconv {
127         pub decimal_point: *mut c_char,
128         pub thousands_sep: *mut c_char,
129         pub grouping: *mut c_char,
130         pub int_curr_symbol: *mut c_char,
131         pub currency_symbol: *mut c_char,
132         pub mon_decimal_point: *mut c_char,
133         pub mon_thousands_sep: *mut c_char,
134         pub mon_grouping: *mut c_char,
135         pub positive_sign: *mut c_char,
136         pub negative_sign: *mut c_char,
137         pub int_frac_digits: c_char,
138         pub frac_digits: c_char,
139         pub p_cs_precedes: c_char,
140         pub p_sep_by_space: c_char,
141         pub n_cs_precedes: c_char,
142         pub n_sep_by_space: c_char,
143         pub p_sign_posn: c_char,
144         pub n_sign_posn: c_char,
145         pub int_n_cs_precedes: c_char,
146         pub int_n_sep_by_space: c_char,
147         pub int_n_sign_posn: c_char,
148         pub int_p_cs_precedes: c_char,
149         pub int_p_sep_by_space: c_char,
150         pub int_p_sign_posn: c_char,
151     }
152 
153     pub struct tm {
154         pub tm_sec: c_int,
155         pub tm_min: c_int,
156         pub tm_hour: c_int,
157         pub tm_mday: c_int,
158         pub tm_mon: c_int,
159         pub tm_year: c_int,
160         pub tm_wday: c_int,
161         pub tm_yday: c_int,
162         pub tm_isdst: c_int,
163     }
164 
165     pub struct statvfs {
166         pub f_bsize: c_ulong,
167         pub f_frsize: c_ulong,
168         pub f_blocks: fsblkcnt_t,
169         pub f_bfree: fsblkcnt_t,
170         pub f_bavail: fsblkcnt_t,
171         pub f_files: fsfilcnt_t,
172         pub f_ffree: fsfilcnt_t,
173         pub f_favail: fsfilcnt_t,
174         pub f_fsid: c_ulong,
175         pub f_flag: c_ulong,
176         pub f_namemax: c_ulong,
177     }
178 
179     pub struct sigaction {
180         pub sa_handler: extern "C" fn(arg1: c_int),
181         pub sa_mask: sigset_t,
182         pub sa_flags: c_int,
183     }
184 
185     pub struct stack_t {
186         pub ss_sp: *mut c_void,
187         pub ss_flags: c_int,
188         pub ss_size: usize,
189     }
190 
191     pub struct fd_set {
192         // Unverified
193         fds_bits: [c_ulong; FD_SETSIZE as usize / ULONG_SIZE],
194     }
195 
196     pub struct passwd {
197         // Unverified
198         pub pw_name: *mut c_char,
199         pub pw_passwd: *mut c_char,
200         pub pw_uid: crate::uid_t,
201         pub pw_gid: crate::gid_t,
202         pub pw_gecos: *mut c_char,
203         pub pw_dir: *mut c_char,
204         pub pw_shell: *mut c_char,
205     }
206 
207     pub struct termios {
208         // Unverified
209         pub c_iflag: crate::tcflag_t,
210         pub c_oflag: crate::tcflag_t,
211         pub c_cflag: crate::tcflag_t,
212         pub c_lflag: crate::tcflag_t,
213         pub c_line: crate::cc_t,
214         pub c_cc: [crate::cc_t; crate::NCCS],
215         #[cfg(target_os = "espidf")]
216         pub c_ispeed: u32,
217         #[cfg(target_os = "espidf")]
218         pub c_ospeed: u32,
219     }
220 
221     pub struct sem_t {
222         // Unverified
223         __size: [c_char; 16],
224     }
225 
226     pub struct Dl_info {
227         // Unverified
228         pub dli_fname: *const c_char,
229         pub dli_fbase: *mut c_void,
230         pub dli_sname: *const c_char,
231         pub dli_saddr: *mut c_void,
232     }
233 
234     pub struct utsname {
235         // Unverified
236         pub sysname: [c_char; 65],
237         pub nodename: [c_char; 65],
238         pub release: [c_char; 65],
239         pub version: [c_char; 65],
240         pub machine: [c_char; 65],
241         pub domainname: [c_char; 65],
242     }
243 
244     pub struct cpu_set_t {
245         // Unverified
246         bits: [u32; 32],
247     }
248 
249     pub struct pthread_attr_t {
250         // Unverified
251         #[cfg(not(target_os = "espidf"))]
252         __size: [u8; __SIZEOF_PTHREAD_ATTR_T],
253         #[cfg(target_os = "espidf")]
254         pub is_initialized: i32,
255         #[cfg(target_os = "espidf")]
256         pub stackaddr: *mut c_void,
257         #[cfg(target_os = "espidf")]
258         pub stacksize: i32,
259         #[cfg(target_os = "espidf")]
260         pub contentionscope: i32,
261         #[cfg(target_os = "espidf")]
262         pub inheritsched: i32,
263         #[cfg(target_os = "espidf")]
264         pub schedpolicy: i32,
265         #[cfg(target_os = "espidf")]
266         pub schedparam: i32,
267         #[cfg(target_os = "espidf")]
268         pub detachstate: i32,
269     }
270 
271     pub struct pthread_rwlockattr_t {
272         // Unverified
273         __size: [u8; __SIZEOF_PTHREAD_RWLOCKATTR_T],
274     }
275 
276     #[cfg_attr(
277         all(
278             target_pointer_width = "32",
279             any(target_arch = "mips", target_arch = "arm", target_arch = "powerpc")
280         ),
281         repr(align(4))
282     )]
283     #[cfg_attr(
284         any(
285             target_pointer_width = "64",
286             not(any(target_arch = "mips", target_arch = "arm", target_arch = "powerpc"))
287         ),
288         repr(align(8))
289     )]
290     pub struct pthread_mutex_t {
291         // Unverified
292         size: [u8; crate::__SIZEOF_PTHREAD_MUTEX_T],
293     }
294 
295     #[cfg_attr(
296         all(
297             target_pointer_width = "32",
298             any(target_arch = "mips", target_arch = "arm", target_arch = "powerpc")
299         ),
300         repr(align(4))
301     )]
302     #[cfg_attr(
303         any(
304             target_pointer_width = "64",
305             not(any(target_arch = "mips", target_arch = "arm", target_arch = "powerpc"))
306         ),
307         repr(align(8))
308     )]
309     pub struct pthread_rwlock_t {
310         // Unverified
311         size: [u8; crate::__SIZEOF_PTHREAD_RWLOCK_T],
312     }
313 
314     #[cfg_attr(
315         any(
316             target_pointer_width = "32",
317             target_arch = "x86_64",
318             target_arch = "powerpc64",
319             target_arch = "mips64",
320             target_arch = "s390x",
321             target_arch = "sparc64"
322         ),
323         repr(align(4))
324     )]
325     #[cfg_attr(
326         not(any(
327             target_pointer_width = "32",
328             target_arch = "x86_64",
329             target_arch = "powerpc64",
330             target_arch = "mips64",
331             target_arch = "s390x",
332             target_arch = "sparc64"
333         )),
334         repr(align(8))
335     )]
336     pub struct pthread_mutexattr_t {
337         // Unverified
338         size: [u8; crate::__SIZEOF_PTHREAD_MUTEXATTR_T],
339     }
340 
341     #[repr(align(8))]
342     pub struct pthread_cond_t {
343         // Unverified
344         size: [u8; crate::__SIZEOF_PTHREAD_COND_T],
345     }
346 
347     #[repr(align(4))]
348     pub struct pthread_condattr_t {
349         // Unverified
350         size: [u8; crate::__SIZEOF_PTHREAD_CONDATTR_T],
351     }
352 }
353 
354 // unverified constants
355 pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
356     size: [__PTHREAD_INITIALIZER_BYTE; __SIZEOF_PTHREAD_MUTEX_T],
357 };
358 pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
359     size: [__PTHREAD_INITIALIZER_BYTE; __SIZEOF_PTHREAD_COND_T],
360 };
361 pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
362     size: [__PTHREAD_INITIALIZER_BYTE; __SIZEOF_PTHREAD_RWLOCK_T],
363 };
364 
365 cfg_if! {
366     if #[cfg(target_os = "espidf")] {
367         pub const NCCS: usize = 11;
368     } else {
369         pub const NCCS: usize = 32;
370     }
371 }
372 
373 cfg_if! {
374     if #[cfg(target_os = "espidf")] {
375         const __PTHREAD_INITIALIZER_BYTE: u8 = 0xff;
376         pub const __SIZEOF_PTHREAD_ATTR_T: usize = 32;
377         pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 4;
378         pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 12;
379         pub const __SIZEOF_PTHREAD_COND_T: usize = 4;
380         pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 8;
381         pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 4;
382         pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 12;
383         pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;
384     } else if #[cfg(target_os = "vita")] {
385         const __PTHREAD_INITIALIZER_BYTE: u8 = 0xff;
386         pub const __SIZEOF_PTHREAD_ATTR_T: usize = 4;
387         pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 4;
388         pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
389         pub const __SIZEOF_PTHREAD_COND_T: usize = 4;
390         pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
391         pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 4;
392         pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 4;
393         pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 4;
394     } else if #[cfg(target_os = "rtems")] {
395         const __PTHREAD_INITIALIZER_BYTE: u8 = 0x00;
396         pub const __SIZEOF_PTHREAD_ATTR_T: usize = 96;
397         pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 64;
398         pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 24;
399         pub const __SIZEOF_PTHREAD_COND_T: usize = 28;
400         pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 24;
401         pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32;
402         pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
403         pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;
404     } else {
405         const __PTHREAD_INITIALIZER_BYTE: u8 = 0;
406         pub const __SIZEOF_PTHREAD_ATTR_T: usize = 56;
407         pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
408         pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
409         pub const __SIZEOF_PTHREAD_COND_T: usize = 48;
410         pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
411         pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
412         pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
413         pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;
414     }
415 }
416 
417 pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;
418 pub const __PTHREAD_MUTEX_HAVE_PREV: usize = 1;
419 pub const __PTHREAD_RWLOCK_INT_FLAGS_SHARED: usize = 1;
420 pub const PTHREAD_MUTEX_NORMAL: c_int = 0;
421 pub const PTHREAD_MUTEX_RECURSIVE: c_int = 1;
422 pub const PTHREAD_MUTEX_ERRORCHECK: c_int = 2;
423 
424 cfg_if! {
425     if #[cfg(any(target_os = "horizon", target_os = "espidf"))] {
426         pub const FD_SETSIZE: usize = 64;
427     } else if #[cfg(target_os = "vita")] {
428         pub const FD_SETSIZE: usize = 256;
429     } else {
430         pub const FD_SETSIZE: usize = 1024;
431     }
432 }
433 // intentionally not public, only used for fd_set
434 const ULONG_SIZE: usize = 32;
435 
436 // Other constants
437 pub const EPERM: c_int = 1;
438 pub const ENOENT: c_int = 2;
439 pub const ESRCH: c_int = 3;
440 pub const EINTR: c_int = 4;
441 pub const EIO: c_int = 5;
442 pub const ENXIO: c_int = 6;
443 pub const E2BIG: c_int = 7;
444 pub const ENOEXEC: c_int = 8;
445 pub const EBADF: c_int = 9;
446 pub const ECHILD: c_int = 10;
447 pub const EAGAIN: c_int = 11;
448 pub const ENOMEM: c_int = 12;
449 pub const EACCES: c_int = 13;
450 pub const EFAULT: c_int = 14;
451 pub const EBUSY: c_int = 16;
452 pub const EEXIST: c_int = 17;
453 pub const EXDEV: c_int = 18;
454 pub const ENODEV: c_int = 19;
455 pub const ENOTDIR: c_int = 20;
456 pub const EISDIR: c_int = 21;
457 pub const EINVAL: c_int = 22;
458 pub const ENFILE: c_int = 23;
459 pub const EMFILE: c_int = 24;
460 pub const ENOTTY: c_int = 25;
461 pub const ETXTBSY: c_int = 26;
462 pub const EFBIG: c_int = 27;
463 pub const ENOSPC: c_int = 28;
464 pub const ESPIPE: c_int = 29;
465 pub const EROFS: c_int = 30;
466 pub const EMLINK: c_int = 31;
467 pub const EPIPE: c_int = 32;
468 pub const EDOM: c_int = 33;
469 pub const ERANGE: c_int = 34;
470 pub const ENOMSG: c_int = 35;
471 pub const EIDRM: c_int = 36;
472 pub const EDEADLK: c_int = 45;
473 pub const ENOLCK: c_int = 46;
474 pub const ENOSTR: c_int = 60;
475 pub const ENODATA: c_int = 61;
476 pub const ETIME: c_int = 62;
477 pub const ENOSR: c_int = 63;
478 pub const ENOLINK: c_int = 67;
479 pub const EPROTO: c_int = 71;
480 pub const EMULTIHOP: c_int = 74;
481 pub const EBADMSG: c_int = 77;
482 pub const EFTYPE: c_int = 79;
483 pub const ENOSYS: c_int = 88;
484 pub const ENOTEMPTY: c_int = 90;
485 pub const ENAMETOOLONG: c_int = 91;
486 pub const ELOOP: c_int = 92;
487 pub const EOPNOTSUPP: c_int = 95;
488 pub const EPFNOSUPPORT: c_int = 96;
489 pub const ECONNRESET: c_int = 104;
490 pub const ENOBUFS: c_int = 105;
491 pub const EAFNOSUPPORT: c_int = 106;
492 pub const EPROTOTYPE: c_int = 107;
493 pub const ENOTSOCK: c_int = 108;
494 pub const ENOPROTOOPT: c_int = 109;
495 pub const ECONNREFUSED: c_int = 111;
496 pub const EADDRINUSE: c_int = 112;
497 pub const ECONNABORTED: c_int = 113;
498 pub const ENETUNREACH: c_int = 114;
499 pub const ENETDOWN: c_int = 115;
500 pub const ETIMEDOUT: c_int = 116;
501 pub const EHOSTDOWN: c_int = 117;
502 pub const EHOSTUNREACH: c_int = 118;
503 pub const EINPROGRESS: c_int = 119;
504 pub const EALREADY: c_int = 120;
505 pub const EDESTADDRREQ: c_int = 121;
506 pub const EMSGSIZE: c_int = 122;
507 pub const EPROTONOSUPPORT: c_int = 123;
508 pub const EADDRNOTAVAIL: c_int = 125;
509 pub const ENETRESET: c_int = 126;
510 pub const EISCONN: c_int = 127;
511 pub const ENOTCONN: c_int = 128;
512 pub const ETOOMANYREFS: c_int = 129;
513 pub const EDQUOT: c_int = 132;
514 pub const ESTALE: c_int = 133;
515 pub const ENOTSUP: c_int = 134;
516 pub const EILSEQ: c_int = 138;
517 pub const EOVERFLOW: c_int = 139;
518 pub const ECANCELED: c_int = 140;
519 pub const ENOTRECOVERABLE: c_int = 141;
520 pub const EOWNERDEAD: c_int = 142;
521 pub const EWOULDBLOCK: c_int = 11;
522 
523 pub const F_DUPFD: c_int = 0;
524 pub const F_GETFD: c_int = 1;
525 pub const F_SETFD: c_int = 2;
526 pub const F_GETFL: c_int = 3;
527 pub const F_SETFL: c_int = 4;
528 pub const F_GETOWN: c_int = 5;
529 pub const F_SETOWN: c_int = 6;
530 pub const F_GETLK: c_int = 7;
531 pub const F_SETLK: c_int = 8;
532 pub const F_SETLKW: c_int = 9;
533 pub const F_RGETLK: c_int = 10;
534 pub const F_RSETLK: c_int = 11;
535 pub const F_CNVT: c_int = 12;
536 pub const F_RSETLKW: c_int = 13;
537 pub const F_DUPFD_CLOEXEC: c_int = 14;
538 
539 pub const O_RDONLY: c_int = 0;
540 pub const O_WRONLY: c_int = 1;
541 pub const O_RDWR: c_int = 2;
542 pub const O_APPEND: c_int = 8;
543 pub const O_CREAT: c_int = 512;
544 pub const O_TRUNC: c_int = 1024;
545 pub const O_EXCL: c_int = 2048;
546 pub const O_SYNC: c_int = 8192;
547 pub const O_NONBLOCK: c_int = 16384;
548 
549 pub const O_ACCMODE: c_int = 3;
550 cfg_if! {
551     if #[cfg(target_os = "espidf")] {
552         pub const O_CLOEXEC: c_int = 0x40000;
553     } else {
554         pub const O_CLOEXEC: c_int = 0x80000;
555     }
556 }
557 
558 pub const RTLD_LAZY: c_int = 0x1;
559 
560 pub const STDIN_FILENO: c_int = 0;
561 pub const STDOUT_FILENO: c_int = 1;
562 pub const STDERR_FILENO: c_int = 2;
563 
564 pub const SEEK_SET: c_int = 0;
565 pub const SEEK_CUR: c_int = 1;
566 pub const SEEK_END: c_int = 2;
567 
568 pub const FIOCLEX: c_ulong = 0x20006601;
569 pub const FIONCLEX: c_ulong = 0x20006602;
570 
571 pub const S_BLKSIZE: mode_t = 1024;
572 pub const S_IREAD: mode_t = 0o0400;
573 pub const S_IWRITE: mode_t = 0o0200;
574 pub const S_IEXEC: mode_t = 0o0100;
575 pub const S_ENFMT: mode_t = 0o2000;
576 pub const S_IFMT: mode_t = 0o17_0000;
577 pub const S_IFDIR: mode_t = 0o4_0000;
578 pub const S_IFCHR: mode_t = 0o2_0000;
579 pub const S_IFBLK: mode_t = 0o6_0000;
580 pub const S_IFREG: mode_t = 0o10_0000;
581 pub const S_IFLNK: mode_t = 0o12_0000;
582 pub const S_IFSOCK: mode_t = 0o14_0000;
583 pub const S_IFIFO: mode_t = 0o1_0000;
584 pub const S_IRUSR: mode_t = 0o0400;
585 pub const S_IWUSR: mode_t = 0o0200;
586 pub const S_IXUSR: mode_t = 0o0100;
587 pub const S_IRGRP: mode_t = 0o0040;
588 pub const S_IWGRP: mode_t = 0o0020;
589 pub const S_IXGRP: mode_t = 0o0010;
590 pub const S_IROTH: mode_t = 0o0004;
591 pub const S_IWOTH: mode_t = 0o0002;
592 pub const S_IXOTH: mode_t = 0o0001;
593 
594 pub const SOL_TCP: c_int = 6;
595 
596 pub const PF_UNSPEC: c_int = 0;
597 pub const PF_INET: c_int = 2;
598 cfg_if! {
599     if #[cfg(target_os = "espidf")] {
600         pub const PF_INET6: c_int = 10;
601     } else {
602         pub const PF_INET6: c_int = 23;
603     }
604 }
605 
606 pub const AF_UNSPEC: c_int = 0;
607 pub const AF_INET: c_int = 2;
608 
609 pub const CLOCK_REALTIME: crate::clockid_t = 1;
610 pub const CLOCK_MONOTONIC: crate::clockid_t = 4;
611 pub const CLOCK_BOOTTIME: crate::clockid_t = 4;
612 
613 pub const SOCK_STREAM: c_int = 1;
614 pub const SOCK_DGRAM: c_int = 2;
615 
616 pub const SHUT_RD: c_int = 0;
617 pub const SHUT_WR: c_int = 1;
618 pub const SHUT_RDWR: c_int = 2;
619 
620 pub const SO_BINTIME: c_int = 0x2000;
621 pub const SO_NO_OFFLOAD: c_int = 0x4000;
622 pub const SO_NO_DDP: c_int = 0x8000;
623 pub const SO_REUSEPORT_LB: c_int = 0x10000;
624 pub const SO_LABEL: c_int = 0x1009;
625 pub const SO_PEERLABEL: c_int = 0x1010;
626 pub const SO_LISTENQLIMIT: c_int = 0x1011;
627 pub const SO_LISTENQLEN: c_int = 0x1012;
628 pub const SO_LISTENINCQLEN: c_int = 0x1013;
629 pub const SO_SETFIB: c_int = 0x1014;
630 pub const SO_USER_COOKIE: c_int = 0x1015;
631 pub const SO_PROTOCOL: c_int = 0x1016;
632 pub const SO_PROTOTYPE: c_int = SO_PROTOCOL;
633 pub const SO_VENDOR: c_int = 0x80000000;
634 pub const SO_DEBUG: c_int = 0x01;
635 pub const SO_ACCEPTCONN: c_int = 0x0002;
636 pub const SO_REUSEADDR: c_int = 0x0004;
637 pub const SO_KEEPALIVE: c_int = 0x0008;
638 pub const SO_DONTROUTE: c_int = 0x0010;
639 pub const SO_BROADCAST: c_int = 0x0020;
640 pub const SO_USELOOPBACK: c_int = 0x0040;
641 pub const SO_LINGER: c_int = 0x0080;
642 pub const SO_OOBINLINE: c_int = 0x0100;
643 pub const SO_REUSEPORT: c_int = 0x0200;
644 pub const SO_TIMESTAMP: c_int = 0x0400;
645 pub const SO_NOSIGPIPE: c_int = 0x0800;
646 pub const SO_ACCEPTFILTER: c_int = 0x1000;
647 pub const SO_SNDBUF: c_int = 0x1001;
648 pub const SO_RCVBUF: c_int = 0x1002;
649 pub const SO_SNDLOWAT: c_int = 0x1003;
650 pub const SO_RCVLOWAT: c_int = 0x1004;
651 pub const SO_SNDTIMEO: c_int = 0x1005;
652 pub const SO_RCVTIMEO: c_int = 0x1006;
653 cfg_if! {
654     if #[cfg(target_os = "horizon")] {
655         pub const SO_ERROR: c_int = 0x1009;
656     } else {
657         pub const SO_ERROR: c_int = 0x1007;
658     }
659 }
660 pub const SO_TYPE: c_int = 0x1008;
661 
662 pub const SOCK_CLOEXEC: c_int = O_CLOEXEC;
663 
664 pub const INET_ADDRSTRLEN: c_int = 16;
665 
666 // https://github.com/bminor/newlib/blob/HEAD/newlib/libc/sys/linux/include/net/if.h#L121
667 pub const IFF_UP: c_int = 0x1; // interface is up
668 pub const IFF_BROADCAST: c_int = 0x2; // broadcast address valid
669 pub const IFF_DEBUG: c_int = 0x4; // turn on debugging
670 pub const IFF_LOOPBACK: c_int = 0x8; // is a loopback net
671 pub const IFF_POINTOPOINT: c_int = 0x10; // interface is point-to-point link
672 pub const IFF_NOTRAILERS: c_int = 0x20; // avoid use of trailers
673 pub const IFF_RUNNING: c_int = 0x40; // resources allocated
674 pub const IFF_NOARP: c_int = 0x80; // no address resolution protocol
675 pub const IFF_PROMISC: c_int = 0x100; // receive all packets
676 pub const IFF_ALLMULTI: c_int = 0x200; // receive all multicast packets
677 pub const IFF_OACTIVE: c_int = 0x400; // transmission in progress
678 pub const IFF_SIMPLEX: c_int = 0x800; // can't hear own transmissions
679 pub const IFF_LINK0: c_int = 0x1000; // per link layer defined bit
680 pub const IFF_LINK1: c_int = 0x2000; // per link layer defined bit
681 pub const IFF_LINK2: c_int = 0x4000; // per link layer defined bit
682 pub const IFF_ALTPHYS: c_int = IFF_LINK2; // use alternate physical connection
683 pub const IFF_MULTICAST: c_int = 0x8000; // supports multicast
684 
685 cfg_if! {
686     if #[cfg(target_os = "vita")] {
687         pub const TCP_NODELAY: c_int = 1;
688         pub const TCP_MAXSEG: c_int = 2;
689     } else if #[cfg(target_os = "espidf")] {
690         pub const TCP_NODELAY: c_int = 1;
691         pub const TCP_MAXSEG: c_int = 8194;
692     } else {
693         pub const TCP_NODELAY: c_int = 8193;
694         pub const TCP_MAXSEG: c_int = 8194;
695     }
696 }
697 
698 pub const TCP_NOPUSH: c_int = 4;
699 pub const TCP_NOOPT: c_int = 8;
700 cfg_if! {
701     if #[cfg(target_os = "espidf")] {
702         pub const TCP_KEEPIDLE: c_int = 3;
703         pub const TCP_KEEPINTVL: c_int = 4;
704         pub const TCP_KEEPCNT: c_int = 5;
705     } else {
706         pub const TCP_KEEPIDLE: c_int = 256;
707         pub const TCP_KEEPINTVL: c_int = 512;
708         pub const TCP_KEEPCNT: c_int = 1024;
709     }
710 }
711 
712 cfg_if! {
713     if #[cfg(target_os = "horizon")] {
714         pub const IP_TOS: c_int = 7;
715     } else if #[cfg(target_os = "espidf")] {
716         pub const IP_TOS: c_int = 1;
717     } else {
718         pub const IP_TOS: c_int = 3;
719     }
720 }
721 cfg_if! {
722     if #[cfg(target_os = "vita")] {
723         pub const IP_TTL: c_int = 4;
724     } else if #[cfg(target_os = "espidf")] {
725         pub const IP_TTL: c_int = 2;
726     } else {
727         pub const IP_TTL: c_int = 8;
728     }
729 }
730 
731 cfg_if! {
732     if #[cfg(target_os = "espidf")] {
733         pub const IP_MULTICAST_IF: c_int = 6;
734         pub const IP_MULTICAST_TTL: c_int = 5;
735         pub const IP_MULTICAST_LOOP: c_int = 7;
736     } else {
737         pub const IP_MULTICAST_IF: c_int = 9;
738         pub const IP_MULTICAST_TTL: c_int = 10;
739         pub const IP_MULTICAST_LOOP: c_int = 11;
740     }
741 }
742 
743 cfg_if! {
744     if #[cfg(target_os = "vita")] {
745         pub const IP_ADD_MEMBERSHIP: c_int = 12;
746         pub const IP_DROP_MEMBERSHIP: c_int = 13;
747     } else if #[cfg(target_os = "espidf")] {
748         pub const IP_ADD_MEMBERSHIP: c_int = 3;
749         pub const IP_DROP_MEMBERSHIP: c_int = 4;
750     } else {
751         pub const IP_ADD_MEMBERSHIP: c_int = 11;
752         pub const IP_DROP_MEMBERSHIP: c_int = 12;
753     }
754 }
755 pub const IPV6_UNICAST_HOPS: c_int = 4;
756 cfg_if! {
757     if #[cfg(target_os = "espidf")] {
758         pub const IPV6_MULTICAST_IF: c_int = 768;
759         pub const IPV6_MULTICAST_HOPS: c_int = 769;
760         pub const IPV6_MULTICAST_LOOP: c_int = 770;
761     } else {
762         pub const IPV6_MULTICAST_IF: c_int = 9;
763         pub const IPV6_MULTICAST_HOPS: c_int = 10;
764         pub const IPV6_MULTICAST_LOOP: c_int = 11;
765     }
766 }
767 pub const IPV6_V6ONLY: c_int = 27;
768 pub const IPV6_JOIN_GROUP: c_int = 12;
769 pub const IPV6_LEAVE_GROUP: c_int = 13;
770 pub const IPV6_ADD_MEMBERSHIP: c_int = 12;
771 pub const IPV6_DROP_MEMBERSHIP: c_int = 13;
772 
773 cfg_if! {
774     if #[cfg(target_os = "espidf")] {
775         pub const HOST_NOT_FOUND: c_int = 210;
776         pub const NO_DATA: c_int = 211;
777         pub const NO_RECOVERY: c_int = 212;
778         pub const TRY_AGAIN: c_int = 213;
779     } else {
780         pub const HOST_NOT_FOUND: c_int = 1;
781         pub const NO_DATA: c_int = 2;
782         pub const NO_RECOVERY: c_int = 3;
783         pub const TRY_AGAIN: c_int = 4;
784     }
785 }
786 pub const NO_ADDRESS: c_int = 2;
787 
788 pub const AI_PASSIVE: c_int = 1;
789 pub const AI_CANONNAME: c_int = 2;
790 pub const AI_NUMERICHOST: c_int = 4;
791 cfg_if! {
792     if #[cfg(target_os = "espidf")] {
793         pub const AI_NUMERICSERV: c_int = 8;
794         pub const AI_ADDRCONFIG: c_int = 64;
795     } else {
796         pub const AI_NUMERICSERV: c_int = 0;
797         pub const AI_ADDRCONFIG: c_int = 0;
798     }
799 }
800 
801 pub const NI_MAXHOST: c_int = 1025;
802 pub const NI_MAXSERV: c_int = 32;
803 pub const NI_NOFQDN: c_int = 1;
804 pub const NI_NUMERICHOST: c_int = 2;
805 pub const NI_NAMEREQD: c_int = 4;
806 cfg_if! {
807     if #[cfg(target_os = "espidf")] {
808         pub const NI_NUMERICSERV: c_int = 8;
809         pub const NI_DGRAM: c_int = 16;
810     } else {
811         pub const NI_NUMERICSERV: c_int = 0;
812         pub const NI_DGRAM: c_int = 0;
813     }
814 }
815 
816 cfg_if! {
817     // Defined in vita/mod.rs for "vita"
818     if #[cfg(target_os = "espidf")] {
819         pub const EAI_FAMILY: c_int = 204;
820         pub const EAI_MEMORY: c_int = 203;
821         pub const EAI_NONAME: c_int = 200;
822         pub const EAI_SOCKTYPE: c_int = 10;
823     } else if #[cfg(not(target_os = "vita"))] {
824         pub const EAI_FAMILY: c_int = -303;
825         pub const EAI_MEMORY: c_int = -304;
826         pub const EAI_NONAME: c_int = -305;
827         pub const EAI_SOCKTYPE: c_int = -307;
828     }
829 }
830 
831 pub const EXIT_SUCCESS: c_int = 0;
832 pub const EXIT_FAILURE: c_int = 1;
833 
834 pub const PRIO_PROCESS: c_int = 0;
835 pub const PRIO_PGRP: c_int = 1;
836 pub const PRIO_USER: c_int = 2;
837 
838 f! {
839     pub fn FD_CLR(fd: c_int, set: *mut fd_set) -> () {
840         let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8;
841         let fd = fd as usize;
842         (*set).fds_bits[fd / bits] &= !(1 << (fd % bits));
843         return;
844     }
845 
846     pub fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool {
847         let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8;
848         let fd = fd as usize;
849         return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0;
850     }
851 
852     pub fn FD_SET(fd: c_int, set: *mut fd_set) -> () {
853         let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8;
854         let fd = fd as usize;
855         (*set).fds_bits[fd / bits] |= 1 << (fd % bits);
856         return;
857     }
858 
859     pub fn FD_ZERO(set: *mut fd_set) -> () {
860         for slot in (*set).fds_bits.iter_mut() {
861             *slot = 0;
862         }
863     }
864 }
865 
866 extern "C" {
getrlimit(resource: c_int, rlim: *mut crate::rlimit) -> c_int867     pub fn getrlimit(resource: c_int, rlim: *mut crate::rlimit) -> c_int;
setrlimit(resource: c_int, rlim: *const crate::rlimit) -> c_int868     pub fn setrlimit(resource: c_int, rlim: *const crate::rlimit) -> c_int;
869 
870     #[cfg_attr(target_os = "linux", link_name = "__xpg_strerror_r")]
strerror_r(errnum: c_int, buf: *mut c_char, buflen: size_t) -> c_int871     pub fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: size_t) -> c_int;
872 
sem_destroy(sem: *mut sem_t) -> c_int873     pub fn sem_destroy(sem: *mut sem_t) -> c_int;
sem_init(sem: *mut sem_t, pshared: c_int, value: c_uint) -> c_int874     pub fn sem_init(sem: *mut sem_t, pshared: c_int, value: c_uint) -> c_int;
875 
abs(i: c_int) -> c_int876     pub fn abs(i: c_int) -> c_int;
labs(i: c_long) -> c_long877     pub fn labs(i: c_long) -> c_long;
rand() -> c_int878     pub fn rand() -> c_int;
srand(seed: c_uint)879     pub fn srand(seed: c_uint);
880 
881     #[cfg(not(all(target_arch = "powerpc", target_vendor = "nintendo")))]
882     #[cfg_attr(target_os = "espidf", link_name = "lwip_bind")]
bind(fd: c_int, addr: *const sockaddr, len: socklen_t) -> c_int883     pub fn bind(fd: c_int, addr: *const sockaddr, len: socklen_t) -> c_int;
clock_settime(clock_id: crate::clockid_t, tp: *const crate::timespec) -> c_int884     pub fn clock_settime(clock_id: crate::clockid_t, tp: *const crate::timespec) -> c_int;
clock_gettime(clock_id: crate::clockid_t, tp: *mut crate::timespec) -> c_int885     pub fn clock_gettime(clock_id: crate::clockid_t, tp: *mut crate::timespec) -> c_int;
clock_getres(clock_id: crate::clockid_t, res: *mut crate::timespec) -> c_int886     pub fn clock_getres(clock_id: crate::clockid_t, res: *mut crate::timespec) -> c_int;
887     #[cfg_attr(target_os = "espidf", link_name = "lwip_close")]
closesocket(sockfd: c_int) -> c_int888     pub fn closesocket(sockfd: c_int) -> c_int;
ioctl(fd: c_int, request: c_ulong, ...) -> c_int889     pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int;
890     #[cfg(not(all(target_arch = "powerpc", target_vendor = "nintendo")))]
891     #[cfg_attr(target_os = "espidf", link_name = "lwip_recvfrom")]
recvfrom( fd: c_int, buf: *mut c_void, n: usize, flags: c_int, addr: *mut sockaddr, addr_len: *mut socklen_t, ) -> isize892     pub fn recvfrom(
893         fd: c_int,
894         buf: *mut c_void,
895         n: usize,
896         flags: c_int,
897         addr: *mut sockaddr,
898         addr_len: *mut socklen_t,
899     ) -> isize;
900     #[cfg(not(all(target_arch = "powerpc", target_vendor = "nintendo")))]
getnameinfo( sa: *const sockaddr, salen: socklen_t, host: *mut c_char, hostlen: socklen_t, serv: *mut c_char, servlen: socklen_t, flags: c_int, ) -> c_int901     pub fn getnameinfo(
902         sa: *const sockaddr,
903         salen: socklen_t,
904         host: *mut c_char,
905         hostlen: socklen_t,
906         serv: *mut c_char,
907         servlen: socklen_t,
908         flags: c_int,
909     ) -> c_int;
memalign(align: size_t, size: size_t) -> *mut c_void910     pub fn memalign(align: size_t, size: size_t) -> *mut c_void;
911 
912     // DIFF(main): changed to `*const *mut` in e77f551de9
fexecve(fd: c_int, argv: *const *const c_char, envp: *const *const c_char) -> c_int913     pub fn fexecve(fd: c_int, argv: *const *const c_char, envp: *const *const c_char) -> c_int;
914 
gettimeofday(tp: *mut crate::timeval, tz: *mut c_void) -> c_int915     pub fn gettimeofday(tp: *mut crate::timeval, tz: *mut c_void) -> c_int;
getgrgid_r( gid: crate::gid_t, grp: *mut crate::group, buf: *mut c_char, buflen: size_t, result: *mut *mut crate::group, ) -> c_int916     pub fn getgrgid_r(
917         gid: crate::gid_t,
918         grp: *mut crate::group,
919         buf: *mut c_char,
920         buflen: size_t,
921         result: *mut *mut crate::group,
922     ) -> c_int;
sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> c_int923     pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> c_int;
sem_close(sem: *mut sem_t) -> c_int924     pub fn sem_close(sem: *mut sem_t) -> c_int;
getdtablesize() -> c_int925     pub fn getdtablesize() -> c_int;
getgrnam_r( name: *const c_char, grp: *mut crate::group, buf: *mut c_char, buflen: size_t, result: *mut *mut crate::group, ) -> c_int926     pub fn getgrnam_r(
927         name: *const c_char,
928         grp: *mut crate::group,
929         buf: *mut c_char,
930         buflen: size_t,
931         result: *mut *mut crate::group,
932     ) -> c_int;
pthread_sigmask(how: c_int, set: *const sigset_t, oldset: *mut sigset_t) -> c_int933     pub fn pthread_sigmask(how: c_int, set: *const sigset_t, oldset: *mut sigset_t) -> c_int;
sem_open(name: *const c_char, oflag: c_int, ...) -> *mut sem_t934     pub fn sem_open(name: *const c_char, oflag: c_int, ...) -> *mut sem_t;
getgrnam(name: *const c_char) -> *mut crate::group935     pub fn getgrnam(name: *const c_char) -> *mut crate::group;
pthread_kill(thread: crate::pthread_t, sig: c_int) -> c_int936     pub fn pthread_kill(thread: crate::pthread_t, sig: c_int) -> c_int;
sem_unlink(name: *const c_char) -> c_int937     pub fn sem_unlink(name: *const c_char) -> c_int;
daemon(nochdir: c_int, noclose: c_int) -> c_int938     pub fn daemon(nochdir: c_int, noclose: c_int) -> c_int;
getpwnam_r( name: *const c_char, pwd: *mut passwd, buf: *mut c_char, buflen: size_t, result: *mut *mut passwd, ) -> c_int939     pub fn getpwnam_r(
940         name: *const c_char,
941         pwd: *mut passwd,
942         buf: *mut c_char,
943         buflen: size_t,
944         result: *mut *mut passwd,
945     ) -> c_int;
getpwuid_r( uid: crate::uid_t, pwd: *mut passwd, buf: *mut c_char, buflen: size_t, result: *mut *mut passwd, ) -> c_int946     pub fn getpwuid_r(
947         uid: crate::uid_t,
948         pwd: *mut passwd,
949         buf: *mut c_char,
950         buflen: size_t,
951         result: *mut *mut passwd,
952     ) -> c_int;
sigwait(set: *const sigset_t, sig: *mut c_int) -> c_int953     pub fn sigwait(set: *const sigset_t, sig: *mut c_int) -> c_int;
pthread_atfork( prepare: Option<unsafe extern "C" fn()>, parent: Option<unsafe extern "C" fn()>, child: Option<unsafe extern "C" fn()>, ) -> c_int954     pub fn pthread_atfork(
955         prepare: Option<unsafe extern "C" fn()>,
956         parent: Option<unsafe extern "C" fn()>,
957         child: Option<unsafe extern "C" fn()>,
958     ) -> c_int;
getgrgid(gid: crate::gid_t) -> *mut crate::group959     pub fn getgrgid(gid: crate::gid_t) -> *mut crate::group;
popen(command: *const c_char, mode: *const c_char) -> *mut crate::FILE960     pub fn popen(command: *const c_char, mode: *const c_char) -> *mut crate::FILE;
uname(buf: *mut crate::utsname) -> c_int961     pub fn uname(buf: *mut crate::utsname) -> c_int;
962 }
963 
964 mod generic;
965 
966 cfg_if! {
967     if #[cfg(target_os = "espidf")] {
968         mod espidf;
969         pub use self::espidf::*;
970     } else if #[cfg(target_os = "horizon")] {
971         mod horizon;
972         pub use self::horizon::*;
973     } else if #[cfg(target_os = "vita")] {
974         mod vita;
975         pub use self::vita::*;
976     } else if #[cfg(target_arch = "arm")] {
977         mod arm;
978         pub use self::arm::*;
979     } else if #[cfg(target_arch = "aarch64")] {
980         mod aarch64;
981         pub use self::aarch64::*;
982     } else if #[cfg(target_arch = "powerpc")] {
983         mod powerpc;
984         pub use self::powerpc::*;
985     } else {
986         // Only tested on ARM so far. Other platforms might have different
987         // definitions for types and constants.
988         pub use target_arch_not_implemented;
989     }
990 }
991 
992 cfg_if! {
993     if #[cfg(target_os = "rtems")] {
994         mod rtems;
995         pub use self::rtems::*;
996     }
997 }
998