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", target_arch = "x86")]
27 #[cfg(target_os = "linux", target_arch = "x86_64")]
28 #[cfg(target_os = "linux", target_arch = "arm")]
29 #[cfg(target_os = "android")]
30 pub static FIONBIO: libc::c_ulong = 0x5421;
31 #[cfg(target_os = "linux", target_arch = "mips")]
32 #[cfg(target_os = "linux", target_arch = "mipsel")]
33 pub static FIONBIO: libc::c_ulong = 0x667e;
35 #[cfg(target_os = "macos")]
36 #[cfg(target_os = "ios")]
37 #[cfg(target_os = "freebsd")]
38 pub static FIOCLEX: libc::c_ulong = 0x20006601;
39 #[cfg(target_os = "linux", target_arch = "x86")]
40 #[cfg(target_os = "linux", target_arch = "x86_64")]
41 #[cfg(target_os = "linux", target_arch = "arm")]
42 #[cfg(target_os = "android")]
43 pub static FIOCLEX: libc::c_ulong = 0x5451;
44 #[cfg(target_os = "linux", target_arch = "mips")]
45 #[cfg(target_os = "linux", target_arch = "mipsel")]
46 pub static FIOCLEX: libc::c_ulong = 0x6601;
48 #[cfg(target_os = "macos")]
49 #[cfg(target_os = "ios")]
50 #[cfg(target_os = "freebsd")]
51 pub static MSG_DONTWAIT: libc::c_int = 0x80;
52 #[cfg(target_os = "linux")]
53 #[cfg(target_os = "android")]
54 pub static MSG_DONTWAIT: libc::c_int = 0x40;
56 pub static WNOHANG: libc::c_int = 1;
59 pub fn gettimeofday(timeval: *mut libc::timeval,
60 tzp: *mut libc::c_void) -> libc::c_int;
61 pub fn select(nfds: libc::c_int,
63 writefds: *mut fd_set,
64 errorfds: *mut fd_set,
65 timeout: *mut libc::timeval) -> libc::c_int;
66 pub fn getsockopt(sockfd: libc::c_int,
69 optval: *mut libc::c_void,
70 optlen: *mut libc::socklen_t) -> libc::c_int;
71 pub fn ioctl(fd: libc::c_int, req: libc::c_ulong, ...) -> libc::c_int;
74 pub fn waitpid(pid: libc::pid_t, status: *mut libc::c_int,
75 options: libc::c_int) -> libc::pid_t;
77 pub fn sigaction(signum: libc::c_int,
78 act: *const sigaction,
79 oldact: *mut sigaction) -> libc::c_int;
81 pub fn sigaddset(set: *mut sigset_t, signum: libc::c_int) -> libc::c_int;
82 pub fn sigdelset(set: *mut sigset_t, signum: libc::c_int) -> libc::c_int;
83 pub fn sigemptyset(set: *mut sigset_t) -> libc::c_int;
86 #[cfg(target_os = "macos")]
87 #[cfg(target_os = "ios")]
89 pub static FD_SETSIZE: uint = 1024;
92 fds_bits: [i32, ..(FD_SETSIZE / 32)]
95 pub fn fd_set(set: &mut fd_set, fd: i32) {
96 set.fds_bits[(fd / 32) as uint] |= 1 << ((fd % 32) as uint);
100 #[cfg(target_os = "android")]
101 #[cfg(target_os = "freebsd")]
102 #[cfg(target_os = "linux")]
106 pub static FD_SETSIZE: uint = 1024;
109 fds_bits: [uint, ..(FD_SETSIZE / uint::BITS)]
112 pub fn fd_set(set: &mut fd_set, fd: i32) {
114 set.fds_bits[fd / uint::BITS] |= 1 << (fd % uint::BITS);
118 #[cfg(target_os = "linux", target_arch = "x86")]
119 #[cfg(target_os = "linux", target_arch = "x86_64")]
120 #[cfg(target_os = "linux", target_arch = "arm")]
121 #[cfg(target_os = "android")]
125 pub static SA_NOCLDSTOP: libc::c_ulong = 0x00000001;
126 pub static SA_NOCLDWAIT: libc::c_ulong = 0x00000002;
127 pub static SA_NODEFER: libc::c_ulong = 0x40000000;
128 pub static SA_ONSTACK: libc::c_ulong = 0x08000000;
129 pub static SA_RESETHAND: libc::c_ulong = 0x80000000;
130 pub static SA_RESTART: libc::c_ulong = 0x10000000;
131 pub static SA_SIGINFO: libc::c_ulong = 0x00000004;
132 pub static SIGCHLD: libc::c_int = 17;
134 // This definition is not as accurate as it could be, {pid, uid, status} is
135 // actually a giant union. Currently we're only interested in these fields,
138 si_signo: libc::c_int,
139 si_errno: libc::c_int,
140 si_code: libc::c_int,
141 pub pid: libc::pid_t,
142 pub uid: libc::uid_t,
143 pub status: libc::c_int,
146 pub struct sigaction {
147 pub sa_handler: extern fn(libc::c_int),
148 pub sa_mask: sigset_t,
149 pub sa_flags: libc::c_ulong,
150 sa_restorer: *mut libc::c_void,
153 #[cfg(target_word_size = "32")]
154 pub struct sigset_t {
155 __val: [libc::c_ulong, ..32],
157 #[cfg(target_word_size = "64")]
158 pub struct sigset_t {
159 __val: [libc::c_ulong, ..16],
163 #[cfg(target_os = "linux", target_arch = "mips")]
164 #[cfg(target_os = "linux", target_arch = "mipsel")]
168 pub static SA_NOCLDSTOP: libc::c_ulong = 0x00000001;
169 pub static SA_NOCLDWAIT: libc::c_ulong = 0x00010000;
170 pub static SA_NODEFER: libc::c_ulong = 0x40000000;
171 pub static SA_ONSTACK: libc::c_ulong = 0x08000000;
172 pub static SA_RESETHAND: libc::c_ulong = 0x80000000;
173 pub static SA_RESTART: libc::c_ulong = 0x10000000;
174 pub static SA_SIGINFO: libc::c_ulong = 0x00000008;
175 pub static SIGCHLD: libc::c_int = 18;
177 // This definition is not as accurate as it could be, {pid, uid, status} is
178 // actually a giant union. Currently we're only interested in these fields,
181 si_signo: libc::c_int,
182 si_code: libc::c_int,
183 si_errno: libc::c_int,
184 pub pid: libc::pid_t,
185 pub uid: libc::uid_t,
186 pub status: libc::c_int,
189 pub struct sigaction {
190 pub sa_flags: libc::c_uint,
191 pub sa_handler: extern fn(libc::c_int),
192 pub sa_mask: sigset_t,
193 sa_restorer: *mut libc::c_void,
194 sa_resv: [libc::c_int, ..1],
197 pub struct sigset_t {
198 __val: [libc::c_ulong, ..32],
202 #[cfg(target_os = "macos")]
203 #[cfg(target_os = "ios")]
204 #[cfg(target_os = "freebsd")]
208 pub static SA_ONSTACK: libc::c_int = 0x0001;
209 pub static SA_RESTART: libc::c_int = 0x0002;
210 pub static SA_RESETHAND: libc::c_int = 0x0004;
211 pub static SA_NOCLDSTOP: libc::c_int = 0x0008;
212 pub static SA_NODEFER: libc::c_int = 0x0010;
213 pub static SA_NOCLDWAIT: libc::c_int = 0x0020;
214 pub static SA_SIGINFO: libc::c_int = 0x0040;
215 pub static SIGCHLD: libc::c_int = 20;
217 #[cfg(target_os = "macos")]
218 #[cfg(target_os = "ios")]
219 pub type sigset_t = u32;
220 #[cfg(target_os = "freebsd")]
221 pub struct sigset_t {
225 // This structure has more fields, but we're not all that interested in
228 pub si_signo: libc::c_int,
229 pub si_errno: libc::c_int,
230 pub si_code: libc::c_int,
231 pub pid: libc::pid_t,
232 pub uid: libc::uid_t,
233 pub status: libc::c_int,
236 #[cfg(target_os = "macos")]
237 #[cfg(target_os = "ios")]
238 pub struct sigaction {
239 pub sa_handler: extern fn(libc::c_int),
240 sa_tramp: *mut libc::c_void,
241 pub sa_mask: sigset_t,
242 pub sa_flags: libc::c_int,
245 #[cfg(target_os = "freebsd")]
246 pub struct sigaction {
247 pub sa_handler: extern fn(libc::c_int),
248 pub sa_flags: libc::c_int,
249 pub sa_mask: sigset_t,