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
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",
31 target_arch = "arm")),
32 target_os = "android"))]
33 pub const FIONBIO: libc::c_ulong = 0x5421;
34 #[cfg(all(target_os = "linux",
35 any(target_arch = "mips", target_arch = "mipsel")))]
36 pub const FIONBIO: libc::c_ulong = 0x667e;
38 #[cfg(any(target_os = "macos",
40 target_os = "freebsd",
41 target_os = "dragonfly"))]
42 pub const FIOCLEX: libc::c_ulong = 0x20006601;
43 #[cfg(any(all(target_os = "linux",
44 any(target_arch = "x86",
45 target_arch = "x86_64",
46 target_arch = "arm")),
47 target_os = "android"))]
48 pub const FIOCLEX: libc::c_ulong = 0x5451;
49 #[cfg(all(target_os = "linux",
50 any(target_arch = "mips", target_arch = "mipsel")))]
51 pub const FIOCLEX: libc::c_ulong = 0x6601;
53 #[cfg(any(target_os = "macos",
55 target_os = "freebsd",
56 target_os = "dragonfly"))]
57 pub const MSG_DONTWAIT: libc::c_int = 0x80;
58 #[cfg(any(target_os = "linux", target_os = "android"))]
59 pub const MSG_DONTWAIT: libc::c_int = 0x40;
61 pub const WNOHANG: libc::c_int = 1;
64 pub fn gettimeofday(timeval: *mut libc::timeval,
65 tzp: *mut libc::c_void) -> libc::c_int;
66 pub fn select(nfds: libc::c_int,
68 writefds: *mut fd_set,
69 errorfds: *mut fd_set,
70 timeout: *mut libc::timeval) -> libc::c_int;
71 pub fn getsockopt(sockfd: libc::c_int,
74 optval: *mut libc::c_void,
75 optlen: *mut libc::socklen_t) -> libc::c_int;
76 pub fn ioctl(fd: libc::c_int, req: libc::c_ulong, ...) -> libc::c_int;
79 pub fn waitpid(pid: libc::pid_t, status: *mut libc::c_int,
80 options: libc::c_int) -> libc::pid_t;
82 pub fn sigaction(signum: libc::c_int,
83 act: *const sigaction,
84 oldact: *mut sigaction) -> libc::c_int;
86 pub fn sigaddset(set: *mut sigset_t, signum: libc::c_int) -> libc::c_int;
87 pub fn sigdelset(set: *mut sigset_t, signum: libc::c_int) -> libc::c_int;
88 pub fn sigemptyset(set: *mut sigset_t) -> libc::c_int;
91 #[cfg(any(target_os = "macos", target_os = "ios"))]
93 pub const FD_SETSIZE: uint = 1024;
97 fds_bits: [i32, ..(FD_SETSIZE / 32)]
100 pub fn fd_set(set: &mut fd_set, fd: i32) {
101 set.fds_bits[(fd / 32) as uint] |= 1 << ((fd % 32) as uint);
105 #[cfg(any(target_os = "android",
106 target_os = "freebsd",
107 target_os = "dragonfly",
108 target_os = "linux"))]
113 pub const FD_SETSIZE: uint = 1024;
117 // FIXME: shouldn't this be a c_ulong?
118 fds_bits: [libc::uintptr_t, ..(FD_SETSIZE / uint::BITS)]
121 pub fn fd_set(set: &mut fd_set, fd: i32) {
123 set.fds_bits[fd / uint::BITS] |= 1 << (fd % uint::BITS);
127 #[cfg(any(all(target_os = "linux",
128 any(target_arch = "x86",
129 target_arch = "x86_64",
130 target_arch = "arm")),
131 target_os = "android"))]
135 pub const SA_NOCLDSTOP: libc::c_ulong = 0x00000001;
136 pub const SA_NOCLDWAIT: libc::c_ulong = 0x00000002;
137 pub const SA_NODEFER: libc::c_ulong = 0x40000000;
138 pub const SA_ONSTACK: libc::c_ulong = 0x08000000;
139 pub const SA_RESETHAND: libc::c_ulong = 0x80000000;
140 pub const SA_RESTART: libc::c_ulong = 0x10000000;
141 pub const SA_SIGINFO: libc::c_ulong = 0x00000004;
142 pub const SIGCHLD: libc::c_int = 17;
144 // This definition is not as accurate as it could be, {pid, uid, status} is
145 // actually a giant union. Currently we're only interested in these fields,
149 si_signo: libc::c_int,
150 si_errno: libc::c_int,
151 si_code: libc::c_int,
152 pub pid: libc::pid_t,
153 pub uid: libc::uid_t,
154 pub status: libc::c_int,
158 pub struct sigaction {
159 pub sa_handler: extern fn(libc::c_int),
160 pub sa_mask: sigset_t,
161 pub sa_flags: libc::c_ulong,
162 sa_restorer: *mut libc::c_void,
165 unsafe impl ::kinds::Send for sigaction { }
166 unsafe impl ::kinds::Sync for sigaction { }
169 #[cfg(target_word_size = "32")]
170 pub struct sigset_t {
171 __val: [libc::c_ulong, ..32],
175 #[cfg(target_word_size = "64")]
176 pub struct sigset_t {
177 __val: [libc::c_ulong, ..16],
181 #[cfg(all(target_os = "linux",
182 any(target_arch = "mips", target_arch = "mipsel")))]
186 pub const SA_NOCLDSTOP: libc::c_ulong = 0x00000001;
187 pub const SA_NOCLDWAIT: libc::c_ulong = 0x00010000;
188 pub const SA_NODEFER: libc::c_ulong = 0x40000000;
189 pub const SA_ONSTACK: libc::c_ulong = 0x08000000;
190 pub const SA_RESETHAND: libc::c_ulong = 0x80000000;
191 pub const SA_RESTART: libc::c_ulong = 0x10000000;
192 pub const SA_SIGINFO: libc::c_ulong = 0x00000008;
193 pub const SIGCHLD: libc::c_int = 18;
195 // This definition is not as accurate as it could be, {pid, uid, status} is
196 // actually a giant union. Currently we're only interested in these fields,
200 si_signo: libc::c_int,
201 si_code: libc::c_int,
202 si_errno: libc::c_int,
203 pub pid: libc::pid_t,
204 pub uid: libc::uid_t,
205 pub status: libc::c_int,
209 pub struct sigaction {
210 pub sa_flags: libc::c_uint,
211 pub sa_handler: extern fn(libc::c_int),
212 pub sa_mask: sigset_t,
213 sa_restorer: *mut libc::c_void,
214 sa_resv: [libc::c_int, ..1],
217 unsafe impl ::kinds::Send for sigaction { }
218 unsafe impl ::kinds::Sync for sigaction { }
221 pub struct sigset_t {
222 __val: [libc::c_ulong, ..32],
226 #[cfg(any(target_os = "macos",
228 target_os = "freebsd",
229 target_os = "dragonfly"))]
233 pub const SA_ONSTACK: libc::c_int = 0x0001;
234 pub const SA_RESTART: libc::c_int = 0x0002;
235 pub const SA_RESETHAND: libc::c_int = 0x0004;
236 pub const SA_NOCLDSTOP: libc::c_int = 0x0008;
237 pub const SA_NODEFER: libc::c_int = 0x0010;
238 pub const SA_NOCLDWAIT: libc::c_int = 0x0020;
239 pub const SA_SIGINFO: libc::c_int = 0x0040;
240 pub const SIGCHLD: libc::c_int = 20;
242 #[cfg(any(target_os = "macos", target_os = "ios"))]
243 pub type sigset_t = u32;
244 #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
246 pub struct sigset_t {
250 // This structure has more fields, but we're not all that interested in
254 pub si_signo: libc::c_int,
255 pub si_errno: libc::c_int,
256 pub si_code: libc::c_int,
257 pub pid: libc::pid_t,
258 pub uid: libc::uid_t,
259 pub status: libc::c_int,
263 pub struct sigaction {
264 pub sa_handler: extern fn(libc::c_int),
265 pub sa_flags: libc::c_int,
266 pub sa_mask: sigset_t,