1 // Copyright 2014 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
15 pub use self::select::fd_set;
16 pub use self::signal::{sigaction, siginfo, sigset_t};
17 pub use self::signal::{SA_ONSTACK, SA_RESTART, SA_RESETHAND, SA_NOCLDSTOP};
18 pub use self::signal::{SA_NODEFER, SA_NOCLDWAIT, SA_SIGINFO, SIGCHLD};
22 #[cfg(any(target_os = "macos",
24 target_os = "freebsd",
25 target_os = "dragonfly"))]
26 pub static FIONBIO: libc::c_ulong = 0x8004667e;
27 #[cfg(any(all(target_os = "linux",
28 any(target_arch = "x86",
29 target_arch = "x86_64",
30 target_arch = "arm")),
31 target_os = "android"))]
32 pub static FIONBIO: libc::c_ulong = 0x5421;
33 #[cfg(all(target_os = "linux",
34 any(target_arch = "mips", target_arch = "mipsel")))]
35 pub static FIONBIO: libc::c_ulong = 0x667e;
37 #[cfg(any(target_os = "macos",
39 target_os = "freebsd",
40 target_os = "dragonfly"))]
41 pub static FIOCLEX: libc::c_ulong = 0x20006601;
42 #[cfg(any(all(target_os = "linux",
43 any(target_arch = "x86",
44 target_arch = "x86_64",
45 target_arch = "arm")),
46 target_os = "android"))]
47 pub static FIOCLEX: libc::c_ulong = 0x5451;
48 #[cfg(all(target_os = "linux",
49 any(target_arch = "mips", target_arch = "mipsel")))]
50 pub static FIOCLEX: libc::c_ulong = 0x6601;
52 #[cfg(any(target_os = "macos",
54 target_os = "freebsd",
55 target_os = "dragonfly"))]
56 pub static MSG_DONTWAIT: libc::c_int = 0x80;
57 #[cfg(any(target_os = "linux", target_os = "android"))]
58 pub static MSG_DONTWAIT: libc::c_int = 0x40;
60 pub static WNOHANG: libc::c_int = 1;
63 pub fn gettimeofday(timeval: *mut libc::timeval,
64 tzp: *mut libc::c_void) -> libc::c_int;
65 pub fn select(nfds: libc::c_int,
67 writefds: *mut fd_set,
68 errorfds: *mut fd_set,
69 timeout: *mut libc::timeval) -> libc::c_int;
70 pub fn getsockopt(sockfd: libc::c_int,
73 optval: *mut libc::c_void,
74 optlen: *mut libc::socklen_t) -> libc::c_int;
75 pub fn ioctl(fd: libc::c_int, req: libc::c_ulong, ...) -> libc::c_int;
78 pub fn waitpid(pid: libc::pid_t, status: *mut libc::c_int,
79 options: libc::c_int) -> libc::pid_t;
81 pub fn sigaction(signum: libc::c_int,
82 act: *const sigaction,
83 oldact: *mut sigaction) -> libc::c_int;
85 pub fn sigaddset(set: *mut sigset_t, signum: libc::c_int) -> libc::c_int;
86 pub fn sigdelset(set: *mut sigset_t, signum: libc::c_int) -> libc::c_int;
87 pub fn sigemptyset(set: *mut sigset_t) -> libc::c_int;
90 #[cfg(any(target_os = "macos", target_os = "ios"))]
92 pub static FD_SETSIZE: uint = 1024;
96 fds_bits: [i32, ..(FD_SETSIZE / 32)]
99 pub fn fd_set(set: &mut fd_set, fd: i32) {
100 set.fds_bits[(fd / 32) as uint] |= 1 << ((fd % 32) as uint);
104 #[cfg(any(target_os = "android",
105 target_os = "freebsd",
106 target_os = "dragonfly",
107 target_os = "linux"))]
112 pub static FD_SETSIZE: uint = 1024;
116 // FIXME: shouldn't this be a c_ulong?
117 fds_bits: [libc::uintptr_t, ..(FD_SETSIZE / uint::BITS)]
120 pub fn fd_set(set: &mut fd_set, fd: i32) {
122 set.fds_bits[fd / uint::BITS] |= 1 << (fd % uint::BITS);
126 #[cfg(any(all(target_os = "linux",
127 any(target_arch = "x86",
128 target_arch = "x86_64",
129 target_arch = "arm")),
130 target_os = "android"))]
134 pub static SA_NOCLDSTOP: libc::c_ulong = 0x00000001;
135 pub static SA_NOCLDWAIT: libc::c_ulong = 0x00000002;
136 pub static SA_NODEFER: libc::c_ulong = 0x40000000;
137 pub static SA_ONSTACK: libc::c_ulong = 0x08000000;
138 pub static SA_RESETHAND: libc::c_ulong = 0x80000000;
139 pub static SA_RESTART: libc::c_ulong = 0x10000000;
140 pub static SA_SIGINFO: libc::c_ulong = 0x00000004;
141 pub static SIGCHLD: libc::c_int = 17;
143 // This definition is not as accurate as it could be, {pid, uid, status} is
144 // actually a giant union. Currently we're only interested in these fields,
148 si_signo: libc::c_int,
149 si_errno: libc::c_int,
150 si_code: libc::c_int,
151 pub pid: libc::pid_t,
152 pub uid: libc::uid_t,
153 pub status: libc::c_int,
157 pub struct sigaction {
158 pub sa_handler: extern fn(libc::c_int),
159 pub sa_mask: sigset_t,
160 pub sa_flags: libc::c_ulong,
161 sa_restorer: *mut libc::c_void,
165 #[cfg(target_word_size = "32")]
166 pub struct sigset_t {
167 __val: [libc::c_ulong, ..32],
171 #[cfg(target_word_size = "64")]
172 pub struct sigset_t {
173 __val: [libc::c_ulong, ..16],
177 #[cfg(all(target_os = "linux",
178 any(target_arch = "mips", target_arch = "mipsel")))]
182 pub static SA_NOCLDSTOP: libc::c_ulong = 0x00000001;
183 pub static SA_NOCLDWAIT: libc::c_ulong = 0x00010000;
184 pub static SA_NODEFER: libc::c_ulong = 0x40000000;
185 pub static SA_ONSTACK: libc::c_ulong = 0x08000000;
186 pub static SA_RESETHAND: libc::c_ulong = 0x80000000;
187 pub static SA_RESTART: libc::c_ulong = 0x10000000;
188 pub static SA_SIGINFO: libc::c_ulong = 0x00000008;
189 pub static SIGCHLD: libc::c_int = 18;
191 // This definition is not as accurate as it could be, {pid, uid, status} is
192 // actually a giant union. Currently we're only interested in these fields,
196 si_signo: libc::c_int,
197 si_code: libc::c_int,
198 si_errno: libc::c_int,
199 pub pid: libc::pid_t,
200 pub uid: libc::uid_t,
201 pub status: libc::c_int,
205 pub struct sigaction {
206 pub sa_flags: libc::c_uint,
207 pub sa_handler: extern fn(libc::c_int),
208 pub sa_mask: sigset_t,
209 sa_restorer: *mut libc::c_void,
210 sa_resv: [libc::c_int, ..1],
214 pub struct sigset_t {
215 __val: [libc::c_ulong, ..32],
219 #[cfg(any(target_os = "macos",
221 target_os = "freebsd",
222 target_os = "dragonfly"))]
226 pub static SA_ONSTACK: libc::c_int = 0x0001;
227 pub static SA_RESTART: libc::c_int = 0x0002;
228 pub static SA_RESETHAND: libc::c_int = 0x0004;
229 pub static SA_NOCLDSTOP: libc::c_int = 0x0008;
230 pub static SA_NODEFER: libc::c_int = 0x0010;
231 pub static SA_NOCLDWAIT: libc::c_int = 0x0020;
232 pub static SA_SIGINFO: libc::c_int = 0x0040;
233 pub static SIGCHLD: libc::c_int = 20;
235 #[cfg(target_os = "macos")]
236 #[cfg(target_os = "ios")]
237 pub type sigset_t = u32;
238 #[cfg(target_os = "freebsd")]
239 #[cfg(target_os = "dragonfly")]
241 pub struct sigset_t {
245 // This structure has more fields, but we're not all that interested in
249 pub si_signo: libc::c_int,
250 pub si_errno: libc::c_int,
251 pub si_code: libc::c_int,
252 pub pid: libc::pid_t,
253 pub uid: libc::uid_t,
254 pub status: libc::c_int,
257 #[cfg(target_os = "macos")]
258 #[cfg(target_os = "ios")]
260 pub struct sigaction {
261 pub sa_handler: extern fn(libc::c_int),
262 sa_tramp: *mut libc::c_void,
263 pub sa_mask: sigset_t,
264 pub sa_flags: libc::c_int,
267 #[cfg(target_os = "freebsd")]
268 #[cfg(target_os = "dragonfly")]
270 pub struct sigaction {
271 pub sa_handler: extern fn(libc::c_int),
272 pub sa_flags: libc::c_int,
273 pub sa_mask: sigset_t,