libc_interface/unix/
mod.rs

1//! Definitions found commonly among almost all Unix derivatives
2//!
3//! More functions and definitions can be found in the more specific modules
4//! according to the platform in question.
5
6pub type pid_t = i32;
7pub type uid_t = u32;
8pub type gid_t = u32;
9pub type in_addr_t = u32;
10pub type in_port_t = u16;
11pub type sighandler_t = ::size_t;
12pub type cc_t = ::c_uchar;
13
14pub enum DIR {}
15pub enum locale_t {}
16
17s! {
18    pub struct group {
19        pub gr_name: *mut ::c_char,
20        pub gr_passwd: *mut ::c_char,
21        pub gr_gid: ::gid_t,
22        pub gr_mem: *mut *mut ::c_char,
23    }
24
25    pub struct utimbuf {
26        pub actime: time_t,
27        pub modtime: time_t,
28    }
29
30    pub struct timeval {
31        pub tv_sec: time_t,
32        pub tv_usec: suseconds_t,
33    }
34
35    // linux x32 compatibility
36    // See https://sourceware.org/bugzilla/show_bug.cgi?id=16437
37    pub struct timespec {
38        pub tv_sec: time_t,
39        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
40        pub tv_nsec: i64,
41        #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
42        pub tv_nsec: ::c_long,
43    }
44
45    pub struct rlimit {
46        pub rlim_cur: rlim_t,
47        pub rlim_max: rlim_t,
48    }
49
50    pub struct rusage {
51        pub ru_utime: timeval,
52        pub ru_stime: timeval,
53        pub ru_maxrss: c_long,
54        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
55        __pad1: u32,
56        pub ru_ixrss: c_long,
57        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
58        __pad2: u32,
59        pub ru_idrss: c_long,
60        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
61        __pad3: u32,
62        pub ru_isrss: c_long,
63        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
64        __pad4: u32,
65        pub ru_minflt: c_long,
66        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
67        __pad5: u32,
68        pub ru_majflt: c_long,
69        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
70        __pad6: u32,
71        pub ru_nswap: c_long,
72        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
73        __pad7: u32,
74        pub ru_inblock: c_long,
75        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
76        __pad8: u32,
77        pub ru_oublock: c_long,
78        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
79        __pad9: u32,
80        pub ru_msgsnd: c_long,
81        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
82        __pad10: u32,
83        pub ru_msgrcv: c_long,
84        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
85        __pad11: u32,
86        pub ru_nsignals: c_long,
87        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
88        __pad12: u32,
89        pub ru_nvcsw: c_long,
90        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
91        __pad13: u32,
92        pub ru_nivcsw: c_long,
93        #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
94        __pad14: u32,
95
96        #[cfg(any(target_env = "musl", target_os = "emscripten"))]
97        __reserved: [c_long; 16],
98    }
99
100    #[cfg_attr(target_os = "netbsd", repr(packed))]
101    pub struct in_addr {
102        pub s_addr: in_addr_t,
103    }
104
105    #[cfg_attr(feature = "align", repr(align(4)))]
106    pub struct in6_addr {
107        pub s6_addr: [u8; 16],
108        #[cfg(not(feature = "align"))]
109        __align: [u32; 0],
110    }
111
112    pub struct ip_mreq {
113        pub imr_multiaddr: in_addr,
114        pub imr_interface: in_addr,
115    }
116
117    pub struct ipv6_mreq {
118        pub ipv6mr_multiaddr: in6_addr,
119        #[cfg(target_os = "android")]
120        pub ipv6mr_interface: ::c_int,
121        #[cfg(not(target_os = "android"))]
122        pub ipv6mr_interface: ::c_uint,
123    }
124
125    pub struct hostent {
126        pub h_name: *mut ::c_char,
127        pub h_aliases: *mut *mut ::c_char,
128        pub h_addrtype: ::c_int,
129        pub h_length: ::c_int,
130        pub h_addr_list: *mut *mut ::c_char,
131    }
132
133    pub struct iovec {
134        pub iov_base: *mut ::c_void,
135        pub iov_len: ::size_t,
136    }
137
138    pub struct pollfd {
139        pub fd: ::c_int,
140        pub events: ::c_short,
141        pub revents: ::c_short,
142    }
143
144    pub struct winsize {
145        pub ws_row: ::c_ushort,
146        pub ws_col: ::c_ushort,
147        pub ws_xpixel: ::c_ushort,
148        pub ws_ypixel: ::c_ushort,
149    }
150
151    pub struct linger {
152        pub l_onoff: ::c_int,
153        pub l_linger: ::c_int,
154    }
155
156    pub struct sigval {
157        // Actually a union of an int and a void*
158        pub sival_ptr: *mut ::c_void
159    }
160
161    // <sys/time.h>
162    pub struct itimerval {
163        pub it_interval: ::timeval,
164        pub it_value: ::timeval,
165    }
166
167    // <sys/times.h>
168    pub struct tms {
169        pub tms_utime: ::clock_t,
170        pub tms_stime: ::clock_t,
171        pub tms_cutime: ::clock_t,
172        pub tms_cstime: ::clock_t,
173    }
174
175    pub struct servent {
176        pub s_name: *mut ::c_char,
177        pub s_aliases: *mut *mut ::c_char,
178        pub s_port: ::c_int,
179        pub s_proto: *mut ::c_char,
180    }
181
182    pub struct protoent {
183        pub p_name: *mut ::c_char,
184        pub p_aliases: *mut *mut ::c_char,
185        pub p_proto: ::c_int,
186    }
187}
188
189pub const SIG_DFL: sighandler_t = 0 as sighandler_t;
190pub const SIG_IGN: sighandler_t = 1 as sighandler_t;
191pub const SIG_ERR: sighandler_t = !0 as sighandler_t;
192
193pub const DT_UNKNOWN: u8 = 0;
194pub const DT_FIFO: u8 = 1;
195pub const DT_CHR: u8 = 2;
196pub const DT_DIR: u8 = 4;
197pub const DT_BLK: u8 = 6;
198pub const DT_REG: u8 = 8;
199pub const DT_LNK: u8 = 10;
200pub const DT_SOCK: u8 = 12;
201
202pub const FD_CLOEXEC: ::c_int = 0x1;
203
204pub const USRQUOTA: ::c_int = 0;
205pub const GRPQUOTA: ::c_int = 1;
206
207pub const SIGIOT: ::c_int = 6;
208
209pub const S_ISUID: ::c_int = 0x800;
210pub const S_ISGID: ::c_int = 0x400;
211pub const S_ISVTX: ::c_int = 0x200;
212
213pub const IF_NAMESIZE: ::size_t = 16;
214pub const IFNAMSIZ: ::size_t = IF_NAMESIZE;
215
216pub const LOG_EMERG: ::c_int = 0;
217pub const LOG_ALERT: ::c_int = 1;
218pub const LOG_CRIT: ::c_int = 2;
219pub const LOG_ERR: ::c_int = 3;
220pub const LOG_WARNING: ::c_int = 4;
221pub const LOG_NOTICE: ::c_int = 5;
222pub const LOG_INFO: ::c_int = 6;
223pub const LOG_DEBUG: ::c_int = 7;
224
225pub const LOG_KERN: ::c_int = 0;
226pub const LOG_USER: ::c_int = 1 << 3;
227pub const LOG_MAIL: ::c_int = 2 << 3;
228pub const LOG_DAEMON: ::c_int = 3 << 3;
229pub const LOG_AUTH: ::c_int = 4 << 3;
230pub const LOG_SYSLOG: ::c_int = 5 << 3;
231pub const LOG_LPR: ::c_int = 6 << 3;
232pub const LOG_NEWS: ::c_int = 7 << 3;
233pub const LOG_UUCP: ::c_int = 8 << 3;
234pub const LOG_LOCAL0: ::c_int = 16 << 3;
235pub const LOG_LOCAL1: ::c_int = 17 << 3;
236pub const LOG_LOCAL2: ::c_int = 18 << 3;
237pub const LOG_LOCAL3: ::c_int = 19 << 3;
238pub const LOG_LOCAL4: ::c_int = 20 << 3;
239pub const LOG_LOCAL5: ::c_int = 21 << 3;
240pub const LOG_LOCAL6: ::c_int = 22 << 3;
241pub const LOG_LOCAL7: ::c_int = 23 << 3;
242
243pub const LOG_PID: ::c_int = 0x01;
244pub const LOG_CONS: ::c_int = 0x02;
245pub const LOG_ODELAY: ::c_int = 0x04;
246pub const LOG_NDELAY: ::c_int = 0x08;
247pub const LOG_NOWAIT: ::c_int = 0x10;
248
249pub const LOG_PRIMASK: ::c_int = 7;
250pub const LOG_FACMASK: ::c_int = 0x3f8;
251
252pub const PRIO_PROCESS: ::c_int = 0;
253pub const PRIO_PGRP: ::c_int = 1;
254pub const PRIO_USER: ::c_int = 2;
255
256pub const PRIO_MIN: ::c_int = -20;
257pub const PRIO_MAX: ::c_int = 20;
258
259pub const IPPROTO_ICMP: ::c_int = 1;
260pub const IPPROTO_ICMPV6: ::c_int = 58;
261pub const IPPROTO_TCP: ::c_int = 6;
262pub const IPPROTO_UDP: ::c_int = 17;
263pub const IPPROTO_IP: ::c_int = 0;
264pub const IPPROTO_IPV6: ::c_int = 41;
265
266pub const INADDR_LOOPBACK: in_addr_t = 2130706433;
267pub const INADDR_ANY: in_addr_t = 0;
268pub const INADDR_BROADCAST: in_addr_t = 4294967295;
269pub const INADDR_NONE: in_addr_t = 4294967295;
270
271pub const ARPOP_REQUEST: u16 = 1;
272pub const ARPOP_REPLY: u16 = 2;
273
274pub const ATF_COM: ::c_int = 0x02;
275pub const ATF_PERM: ::c_int = 0x04;
276pub const ATF_PUBL: ::c_int = 0x08;
277pub const ATF_USETRAILERS: ::c_int = 0x10;
278
279cfg_if! {
280    if #[cfg(target_env = "uclibc")] {
281        mod uclibc;
282        pub use self::uclibc::*;
283    } else if #[cfg(target_env = "newlib")] {
284        mod newlib;
285        pub use self::newlib::*;
286    } else if #[cfg(any(target_os = "linux",
287                        target_os = "android",
288                        target_os = "emscripten",
289                        target_os = "fuchsia"))] {
290        mod notbsd;
291        pub use self::notbsd::*;
292    } else if #[cfg(any(target_os = "macos",
293                        target_os = "ios",
294                        target_os = "freebsd",
295                        target_os = "dragonfly",
296                        target_os = "openbsd",
297                        target_os = "netbsd",
298                        target_os = "bitrig"))] {
299        mod bsd;
300        pub use self::bsd::*;
301    } else if #[cfg(target_os = "solaris")] {
302        mod solaris;
303        pub use self::solaris::*;
304    } else if #[cfg(target_os = "haiku")] {
305        mod haiku;
306        pub use self::haiku::*;
307    } else if #[cfg(target_os = "hermit")] {
308        mod hermit;
309        pub use self::hermit::*;
310    } else {
311        // Unknown target_os
312    }
313}