1 // Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! C definitions used by libnative that don't belong in liblibc
14 #![allow(non_camel_case_types)]
16 pub use self::select::fd_set;
17 pub use self::signal::{sigaction, siginfo, sigset_t};
18 pub use self::signal::{SA_ONSTACK, SA_RESTART, SA_RESETHAND, SA_NOCLDSTOP};
19 pub use self::signal::{SA_NODEFER, SA_NOCLDWAIT, SA_SIGINFO, SIGCHLD};
23 #[cfg(any(target_os = "macos",
25 target_os = "freebsd",
26 target_os = "dragonfly"))]
27 pub const FIONBIO: libc::c_ulong = 0x8004667e;
28 #[cfg(any(all(target_os = "linux",
29 any(target_arch = "x86",
30 target_arch = "x86_64",
32 target_arch = "aarch64")),
33 target_os = "android"))]
34 pub const FIONBIO: libc::c_ulong = 0x5421;
35 #[cfg(all(target_os = "linux",
36 any(target_arch = "mips",
37 target_arch = "mipsel",
38 target_arch = "powerpc")))]
39 pub const FIONBIO: libc::c_ulong = 0x667e;
41 #[cfg(any(target_os = "macos",
43 target_os = "freebsd",
44 target_os = "dragonfly"))]
45 pub const FIOCLEX: libc::c_ulong = 0x20006601;
46 #[cfg(any(all(target_os = "linux",
47 any(target_arch = "x86",
48 target_arch = "x86_64",
50 target_arch = "aarch64")),
51 target_os = "android"))]
52 pub const FIOCLEX: libc::c_ulong = 0x5451;
53 #[cfg(all(target_os = "linux",
54 any(target_arch = "mips",
55 target_arch = "mipsel",
56 target_arch = "powerpc")))]
57 pub const FIOCLEX: libc::c_ulong = 0x6601;
59 #[cfg(any(target_os = "macos",
61 target_os = "freebsd",
62 target_os = "dragonfly"))]
63 pub const MSG_DONTWAIT: libc::c_int = 0x80;
64 #[cfg(any(target_os = "linux", target_os = "android"))]
65 pub const MSG_DONTWAIT: libc::c_int = 0x40;
67 pub const WNOHANG: libc::c_int = 1;
70 pub fn gettimeofday(timeval: *mut libc::timeval,
71 tzp: *mut libc::c_void) -> libc::c_int;
72 pub fn select(nfds: libc::c_int,
74 writefds: *mut fd_set,
75 errorfds: *mut fd_set,
76 timeout: *mut libc::timeval) -> libc::c_int;
77 pub fn getsockopt(sockfd: libc::c_int,
80 optval: *mut libc::c_void,
81 optlen: *mut libc::socklen_t) -> libc::c_int;
82 pub fn ioctl(fd: libc::c_int, req: libc::c_ulong, ...) -> libc::c_int;
85 pub fn waitpid(pid: libc::pid_t, status: *mut libc::c_int,
86 options: libc::c_int) -> libc::pid_t;
88 pub fn sigaction(signum: libc::c_int,
89 act: *const sigaction,
90 oldact: *mut sigaction) -> libc::c_int;
92 pub fn sigaddset(set: *mut sigset_t, signum: libc::c_int) -> libc::c_int;
93 pub fn sigdelset(set: *mut sigset_t, signum: libc::c_int) -> libc::c_int;
94 pub fn sigemptyset(set: *mut sigset_t) -> libc::c_int;
97 #[cfg(any(target_os = "macos", target_os = "ios"))]
99 pub const FD_SETSIZE: uint = 1024;
103 fds_bits: [i32; (FD_SETSIZE / 32)]
106 pub fn fd_set(set: &mut fd_set, fd: i32) {
107 set.fds_bits[(fd / 32) as uint] |= 1 << ((fd % 32) as uint);
111 #[cfg(any(target_os = "android",
112 target_os = "freebsd",
113 target_os = "dragonfly",
114 target_os = "linux"))]
119 pub const FD_SETSIZE: uint = 1024;
123 // FIXME: shouldn't this be a c_ulong?
124 fds_bits: [libc::uintptr_t; (FD_SETSIZE / uint::BITS)]
127 pub fn fd_set(set: &mut fd_set, fd: i32) {
129 set.fds_bits[fd / uint::BITS] |= 1 << (fd % uint::BITS);
133 #[cfg(any(all(target_os = "linux",
134 any(target_arch = "x86",
135 target_arch = "x86_64",
137 target_arch = "aarch64")),
138 target_os = "android"))]
142 pub const SA_NOCLDSTOP: libc::c_ulong = 0x00000001;
143 pub const SA_NOCLDWAIT: libc::c_ulong = 0x00000002;
144 pub const SA_NODEFER: libc::c_ulong = 0x40000000;
145 pub const SA_ONSTACK: libc::c_ulong = 0x08000000;
146 pub const SA_RESETHAND: libc::c_ulong = 0x80000000;
147 pub const SA_RESTART: libc::c_ulong = 0x10000000;
148 pub const SA_SIGINFO: libc::c_ulong = 0x00000004;
149 pub const SIGCHLD: libc::c_int = 17;
151 // This definition is not as accurate as it could be, {pid, uid, status} is
152 // actually a giant union. Currently we're only interested in these fields,
156 si_signo: libc::c_int,
157 si_errno: libc::c_int,
158 si_code: libc::c_int,
159 pub pid: libc::pid_t,
160 pub uid: libc::uid_t,
161 pub status: libc::c_int,
165 pub struct sigaction {
166 pub sa_handler: extern fn(libc::c_int),
167 pub sa_mask: sigset_t,
168 pub sa_flags: libc::c_ulong,
169 sa_restorer: *mut libc::c_void,
172 unsafe impl ::marker::Send for sigaction { }
173 unsafe impl ::marker::Sync for sigaction { }
176 #[cfg(any(all(stage0, target_word_size = "32"), all(not(stage0), target_pointer_width = "32")))]
177 pub struct sigset_t {
178 __val: [libc::c_ulong; 32],
182 #[cfg(any(all(stage0, target_word_size = "64"), all(not(stage0), target_pointer_width = "64")))]
183 pub struct sigset_t {
184 __val: [libc::c_ulong; 16],
188 #[cfg(all(target_os = "linux",
189 any(target_arch = "mips",
190 target_arch = "mipsel",
191 target_arch = "powerpc")))]
195 pub const SA_NOCLDSTOP: libc::c_ulong = 0x00000001;
196 pub const SA_NOCLDWAIT: libc::c_ulong = 0x00010000;
197 pub const SA_NODEFER: libc::c_ulong = 0x40000000;
198 pub const SA_ONSTACK: libc::c_ulong = 0x08000000;
199 pub const SA_RESETHAND: libc::c_ulong = 0x80000000;
200 pub const SA_RESTART: libc::c_ulong = 0x10000000;
201 pub const SA_SIGINFO: libc::c_ulong = 0x00000008;
202 pub const SIGCHLD: libc::c_int = 18;
204 // This definition is not as accurate as it could be, {pid, uid, status} is
205 // actually a giant union. Currently we're only interested in these fields,
209 si_signo: libc::c_int,
210 si_code: libc::c_int,
211 si_errno: libc::c_int,
212 pub pid: libc::pid_t,
213 pub uid: libc::uid_t,
214 pub status: libc::c_int,
218 pub struct sigaction {
219 pub sa_flags: libc::c_uint,
220 pub sa_handler: extern fn(libc::c_int),
221 pub sa_mask: sigset_t,
222 sa_restorer: *mut libc::c_void,
223 sa_resv: [libc::c_int; 1],
226 unsafe impl ::marker::Send for sigaction { }
227 unsafe impl ::marker::Sync for sigaction { }
230 pub struct sigset_t {
231 __val: [libc::c_ulong; 32],
235 #[cfg(any(target_os = "macos",
237 target_os = "freebsd",
238 target_os = "dragonfly"))]
242 pub const SA_ONSTACK: libc::c_int = 0x0001;
243 pub const SA_RESTART: libc::c_int = 0x0002;
244 pub const SA_RESETHAND: libc::c_int = 0x0004;
245 pub const SA_NOCLDSTOP: libc::c_int = 0x0008;
246 pub const SA_NODEFER: libc::c_int = 0x0010;
247 pub const SA_NOCLDWAIT: libc::c_int = 0x0020;
248 pub const SA_SIGINFO: libc::c_int = 0x0040;
249 pub const SIGCHLD: libc::c_int = 20;
251 #[cfg(any(target_os = "macos", target_os = "ios"))]
252 pub type sigset_t = u32;
253 #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
255 pub struct sigset_t {
259 // This structure has more fields, but we're not all that interested in
263 pub si_signo: libc::c_int,
264 pub si_errno: libc::c_int,
265 pub si_code: libc::c_int,
266 pub pid: libc::pid_t,
267 pub uid: libc::uid_t,
268 pub status: libc::c_int,
272 pub struct sigaction {
273 pub sa_handler: extern fn(libc::c_int),
274 pub sa_flags: libc::c_int,
275 pub sa_mask: sigset_t,