Debian Codegraph @

debian/missing-sources/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 pub const O_APPEND: c_int = 8;
519 pub const O_CREAT: c_int = 512;
520 pub const O_TRUNC: c_int = 1024;
521 pub const O_EXCL: c_int = 2048;
522 pub const O_SYNC: c_int = 8192;
523 pub const O_NONBLOCK: c_int = 16384;
524
525 pub const O_ACCMODE: c_int = 3;
526 cfg_if! {
527 if #[cfg(target_os = "espidf")] {
528 pub const O_CLOEXEC: c_int = 0x40000;
529 } else {
530 pub const O_CLOEXEC: c_int = 0x80000;
531 }
532 }
533
534 pub const RTLD_LAZY: c_int = 0x1;
535
536 pub const SEEK_SET: c_int = 0;
537 pub const SEEK_CUR: c_int = 1;
538 pub const SEEK_END: c_int = 2;
539
540 pub const FIOCLEX: c_ulong = 0x20006601;
541 pub const FIONCLEX: c_ulong = 0x20006602;
542
543 pub const S_BLKSIZE: mode_t = 1024;
544 pub const S_IREAD: mode_t = 0o0400;
545 pub const S_IWRITE: mode_t = 0o0200;
546 pub const S_IEXEC: mode_t = 0o0100;
547 pub const S_ENFMT: mode_t = 0o2000;
548 pub const S_IFMT: mode_t = 0o17_0000;
549 pub const S_IFDIR: mode_t = 0o4_0000;
550 pub const S_IFCHR: mode_t = 0o2_0000;
551 pub const S_IFBLK: mode_t = 0o6_0000;
552 pub const S_IFREG: mode_t = 0o10_0000;
553 pub const S_IFLNK: mode_t = 0o12_0000;
554 pub const S_IFSOCK: mode_t = 0o14_0000;
555 pub const S_IFIFO: mode_t = 0o1_0000;
556 pub const S_IRUSR: mode_t = 0o0400;
557 pub const S_IWUSR: mode_t = 0o0200;
558 pub const S_IXUSR: mode_t = 0o0100;
559 pub const S_IRGRP: mode_t = 0o0040;
560 pub const S_IWGRP: mode_t = 0o0020;
561 pub const S_IXGRP: mode_t = 0o0010;
562 pub const S_IROTH: mode_t = 0o0004;
563 pub const S_IWOTH: mode_t = 0o0002;
564 pub const S_IXOTH: mode_t = 0o0001;
565
566 pub const SOL_TCP: c_int = 6;
567
568 pub const PF_UNSPEC: c_int = 0;
569 pub const PF_INET: c_int = 2;
570 cfg_if! {
571 if #[cfg(target_os = "espidf")] {
572 pub const PF_INET6: c_int = 10;
573 } else {
574 pub const PF_INET6: c_int = 23;
575 }
576 }
577
578 pub const AF_UNSPEC: c_int = 0;
579 pub const AF_INET: c_int = 2;
580
581 pub const CLOCK_REALTIME: crate::clockid_t = 1;
582 pub const CLOCK_MONOTONIC: crate::clockid_t = 4;
583 pub const CLOCK_BOOTTIME: crate::clockid_t = 4;
584
585 pub const SOCK_STREAM: c_int = 1;
586 pub const SOCK_DGRAM: c_int = 2;
587
588 pub const SHUT_RD: c_int = 0;
589 pub const SHUT_WR: c_int = 1;
590 pub const SHUT_RDWR: c_int = 2;
591
592 pub const SO_BINTIME: c_int = 0x2000;
593 pub const SO_NO_OFFLOAD: c_int = 0x4000;
594 pub const SO_NO_DDP: c_int = 0x8000;
595 pub const SO_REUSEPORT_LB: c_int = 0x10000;
596 pub const SO_LABEL: c_int = 0x1009;
597 pub const SO_PEERLABEL: c_int = 0x1010;
598 pub const SO_LISTENQLIMIT: c_int = 0x1011;
599 pub const SO_LISTENQLEN: c_int = 0x1012;
600 pub const SO_LISTENINCQLEN: c_int = 0x1013;
601 pub const SO_SETFIB: c_int = 0x1014;
602 pub const SO_USER_COOKIE: c_int = 0x1015;
603 pub const SO_PROTOCOL: c_int = 0x1016;
604 pub const SO_PROTOTYPE: c_int = SO_PROTOCOL;
605 pub const SO_VENDOR: c_int = 0x80000000;
606 pub const SO_DEBUG: c_int = 0x01;
607 pub const SO_ACCEPTCONN: c_int = 0x0002;
608 pub const SO_REUSEADDR: c_int = 0x0004;
609 pub const SO_KEEPALIVE: c_int = 0x0008;
610 pub const SO_DONTROUTE: c_int = 0x0010;
611 pub const SO_BROADCAST: c_int = 0x0020;
612 pub const SO_USELOOPBACK: c_int = 0x0040;
613 pub const SO_LINGER: c_int = 0x0080;
614 pub const SO_OOBINLINE: c_int = 0x0100;
615 pub const SO_REUSEPORT: c_int = 0x0200;
616 pub const SO_TIMESTAMP: c_int = 0x0400;
617 pub const SO_NOSIGPIPE: c_int = 0x0800;
618 pub const SO_ACCEPTFILTER: c_int = 0x1000;
619 pub const SO_SNDBUF: c_int = 0x1001;
620 pub const SO_RCVBUF: c_int = 0x1002;
621 pub const SO_SNDLOWAT: c_int = 0x1003;
622 pub const SO_RCVLOWAT: c_int = 0x1004;
623 pub const SO_SNDTIMEO: c_int = 0x1005;
624 pub const SO_RCVTIMEO: c_int = 0x1006;
625 cfg_if! {
626 if #[cfg(target_os = "horizon")] {
627 pub const SO_ERROR: c_int = 0x1009;
628 } else {
629 pub const SO_ERROR: c_int = 0x1007;
630 }
631 }
632 pub const SO_TYPE: c_int = 0x1008;
633
634 pub const SOCK_CLOEXEC: c_int = O_CLOEXEC;
635
636 pub const INET_ADDRSTRLEN: c_int = 16;
637
638 // https://github.com/bminor/newlib/blob/HEAD/newlib/libc/sys/linux/include/net/if.h#L121
639 pub const IFF_UP: c_int = 0x1; // interface is up
640 pub const IFF_BROADCAST: c_int = 0x2; // broadcast address valid
641 pub const IFF_DEBUG: c_int = 0x4; // turn on debugging
642 pub const IFF_LOOPBACK: c_int = 0x8; // is a loopback net
643 pub const IFF_POINTOPOINT: c_int = 0x10; // interface is point-to-point link
644 pub const IFF_NOTRAILERS: c_int = 0x20; // avoid use of trailers
645 pub const IFF_RUNNING: c_int = 0x40; // resources allocated
646 pub const IFF_NOARP: c_int = 0x80; // no address resolution protocol
647 pub const IFF_PROMISC: c_int = 0x100; // receive all packets
648 pub const IFF_ALLMULTI: c_int = 0x200; // receive all multicast packets
649 pub const IFF_OACTIVE: c_int = 0x400; // transmission in progress
650 pub const IFF_SIMPLEX: c_int = 0x800; // can't hear own transmissions
651 pub const IFF_LINK0: c_int = 0x1000; // per link layer defined bit
652 pub const IFF_LINK1: c_int = 0x2000; // per link layer defined bit
653 pub const IFF_LINK2: c_int = 0x4000; // per link layer defined bit
654 pub const IFF_ALTPHYS: c_int = IFF_LINK2; // use alternate physical connection
655 pub const IFF_MULTICAST: c_int = 0x8000; // supports multicast
656
657 cfg_if! {
658 if #[cfg(target_os = "vita")] {
659 pub const TCP_NODELAY: c_int = 1;
660 pub const TCP_MAXSEG: c_int = 2;
661 } else if #[cfg(target_os = "espidf")] {
662 pub const TCP_NODELAY: c_int = 1;
663 pub const TCP_MAXSEG: c_int = 8194;
664 } else {
665 pub const TCP_NODELAY: c_int = 8193;
666 pub const TCP_MAXSEG: c_int = 8194;
667 }
668 }
669
670 pub const TCP_NOPUSH: c_int = 4;
671 pub const TCP_NOOPT: c_int = 8;
672 cfg_if! {
673 if #[cfg(target_os = "espidf")] {
674 pub const TCP_KEEPIDLE: c_int = 3;
675 pub const TCP_KEEPINTVL: c_int = 4;
676 pub const TCP_KEEPCNT: c_int = 5;
677 } else {
678 pub const TCP_KEEPIDLE: c_int = 256;
679 pub const TCP_KEEPINTVL: c_int = 512;
680 pub const TCP_KEEPCNT: c_int = 1024;
681 }
682 }
683
684 cfg_if! {
685 if #[cfg(target_os = "horizon")] {
686 pub const IP_TOS: c_int = 7;
687 } else if #[cfg(target_os = "espidf")] {
688 pub const IP_TOS: c_int = 1;
689 } else {
690 pub const IP_TOS: c_int = 3;
691 }
692 }
693 cfg_if! {
694 if #[cfg(target_os = "vita")] {
695 pub const IP_TTL: c_int = 4;
696 } else if #[cfg(target_os = "espidf")] {
697 pub const IP_TTL: c_int = 2;
698 } else {
699 pub const IP_TTL: c_int = 8;
700 }
701 }
702
703 cfg_if! {
704 if #[cfg(target_os = "espidf")] {
705 pub const IP_MULTICAST_IF: c_int = 6;
706 pub const IP_MULTICAST_TTL: c_int = 5;
707 pub const IP_MULTICAST_LOOP: c_int = 7;
708 } else {
709 pub const IP_MULTICAST_IF: c_int = 9;
710 pub const IP_MULTICAST_TTL: c_int = 10;
711 pub const IP_MULTICAST_LOOP: c_int = 11;
712 }
713 }
714
715 cfg_if! {
716 if #[cfg(target_os = "vita")] {
717 pub const IP_ADD_MEMBERSHIP: c_int = 12;
718 pub const IP_DROP_MEMBERSHIP: c_int = 13;
719 } else if #[cfg(target_os = "espidf")] {
720 pub const IP_ADD_MEMBERSHIP: c_int = 3;
721 pub const IP_DROP_MEMBERSHIP: c_int = 4;
722 } else {
723 pub const IP_ADD_MEMBERSHIP: c_int = 11;
724 pub const IP_DROP_MEMBERSHIP: c_int = 12;
725 }
726 }
727 pub const IPV6_UNICAST_HOPS: c_int = 4;
728 cfg_if! {
729 if #[cfg(target_os = "espidf")] {
730 pub const IPV6_MULTICAST_IF: c_int = 768;
731 pub const IPV6_MULTICAST_HOPS: c_int = 769;
732 pub const IPV6_MULTICAST_LOOP: c_int = 770;
733 } else {
734 pub const IPV6_MULTICAST_IF: c_int = 9;
735 pub const IPV6_MULTICAST_HOPS: c_int = 10;
736 pub const IPV6_MULTICAST_LOOP: c_int = 11;
737 }
738 }
739 pub const IPV6_V6ONLY: c_int = 27;
740 pub const IPV6_JOIN_GROUP: c_int = 12;
741 pub const IPV6_LEAVE_GROUP: c_int = 13;
742 pub const IPV6_ADD_MEMBERSHIP: c_int = 12;
743 pub const IPV6_DROP_MEMBERSHIP: c_int = 13;
744
745 cfg_if! {
746 if #[cfg(target_os = "espidf")] {
747 pub const HOST_NOT_FOUND: c_int = 210;
748 pub const NO_DATA: c_int = 211;
749 pub const NO_RECOVERY: c_int = 212;
750 pub const TRY_AGAIN: c_int = 213;
751 } else {
752 pub const HOST_NOT_FOUND: c_int = 1;
753 pub const NO_DATA: c_int = 2;
754 pub const NO_RECOVERY: c_int = 3;
755 pub const TRY_AGAIN: c_int = 4;
756 }
757 }
758 pub const NO_ADDRESS: c_int = 2;
759
760 pub const AI_PASSIVE: c_int = 1;
761 pub const AI_CANONNAME: c_int = 2;
762 pub const AI_NUMERICHOST: c_int = 4;
763 cfg_if! {
764 if #[cfg(target_os = "espidf")] {
765 pub const AI_NUMERICSERV: c_int = 8;
766 pub const AI_ADDRCONFIG: c_int = 64;
767 } else {
768 pub const AI_NUMERICSERV: c_int = 0;
769 pub const AI_ADDRCONFIG: c_int = 0;
770 }
771 }
772
773 pub const NI_MAXHOST: c_int = 1025;
774 pub const NI_MAXSERV: c_int = 32;
775 pub const NI_NOFQDN: c_int = 1;
776 pub const NI_NUMERICHOST: c_int = 2;
777 pub const NI_NAMEREQD: c_int = 4;
778 cfg_if! {
779 if #[cfg(target_os = "espidf")] {
780 pub const NI_NUMERICSERV: c_int = 8;
781 pub const NI_DGRAM: c_int = 16;
782 } else {
783 pub const NI_NUMERICSERV: c_int = 0;
784 pub const NI_DGRAM: c_int = 0;
785 }
786 }
787
788 cfg_if! {
789 // Defined in vita/mod.rs for "vita"
790 if #[cfg(target_os = "espidf")] {
791 pub const EAI_FAMILY: c_int = 204;
792 pub const EAI_MEMORY: c_int = 203;
793 pub const EAI_NONAME: c_int = 200;
794 pub const EAI_SOCKTYPE: c_int = 10;
795 } else if #[cfg(not(target_os = "vita"))] {
796 pub const EAI_FAMILY: c_int = -303;
797 pub const EAI_MEMORY: c_int = -304;
798 pub const EAI_NONAME: c_int = -305;
799 pub const EAI_SOCKTYPE: c_int = -307;
800 }
801 }
802
803 pub const EXIT_SUCCESS: c_int = 0;
804 pub const EXIT_FAILURE: c_int = 1;
805
806 pub const PRIO_PROCESS: c_int = 0;
807 pub const PRIO_PGRP: c_int = 1;
808 pub const PRIO_USER: c_int = 2;
809
810 f! {
811 pub fn FD_CLR(fd: c_int, set: *mut fd_set) -> () {
812 let bits = size_of_val(&(*set).fds_bits[0]) * 8;
813 let fd = fd as usize;
814 (*set).fds_bits[fd / bits] &= !(1 << (fd % bits));
815 return;
816 }
817
818 pub fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool {
819 let bits = size_of_val(&(*set).fds_bits[0]) * 8;
820 let fd = fd as usize;
821 return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0;
822 }
823
824 pub fn FD_SET(fd: c_int, set: *mut fd_set) -> () {
825 let bits = size_of_val(&(*set).fds_bits[0]) * 8;
826 let fd = fd as usize;
827 (*set).fds_bits[fd / bits] |= 1 << (fd % bits);
828 return;
829 }
830
831 pub fn FD_ZERO(set: *mut fd_set) -> () {
832 for slot in (*set).fds_bits.iter_mut() {
833 *slot = 0;
834 }
835 }
836 }
837
838 extern "C" {
839 pub fn getrlimit(resource: c_int, rlim: *mut crate::rlimit) -> c_int;
840 pub fn setrlimit(resource: c_int, rlim: *const crate::rlimit) -> c_int;
841
842 #[cfg_attr(target_os = "linux", link_name = "__xpg_strerror_r")]
843 pub fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: size_t) -> c_int;
844
845 pub fn sem_destroy(sem: *mut sem_t) -> c_int;
846 pub fn sem_init(sem: *mut sem_t, pshared: c_int, value: c_uint) -> c_int;
847
848 pub fn abs(i: c_int) -> c_int;
849 pub fn labs(i: c_long) -> c_long;
850 pub fn rand() -> c_int;
851 pub fn srand(seed: c_uint);
852
853 #[cfg(not(all(target_arch = "powerpc", target_vendor = "nintendo")))]
854 #[cfg_attr(target_os = "espidf", link_name = "lwip_bind")]
855 pub fn bind(fd: c_int, addr: *const sockaddr, len: socklen_t) -> c_int;
856 pub fn clock_settime(clock_id: crate::clockid_t, tp: *const crate::timespec) -> c_int;
857 pub fn clock_gettime(clock_id: crate::clockid_t, tp: *mut crate::timespec) -> c_int;
858 pub fn clock_getres(clock_id: crate::clockid_t, res: *mut crate::timespec) -> c_int;
859 #[cfg_attr(target_os = "espidf", link_name = "lwip_close")]
860 pub fn closesocket(sockfd: c_int) -> c_int;
861 pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int;
862 #[cfg(not(all(target_arch = "powerpc", target_vendor = "nintendo")))]
863 #[cfg_attr(target_os = "espidf", link_name = "lwip_recvfrom")]
864 pub fn recvfrom(
865 fd: c_int,
866 buf: *mut c_void,
867 n: usize,
868 flags: c_int,
869 addr: *mut sockaddr,
870 addr_len: *mut socklen_t,
871 ) -> isize;
872 #[cfg(not(all(target_arch = "powerpc", target_vendor = "nintendo")))]
873 pub fn getnameinfo(
874 sa: *const sockaddr,
875 salen: socklen_t,
876 host: *mut c_char,
877 hostlen: socklen_t,
878 serv: *mut c_char,
879 servlen: socklen_t,
880 flags: c_int,
881 ) -> c_int;
882 pub fn memalign(align: size_t, size: size_t) -> *mut c_void;
883
884 // DIFF(main): changed to `*const *mut` in e77f551de9
885 pub fn fexecve(fd: c_int, argv: *const *const c_char, envp: *const *const c_char) -> c_int;
886
887 pub fn gettimeofday(tp: *mut crate::timeval, tz: *mut c_void) -> c_int;
888 pub fn getgrgid_r(
889 gid: crate::gid_t,
890 grp: *mut crate::group,
891 buf: *mut c_char,
892 buflen: size_t,
893 result: *mut *mut crate::group,
894 ) -> c_int;
895 pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> c_int;
896 pub fn sem_close(sem: *mut sem_t) -> c_int;
897 pub fn getdtablesize() -> c_int;
898 pub fn getgrnam_r(
899 name: *const c_char,
900 grp: *mut crate::group,
901 buf: *mut c_char,
902 buflen: size_t,
903 result: *mut *mut crate::group,
904 ) -> c_int;
905 pub fn pthread_sigmask(how: c_int, set: *const sigset_t, oldset: *mut sigset_t) -> c_int;
906 pub fn sem_open(name: *const c_char, oflag: c_int, ...) -> *mut sem_t;
907 pub fn getgrnam(name: *const c_char) -> *mut crate::group;
908 pub fn pthread_kill(thread: crate::pthread_t, sig: c_int) -> c_int;
909 pub fn sem_unlink(name: *const c_char) -> c_int;
910 pub fn daemon(nochdir: c_int, noclose: c_int) -> c_int;
911 pub fn getpwnam_r(
912 name: *const c_char,
913 pwd: *mut passwd,
914 buf: *mut c_char,
915 buflen: size_t,
916 result: *mut *mut passwd,
917 ) -> c_int;
918 pub fn getpwuid_r(
919 uid: crate::uid_t,
920 pwd: *mut passwd,
921 buf: *mut c_char,
922 buflen: size_t,
923 result: *mut *mut passwd,
924 ) -> c_int;
925 pub fn sigwait(set: *const sigset_t, sig: *mut c_int) -> c_int;
926 pub fn pthread_atfork(
927 prepare: Option<unsafe extern "C" fn()>,
928 parent: Option<unsafe extern "C" fn()>,
929 child: Option<unsafe extern "C" fn()>,
930 ) -> c_int;
931 pub fn getgrgid(gid: crate::gid_t) -> *mut crate::group;
932 pub fn popen(command: *const c_char, mode: *const c_char) -> *mut crate::FILE;
933 pub fn uname(buf: *mut crate::utsname) -> c_int;
934 }
935
936 mod generic;
937
938 cfg_if! {
939 if #[cfg(target_os = "espidf")] {
940 mod espidf;
941 pub use self::espidf::*;
942 } else if #[cfg(target_os = "horizon")] {
943 mod horizon;
944 pub use self::horizon::*;
945 } else if #[cfg(target_os = "vita")] {
946 mod vita;
947 pub use self::vita::*;
948 } else if #[cfg(target_arch = "arm")] {
949 mod arm;
950 pub use self::arm::*;
951 } else if #[cfg(target_arch = "aarch64")] {
952 mod aarch64;
953 pub use self::aarch64::*;
954 } else if #[cfg(target_arch = "powerpc")] {
955 mod powerpc;
956 pub use self::powerpc::*;
957 } else {
958 // Only tested on ARM so far. Other platforms might have different
959 // definitions for types and constants.
960 pub use target_arch_not_implemented;
961 }
962 }
963
964 cfg_if! {
965 if #[cfg(target_os = "rtems")] {
966 mod rtems;
967 pub use self::rtems::*;
968 }
969 }