]> git.proxmox.com Git - rustc.git/blame - src/liblibc/src/unix/bsd/mod.rs
New upstream version 1.12.0+dfsg1
[rustc.git] / src / liblibc / src / unix / bsd / mod.rs
CommitLineData
7453a54e
SL
1use dox::mem;
2
92a42be0
SL
3pub type c_char = i8;
4pub type wchar_t = i32;
5pub type off_t = i64;
6pub type useconds_t = u32;
7pub type blkcnt_t = i64;
8pub type socklen_t = u32;
9pub type sa_family_t = u8;
10pub type pthread_t = ::uintptr_t;
9cc50fc6 11pub type nfds_t = ::c_uint;
92a42be0
SL
12
13s! {
14 pub struct sockaddr {
15 pub sa_len: u8,
16 pub sa_family: sa_family_t,
17 pub sa_data: [::c_char; 14],
18 }
19
92a42be0
SL
20 pub struct sockaddr_in6 {
21 pub sin6_len: u8,
22 pub sin6_family: sa_family_t,
23 pub sin6_port: ::in_port_t,
24 pub sin6_flowinfo: u32,
25 pub sin6_addr: ::in6_addr,
26 pub sin6_scope_id: u32,
27 }
28
29 pub struct sockaddr_un {
30 pub sun_len: u8,
31 pub sun_family: sa_family_t,
32 pub sun_path: [c_char; 104]
33 }
34
35 pub struct passwd {
36 pub pw_name: *mut ::c_char,
37 pub pw_passwd: *mut ::c_char,
38 pub pw_uid: ::uid_t,
39 pub pw_gid: ::gid_t,
40 pub pw_change: ::time_t,
41 pub pw_class: *mut ::c_char,
42 pub pw_gecos: *mut ::c_char,
43 pub pw_dir: *mut ::c_char,
44 pub pw_shell: *mut ::c_char,
45 pub pw_expire: ::time_t,
46
9cc50fc6
SL
47 #[cfg(not(any(target_os = "macos",
48 target_os = "ios",
49 target_os = "netbsd",
50 target_os = "openbsd")))]
92a42be0
SL
51 pub pw_fields: ::c_int,
52 }
53
54 pub struct ifaddrs {
55 pub ifa_next: *mut ifaddrs,
56 pub ifa_name: *mut ::c_char,
57 pub ifa_flags: ::c_uint,
58 pub ifa_addr: *mut ::sockaddr,
59 pub ifa_netmask: *mut ::sockaddr,
60 pub ifa_dstaddr: *mut ::sockaddr,
61 pub ifa_data: *mut ::c_void
62 }
63
64 pub struct fd_set {
7453a54e 65 #[cfg(all(target_pointer_width = "64",
54a0048b 66 any(target_os = "freebsd", target_os = "dragonfly")))]
7453a54e
SL
67 fds_bits: [i64; FD_SETSIZE / 64],
68 #[cfg(not(all(target_pointer_width = "64",
54a0048b 69 any(target_os = "freebsd", target_os = "dragonfly"))))]
92a42be0
SL
70 fds_bits: [i32; FD_SETSIZE / 32],
71 }
72
73 pub struct tm {
74 pub tm_sec: ::c_int,
75 pub tm_min: ::c_int,
76 pub tm_hour: ::c_int,
77 pub tm_mday: ::c_int,
78 pub tm_mon: ::c_int,
79 pub tm_year: ::c_int,
80 pub tm_wday: ::c_int,
81 pub tm_yday: ::c_int,
82 pub tm_isdst: ::c_int,
83 pub tm_gmtoff: ::c_long,
84 pub tm_zone: *mut ::c_char,
85 }
9cc50fc6
SL
86
87 pub struct utsname {
54a0048b 88 #[cfg(not(target_os = "dragonfly"))]
9cc50fc6 89 pub sysname: [::c_char; 256],
54a0048b
SL
90 #[cfg(target_os = "dragonfly")]
91 pub sysname: [::c_char; 32],
92 #[cfg(not(target_os = "dragonfly"))]
9cc50fc6 93 pub nodename: [::c_char; 256],
54a0048b
SL
94 #[cfg(target_os = "dragonfly")]
95 pub nodename: [::c_char; 32],
96 #[cfg(not(target_os = "dragonfly"))]
9cc50fc6 97 pub release: [::c_char; 256],
54a0048b
SL
98 #[cfg(target_os = "dragonfly")]
99 pub release: [::c_char; 32],
100 #[cfg(not(target_os = "dragonfly"))]
9cc50fc6 101 pub version: [::c_char; 256],
54a0048b
SL
102 #[cfg(target_os = "dragonfly")]
103 pub version: [::c_char; 32],
104 #[cfg(not(target_os = "dragonfly"))]
9cc50fc6 105 pub machine: [::c_char; 256],
54a0048b
SL
106 #[cfg(target_os = "dragonfly")]
107 pub machine: [::c_char; 32],
9cc50fc6
SL
108 }
109
110 pub struct msghdr {
111 pub msg_name: *mut ::c_void,
112 pub msg_namelen: ::socklen_t,
113 pub msg_iov: *mut ::iovec,
114 pub msg_iovlen: ::c_int,
115 pub msg_control: *mut ::c_void,
116 pub msg_controllen: ::socklen_t,
117 pub msg_flags: ::c_int,
118 }
119
9cc50fc6
SL
120 pub struct fsid_t {
121 __fsid_val: [::int32_t; 2],
122 }
5bcae85e
SL
123
124 pub struct if_nameindex {
125 pub if_index: ::c_uint,
126 pub if_name: *mut ::c_char,
127 }
92a42be0
SL
128}
129
54a0048b
SL
130pub const LC_ALL: ::c_int = 0;
131pub const LC_COLLATE: ::c_int = 1;
132pub const LC_CTYPE: ::c_int = 2;
133pub const LC_MONETARY: ::c_int = 3;
134pub const LC_NUMERIC: ::c_int = 4;
135pub const LC_TIME: ::c_int = 5;
136pub const LC_MESSAGES: ::c_int = 6;
137
92a42be0
SL
138pub const FIOCLEX: ::c_ulong = 0x20006601;
139pub const FIONBIO: ::c_ulong = 0x8004667e;
140
9cc50fc6
SL
141pub const PATH_MAX: ::c_int = 1024;
142
92a42be0
SL
143pub const SA_ONSTACK: ::c_int = 0x0001;
144pub const SA_SIGINFO: ::c_int = 0x0040;
145pub const SA_RESTART: ::c_int = 0x0002;
146pub const SA_RESETHAND: ::c_int = 0x0004;
147pub const SA_NOCLDSTOP: ::c_int = 0x0008;
148pub const SA_NODEFER: ::c_int = 0x0010;
149pub const SA_NOCLDWAIT: ::c_int = 0x0020;
150
7453a54e
SL
151pub const SS_ONSTACK: ::c_int = 1;
152pub const SS_DISABLE: ::c_int = 4;
153
92a42be0
SL
154pub const SIGCHLD: ::c_int = 20;
155pub const SIGBUS: ::c_int = 10;
9cc50fc6
SL
156pub const SIGUSR1: ::c_int = 30;
157pub const SIGUSR2: ::c_int = 31;
158pub const SIGCONT: ::c_int = 19;
159pub const SIGSTOP: ::c_int = 17;
160pub const SIGTSTP: ::c_int = 18;
161pub const SIGURG: ::c_int = 16;
162pub const SIGIO: ::c_int = 23;
163pub const SIGSYS: ::c_int = 12;
164pub const SIGTTIN: ::c_int = 21;
165pub const SIGTTOU: ::c_int = 22;
166pub const SIGXCPU: ::c_int = 24;
167pub const SIGXFSZ: ::c_int = 25;
168pub const SIGVTALRM: ::c_int = 26;
169pub const SIGPROF: ::c_int = 27;
170pub const SIGWINCH: ::c_int = 28;
a7813a04 171pub const SIGINFO: ::c_int = 29;
9cc50fc6 172
92a42be0 173pub const SIG_SETMASK: ::c_int = 3;
9cc50fc6
SL
174pub const SIG_BLOCK: ::c_int = 0x1;
175pub const SIG_UNBLOCK: ::c_int = 0x2;
92a42be0
SL
176
177pub const IPV6_MULTICAST_LOOP: ::c_int = 11;
178pub const IPV6_V6ONLY: ::c_int = 27;
179
92a42be0 180pub const ST_RDONLY: ::c_ulong = 1;
92a42be0 181
9cc50fc6
SL
182pub const EV_ADD: ::uint16_t = 0x1;
183pub const EV_CLEAR: ::uint16_t = 0x20;
184pub const EV_DELETE: ::uint16_t = 0x2;
185pub const EV_DISABLE: ::uint16_t = 0x8;
186pub const EV_ENABLE: ::uint16_t = 0x4;
187pub const EV_EOF: ::uint16_t = 0x8000;
188pub const EV_ERROR: ::uint16_t = 0x4000;
189pub const EV_FLAG1: ::uint16_t = 0x2000;
190pub const EV_ONESHOT: ::uint16_t = 0x10;
191pub const EV_SYSFLAGS: ::uint16_t = 0xf000;
192
193pub const NOTE_ATTRIB: ::uint32_t = 0x8;
194pub const NOTE_CHILD: ::uint32_t = 0x4;
195pub const NOTE_DELETE: ::uint32_t = 0x1;
196pub const NOTE_EXEC: ::uint32_t = 0x20000000;
197pub const NOTE_EXIT: ::uint32_t = 0x80000000;
198pub const NOTE_EXTEND: ::uint32_t = 0x4;
199pub const NOTE_FORK: ::uint32_t = 0x40000000;
200pub const NOTE_LINK: ::uint32_t = 0x10;
201pub const NOTE_LOWAT: ::uint32_t = 0x1;
202pub const NOTE_PDATAMASK: ::uint32_t = 0x000fffff;
203pub const NOTE_RENAME: ::uint32_t = 0x20;
204pub const NOTE_REVOKE: ::uint32_t = 0x40;
205pub const NOTE_TRACK: ::uint32_t = 0x1;
206pub const NOTE_TRACKERR: ::uint32_t = 0x2;
207pub const NOTE_WRITE: ::uint32_t = 0x2;
208
209pub const NCCS: usize = 20;
210
211pub const O_ASYNC: ::c_int = 0x40;
212pub const O_FSYNC: ::c_int = 0x80;
213pub const O_NDELAY: ::c_int = 0x4;
214pub const O_NOFOLLOW: ::c_int = 0x100;
215
9cc50fc6 216pub const F_GETOWN: ::c_int = 5;
9cc50fc6
SL
217pub const F_SETOWN: ::c_int = 6;
218
219pub const MNT_FORCE: ::c_int = 0x80000;
220
221pub const Q_SYNC: ::c_int = 0x600;
222pub const Q_QUOTAON: ::c_int = 0x100;
223pub const Q_QUOTAOFF: ::c_int = 0x200;
9cc50fc6
SL
224
225pub const TCIOFF: ::c_int = 3;
226pub const TCION: ::c_int = 4;
227pub const TCOOFF: ::c_int = 1;
228pub const TCOON: ::c_int = 2;
229pub const TCIFLUSH: ::c_int = 1;
230pub const TCOFLUSH: ::c_int = 2;
231pub const TCIOFLUSH: ::c_int = 3;
232pub const TCSANOW: ::c_int = 0;
233pub const TCSADRAIN: ::c_int = 1;
234pub const TCSAFLUSH: ::c_int = 2;
9cc50fc6
SL
235pub const VEOF: usize = 0;
236pub const VEOL: usize = 1;
237pub const VEOL2: usize = 2;
238pub const VERASE: usize = 3;
239pub const VWERASE: usize = 4;
240pub const VKILL: usize = 5;
241pub const VREPRINT: usize = 6;
242pub const VINTR: usize = 8;
243pub const VQUIT: usize = 9;
244pub const VSUSP: usize = 10;
245pub const VSTART: usize = 12;
246pub const VSTOP: usize = 13;
247pub const VLNEXT: usize = 14;
248pub const VDISCARD: usize = 15;
249pub const VMIN: usize = 16;
250pub const VTIME: usize = 17;
251pub const IGNBRK: ::tcflag_t = 0x00000001;
252pub const BRKINT: ::tcflag_t = 0x00000002;
253pub const IGNPAR: ::tcflag_t = 0x00000004;
254pub const PARMRK: ::tcflag_t = 0x00000008;
255pub const INPCK: ::tcflag_t = 0x00000010;
256pub const ISTRIP: ::tcflag_t = 0x00000020;
257pub const INLCR: ::tcflag_t = 0x00000040;
258pub const IGNCR: ::tcflag_t = 0x00000080;
259pub const ICRNL: ::tcflag_t = 0x00000100;
260pub const IXON: ::tcflag_t = 0x00000200;
261pub const IXOFF: ::tcflag_t = 0x00000400;
262pub const IXANY: ::tcflag_t = 0x00000800;
263pub const IMAXBEL: ::tcflag_t = 0x00002000;
264pub const OPOST: ::tcflag_t = 0x1;
265pub const ONLCR: ::tcflag_t = 0x2;
266pub const CSIZE: ::tcflag_t = 0x00000300;
267pub const CS5: ::tcflag_t = 0x00000000;
268pub const CS6: ::tcflag_t = 0x00000100;
269pub const CS7: ::tcflag_t = 0x00000200;
270pub const CS8: ::tcflag_t = 0x00000300;
271pub const CSTOPB: ::tcflag_t = 0x00000400;
272pub const CREAD: ::tcflag_t = 0x00000800;
273pub const PARENB: ::tcflag_t = 0x00001000;
274pub const PARODD: ::tcflag_t = 0x00002000;
275pub const HUPCL: ::tcflag_t = 0x00004000;
276pub const CLOCAL: ::tcflag_t = 0x00008000;
277pub const ECHOKE: ::tcflag_t = 0x00000001;
278pub const ECHOE: ::tcflag_t = 0x00000002;
279pub const ECHOK: ::tcflag_t = 0x00000004;
280pub const ECHO: ::tcflag_t = 0x00000008;
281pub const ECHONL: ::tcflag_t = 0x00000010;
282pub const ECHOPRT: ::tcflag_t = 0x00000020;
283pub const ECHOCTL: ::tcflag_t = 0x00000040;
284pub const ISIG: ::tcflag_t = 0x00000080;
285pub const ICANON: ::tcflag_t = 0x00000100;
286pub const IEXTEN: ::tcflag_t = 0x00000400;
287pub const EXTPROC: ::tcflag_t = 0x00000800;
288pub const TOSTOP: ::tcflag_t = 0x00400000;
289pub const FLUSHO: ::tcflag_t = 0x00800000;
290pub const PENDIN: ::tcflag_t = 0x20000000;
291pub const NOFLSH: ::tcflag_t = 0x80000000;
92a42be0 292
5bcae85e
SL
293pub const WNOHANG: ::c_int = 0x00000001;
294pub const WUNTRACED: ::c_int = 0x00000002;
7453a54e
SL
295
296pub const RTLD_NOW: ::c_int = 0x2;
54a0048b 297pub const RTLD_DEFAULT: *mut ::c_void = -2isize as *mut ::c_void;
7453a54e 298
a7813a04
XL
299pub const LOG_CRON: ::c_int = 9 << 3;
300pub const LOG_AUTHPRIV: ::c_int = 10 << 3;
301pub const LOG_FTP: ::c_int = 11 << 3;
302pub const LOG_PERROR: ::c_int = 0x20;
303
304pub const PIPE_BUF: usize = 512;
305
92a42be0
SL
306f! {
307 pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
7453a54e 308 let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8;
92a42be0 309 let fd = fd as usize;
7453a54e 310 (*set).fds_bits[fd / bits] &= !(1 << (fd % bits));
92a42be0
SL
311 return
312 }
313
314 pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool {
7453a54e 315 let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8;
92a42be0 316 let fd = fd as usize;
7453a54e 317 return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0
92a42be0
SL
318 }
319
320 pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () {
7453a54e 321 let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8;
92a42be0 322 let fd = fd as usize;
7453a54e 323 (*set).fds_bits[fd / bits] |= 1 << (fd % bits);
92a42be0
SL
324 return
325 }
326
327 pub fn FD_ZERO(set: *mut fd_set) -> () {
328 for slot in (*set).fds_bits.iter_mut() {
329 *slot = 0;
330 }
331 }
332
5bcae85e
SL
333 pub fn WTERMSIG(status: ::c_int) -> ::c_int {
334 status & 0o177
335 }
336
92a42be0 337 pub fn WIFEXITED(status: ::c_int) -> bool {
5bcae85e 338 (status & 0o177) == 0
92a42be0
SL
339 }
340
341 pub fn WEXITSTATUS(status: ::c_int) -> ::c_int {
342 status >> 8
343 }
344
a7813a04
XL
345 pub fn WCOREDUMP(status: ::c_int) -> bool {
346 (status & 0o200) != 0
347 }
92a42be0
SL
348}
349
350extern {
92a42be0
SL
351 pub fn setgroups(ngroups: ::c_int,
352 ptr: *const ::gid_t) -> ::c_int;
353 pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int;
9cc50fc6
SL
354 pub fn kqueue() -> ::c_int;
355 pub fn unmount(target: *const ::c_char, arg: ::c_int) -> ::c_int;
356 pub fn syscall(num: ::c_int, ...) -> ::c_int;
7453a54e
SL
357 #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")]
358 pub fn getpwuid_r(uid: ::uid_t,
359 pwd: *mut passwd,
360 buf: *mut ::c_char,
361 buflen: ::size_t,
362 result: *mut *mut passwd) -> ::c_int;
a7813a04
XL
363 pub fn getprogname() -> *const ::c_char;
364 pub fn setprogname(name: *const ::c_char);
365 pub fn getloadavg(loadavg: *mut ::c_double, nelem: ::c_int) -> ::c_int;
5bcae85e
SL
366 pub fn if_nameindex() -> *mut if_nameindex;
367 pub fn if_freenameindex(ptr: *mut if_nameindex);
92a42be0
SL
368}
369
370cfg_if! {
371 if #[cfg(any(target_os = "macos", target_os = "ios"))] {
372 mod apple;
373 pub use self::apple::*;
374 } else if #[cfg(any(target_os = "openbsd", target_os = "netbsd",
375 target_os = "bitrig"))] {
376 mod openbsdlike;
377 pub use self::openbsdlike::*;
378 } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] {
379 mod freebsdlike;
380 pub use self::freebsdlike::*;
381 } else {
54a0048b 382 // Unknown target_os
92a42be0
SL
383 }
384}