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 pub static FIONBIO: libc::c_ulong = 0x8004667e;
26 #[cfg(target_os = "linux", not(target_arch = "mips"))]
27 #[cfg(target_os = "android")]
28 pub static FIONBIO: libc::c_ulong = 0x5421;
29 #[cfg(target_os = "linux", target_arch = "mips")]
30 pub static FIONBIO: libc::c_ulong = 0x667e;
32 #[cfg(target_os = "macos")]
33 #[cfg(target_os = "ios")]
34 #[cfg(target_os = "freebsd")]
35 pub static FIOCLEX: libc::c_ulong = 0x20006601;
36 #[cfg(target_os = "linux", not(target_arch = "mips"))]
37 #[cfg(target_os = "android")]
38 pub static FIOCLEX: libc::c_ulong = 0x5451;
39 #[cfg(target_os = "linux", target_arch = "mips")]
40 pub static FIOCLEX: libc::c_ulong = 0x6601;
42 #[cfg(target_os = "macos")]
43 #[cfg(target_os = "ios")]
44 #[cfg(target_os = "freebsd")]
45 pub static MSG_DONTWAIT: libc::c_int = 0x80;
46 #[cfg(target_os = "linux")]
47 #[cfg(target_os = "android")]
48 pub static MSG_DONTWAIT: libc::c_int = 0x40;
50 pub static WNOHANG: libc::c_int = 1;
53 pub fn gettimeofday(timeval: *mut libc::timeval,
54 tzp: *libc::c_void) -> libc::c_int;
55 pub fn select(nfds: libc::c_int,
59 timeout: *libc::timeval) -> libc::c_int;
60 pub fn getsockopt(sockfd: libc::c_int,
63 optval: *mut libc::c_void,
64 optlen: *mut libc::socklen_t) -> libc::c_int;
65 pub fn ioctl(fd: libc::c_int, req: libc::c_ulong, ...) -> libc::c_int;
68 pub fn waitpid(pid: libc::pid_t, status: *mut libc::c_int,
69 options: libc::c_int) -> libc::pid_t;
71 pub fn sigaction(signum: libc::c_int,
73 oldact: *mut sigaction) -> libc::c_int;
75 pub fn sigaddset(set: *mut sigset_t, signum: libc::c_int) -> libc::c_int;
76 pub fn sigdelset(set: *mut sigset_t, signum: libc::c_int) -> libc::c_int;
77 pub fn sigemptyset(set: *mut sigset_t) -> libc::c_int;
80 #[cfg(target_os = "macos")]
81 #[cfg(target_os = "ios")]
83 pub static FD_SETSIZE: uint = 1024;
86 fds_bits: [i32, ..(FD_SETSIZE / 32)]
89 pub fn fd_set(set: &mut fd_set, fd: i32) {
90 set.fds_bits[(fd / 32) as uint] |= 1 << (fd % 32);
94 #[cfg(target_os = "android")]
95 #[cfg(target_os = "freebsd")]
96 #[cfg(target_os = "linux")]
100 pub static FD_SETSIZE: uint = 1024;
103 fds_bits: [uint, ..(FD_SETSIZE / uint::BITS)]
106 pub fn fd_set(set: &mut fd_set, fd: i32) {
108 set.fds_bits[fd / uint::BITS] |= 1 << (fd % uint::BITS);
112 #[cfg(target_os = "linux", not(target_arch = "mips"))]
113 #[cfg(target_os = "android")]
117 pub static SA_NOCLDSTOP: libc::c_ulong = 0x00000001;
118 pub static SA_NOCLDWAIT: libc::c_ulong = 0x00000002;
119 pub static SA_NODEFER: libc::c_ulong = 0x40000000;
120 pub static SA_ONSTACK: libc::c_ulong = 0x08000000;
121 pub static SA_RESETHAND: libc::c_ulong = 0x80000000;
122 pub static SA_RESTART: libc::c_ulong = 0x10000000;
123 pub static SA_SIGINFO: libc::c_ulong = 0x00000004;
124 pub static SIGCHLD: libc::c_int = 17;
126 // This definition is not as accurate as it could be, {pid, uid, status} is
127 // actually a giant union. Currently we're only interested in these fields,
130 si_signo: libc::c_int,
131 si_errno: libc::c_int,
132 si_code: libc::c_int,
133 pub pid: libc::pid_t,
134 pub uid: libc::uid_t,
135 pub status: libc::c_int,
138 pub struct sigaction {
139 pub sa_handler: extern fn(libc::c_int),
140 pub sa_mask: sigset_t,
141 pub sa_flags: libc::c_ulong,
142 sa_restorer: *mut libc::c_void,
145 #[cfg(target_word_size = "32")]
146 pub struct sigset_t {
147 __val: [libc::c_ulong, ..32],
149 #[cfg(target_word_size = "64")]
150 pub struct sigset_t {
151 __val: [libc::c_ulong, ..16],
155 #[cfg(target_os = "linux", target_arch = "mips")]
159 pub static SA_NOCLDSTOP: libc::c_ulong = 0x00000001;
160 pub static SA_NOCLDWAIT: libc::c_ulong = 0x00010000;
161 pub static SA_NODEFER: libc::c_ulong = 0x40000000;
162 pub static SA_ONSTACK: libc::c_ulong = 0x08000000;
163 pub static SA_RESETHAND: libc::c_ulong = 0x80000000;
164 pub static SA_RESTART: libc::c_ulong = 0x10000000;
165 pub static SA_SIGINFO: libc::c_ulong = 0x00000008;
166 pub static SIGCHLD: libc::c_int = 18;
168 // This definition is not as accurate as it could be, {pid, uid, status} is
169 // actually a giant union. Currently we're only interested in these fields,
172 si_signo: libc::c_int,
173 si_code: libc::c_int,
174 si_errno: libc::c_int,
175 pub pid: libc::pid_t,
176 pub uid: libc::uid_t,
177 pub status: libc::c_int,
180 pub struct sigaction {
181 pub sa_flags: libc::c_uint,
182 pub sa_handler: extern fn(libc::c_int),
183 pub sa_mask: sigset_t,
184 sa_restorer: *mut libc::c_void,
185 sa_resv: [libc::c_int, ..1],
188 pub struct sigset_t {
189 __val: [libc::c_ulong, ..32],
193 #[cfg(target_os = "macos")]
194 #[cfg(target_os = "ios")]
195 #[cfg(target_os = "freebsd")]
199 pub static SA_ONSTACK: libc::c_int = 0x0001;
200 pub static SA_RESTART: libc::c_int = 0x0002;
201 pub static SA_RESETHAND: libc::c_int = 0x0004;
202 pub static SA_NOCLDSTOP: libc::c_int = 0x0008;
203 pub static SA_NODEFER: libc::c_int = 0x0010;
204 pub static SA_NOCLDWAIT: libc::c_int = 0x0020;
205 pub static SA_SIGINFO: libc::c_int = 0x0040;
206 pub static SIGCHLD: libc::c_int = 20;
208 #[cfg(target_os = "macos")]
209 #[cfg(target_os = "ios")]
210 pub type sigset_t = u32;
211 #[cfg(target_os = "freebsd")]
212 pub struct sigset_t {
216 // This structure has more fields, but we're not all that interested in
219 pub si_signo: libc::c_int,
220 pub si_errno: libc::c_int,
221 pub si_code: libc::c_int,
222 pub pid: libc::pid_t,
223 pub uid: libc::uid_t,
224 pub status: libc::c_int,
227 #[cfg(target_os = "macos")]
228 #[cfg(target_os = "ios")]
229 pub struct sigaction {
230 pub sa_handler: extern fn(libc::c_int),
231 sa_tramp: *mut libc::c_void,
232 pub sa_mask: sigset_t,
233 pub sa_flags: libc::c_int,
236 #[cfg(target_os = "freebsd")]
237 pub struct sigaction {
238 pub sa_handler: extern fn(libc::c_int),
239 pub sa_flags: libc::c_int,
240 pub sa_mask: sigset_t,