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(target_os = "macos")]
23 #[cfg(target_os = "ios")]
24 #[cfg(target_os = "freebsd")]
25 #[cfg(target_os = "dragonfly")]
26 pub static FIONBIO: libc::c_ulong = 0x8004667e;
27 #[cfg(target_os = "linux", target_arch = "x86")]
28 #[cfg(target_os = "linux", target_arch = "x86_64")]
29 #[cfg(target_os = "linux", target_arch = "arm")]
30 #[cfg(target_os = "android")]
31 pub static FIONBIO: libc::c_ulong = 0x5421;
32 #[cfg(target_os = "linux", target_arch = "mips")]
33 #[cfg(target_os = "linux", target_arch = "mipsel")]
34 pub static FIONBIO: libc::c_ulong = 0x667e;
36 #[cfg(target_os = "macos")]
37 #[cfg(target_os = "ios")]
38 #[cfg(target_os = "freebsd")]
39 #[cfg(target_os = "dragonfly")]
40 pub static FIOCLEX: libc::c_ulong = 0x20006601;
41 #[cfg(target_os = "linux", target_arch = "x86")]
42 #[cfg(target_os = "linux", target_arch = "x86_64")]
43 #[cfg(target_os = "linux", target_arch = "arm")]
44 #[cfg(target_os = "android")]
45 pub static FIOCLEX: libc::c_ulong = 0x5451;
46 #[cfg(target_os = "linux", target_arch = "mips")]
47 #[cfg(target_os = "linux", target_arch = "mipsel")]
48 pub static FIOCLEX: libc::c_ulong = 0x6601;
50 #[cfg(target_os = "macos")]
51 #[cfg(target_os = "ios")]
52 #[cfg(target_os = "freebsd")]
53 #[cfg(target_os = "dragonfly")]
54 pub static MSG_DONTWAIT: libc::c_int = 0x80;
55 #[cfg(target_os = "linux")]
56 #[cfg(target_os = "android")]
57 pub static MSG_DONTWAIT: libc::c_int = 0x40;
59 pub static WNOHANG: libc::c_int = 1;
62 pub fn gettimeofday(timeval: *mut libc::timeval,
63 tzp: *mut libc::c_void) -> libc::c_int;
64 pub fn select(nfds: libc::c_int,
66 writefds: *mut fd_set,
67 errorfds: *mut fd_set,
68 timeout: *mut libc::timeval) -> libc::c_int;
69 pub fn getsockopt(sockfd: libc::c_int,
72 optval: *mut libc::c_void,
73 optlen: *mut libc::socklen_t) -> libc::c_int;
74 pub fn ioctl(fd: libc::c_int, req: libc::c_ulong, ...) -> libc::c_int;
77 pub fn waitpid(pid: libc::pid_t, status: *mut libc::c_int,
78 options: libc::c_int) -> libc::pid_t;
80 pub fn sigaction(signum: libc::c_int,
81 act: *const sigaction,
82 oldact: *mut sigaction) -> libc::c_int;
84 pub fn sigaddset(set: *mut sigset_t, signum: libc::c_int) -> libc::c_int;
85 pub fn sigdelset(set: *mut sigset_t, signum: libc::c_int) -> libc::c_int;
86 pub fn sigemptyset(set: *mut sigset_t) -> libc::c_int;
89 #[cfg(target_os = "macos")]
90 #[cfg(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(target_os = "android")]
105 #[cfg(target_os = "freebsd")]
106 #[cfg(target_os = "dragonfly")]
107 #[cfg(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(target_os = "linux", target_arch = "x86")]
127 #[cfg(target_os = "linux", target_arch = "x86_64")]
128 #[cfg(target_os = "linux", target_arch = "arm")]
129 #[cfg(target_os = "android")]
133 pub static SA_NOCLDSTOP: libc::c_ulong = 0x00000001;
134 pub static SA_NOCLDWAIT: libc::c_ulong = 0x00000002;
135 pub static SA_NODEFER: libc::c_ulong = 0x40000000;
136 pub static SA_ONSTACK: libc::c_ulong = 0x08000000;
137 pub static SA_RESETHAND: libc::c_ulong = 0x80000000;
138 pub static SA_RESTART: libc::c_ulong = 0x10000000;
139 pub static SA_SIGINFO: libc::c_ulong = 0x00000004;
140 pub static SIGCHLD: libc::c_int = 17;
142 // This definition is not as accurate as it could be, {pid, uid, status} is
143 // actually a giant union. Currently we're only interested in these fields,
147 si_signo: libc::c_int,
148 si_errno: libc::c_int,
149 si_code: libc::c_int,
150 pub pid: libc::pid_t,
151 pub uid: libc::uid_t,
152 pub status: libc::c_int,
156 pub struct sigaction {
157 pub sa_handler: extern fn(libc::c_int),
158 pub sa_mask: sigset_t,
159 pub sa_flags: libc::c_ulong,
160 sa_restorer: *mut libc::c_void,
164 #[cfg(target_word_size = "32")]
165 pub struct sigset_t {
166 __val: [libc::c_ulong, ..32],
170 #[cfg(target_word_size = "64")]
171 pub struct sigset_t {
172 __val: [libc::c_ulong, ..16],
176 #[cfg(target_os = "linux", target_arch = "mips")]
177 #[cfg(target_os = "linux", target_arch = "mipsel")]
181 pub static SA_NOCLDSTOP: libc::c_ulong = 0x00000001;
182 pub static SA_NOCLDWAIT: libc::c_ulong = 0x00010000;
183 pub static SA_NODEFER: libc::c_ulong = 0x40000000;
184 pub static SA_ONSTACK: libc::c_ulong = 0x08000000;
185 pub static SA_RESETHAND: libc::c_ulong = 0x80000000;
186 pub static SA_RESTART: libc::c_ulong = 0x10000000;
187 pub static SA_SIGINFO: libc::c_ulong = 0x00000008;
188 pub static SIGCHLD: libc::c_int = 18;
190 // This definition is not as accurate as it could be, {pid, uid, status} is
191 // actually a giant union. Currently we're only interested in these fields,
195 si_signo: libc::c_int,
196 si_code: libc::c_int,
197 si_errno: libc::c_int,
198 pub pid: libc::pid_t,
199 pub uid: libc::uid_t,
200 pub status: libc::c_int,
204 pub struct sigaction {
205 pub sa_flags: libc::c_uint,
206 pub sa_handler: extern fn(libc::c_int),
207 pub sa_mask: sigset_t,
208 sa_restorer: *mut libc::c_void,
209 sa_resv: [libc::c_int, ..1],
213 pub struct sigset_t {
214 __val: [libc::c_ulong, ..32],
218 #[cfg(target_os = "macos")]
219 #[cfg(target_os = "ios")]
220 #[cfg(target_os = "freebsd")]
221 #[cfg(target_os = "dragonfly")]
225 pub static SA_ONSTACK: libc::c_int = 0x0001;
226 pub static SA_RESTART: libc::c_int = 0x0002;
227 pub static SA_RESETHAND: libc::c_int = 0x0004;
228 pub static SA_NOCLDSTOP: libc::c_int = 0x0008;
229 pub static SA_NODEFER: libc::c_int = 0x0010;
230 pub static SA_NOCLDWAIT: libc::c_int = 0x0020;
231 pub static SA_SIGINFO: libc::c_int = 0x0040;
232 pub static SIGCHLD: libc::c_int = 20;
234 #[cfg(target_os = "macos")]
235 #[cfg(target_os = "ios")]
236 pub type sigset_t = u32;
237 #[cfg(target_os = "freebsd")]
238 #[cfg(target_os = "dragonfly")]
240 pub struct sigset_t {
244 // This structure has more fields, but we're not all that interested in
248 pub si_signo: libc::c_int,
249 pub si_errno: libc::c_int,
250 pub si_code: libc::c_int,
251 pub pid: libc::pid_t,
252 pub uid: libc::uid_t,
253 pub status: libc::c_int,
256 #[cfg(target_os = "macos")]
257 #[cfg(target_os = "ios")]
259 pub struct sigaction {
260 pub sa_handler: extern fn(libc::c_int),
261 sa_tramp: *mut libc::c_void,
262 pub sa_mask: sigset_t,
263 pub sa_flags: libc::c_int,
266 #[cfg(target_os = "freebsd")]
267 #[cfg(target_os = "dragonfly")]
269 pub struct sigaction {
270 pub sa_handler: extern fn(libc::c_int),
271 pub sa_flags: libc::c_int,
272 pub sa_mask: sigset_t,