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