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