Debian Codegraph @

debian/rust-vendor/libc/src/unix/newlib/mod.rs

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