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