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 = "freebsd")]
24 pub static FIONBIO: libc::c_ulong = 0x8004667e;
25 #[cfg(target_os = "linux")]
26 #[cfg(target_os = "android")]
27 pub static FIONBIO: libc::c_ulong = 0x5421;
28 #[cfg(target_os = "macos")]
29 #[cfg(target_os = "freebsd")]
30 pub static FIOCLEX: libc::c_ulong = 0x20006601;
31 #[cfg(target_os = "linux")]
32 #[cfg(target_os = "android")]
33 pub static FIOCLEX: libc::c_ulong = 0x5451;
35 #[cfg(target_os = "macos")]
36 #[cfg(target_os = "freebsd")]
37 pub static MSG_DONTWAIT: libc::c_int = 0x80;
38 #[cfg(target_os = "linux")]
39 #[cfg(target_os = "android")]
40 pub static MSG_DONTWAIT: libc::c_int = 0x40;
42 pub static WNOHANG: libc::c_int = 1;
45 pub fn gettimeofday(timeval: *mut libc::timeval,
46 tzp: *libc::c_void) -> libc::c_int;
47 pub fn select(nfds: libc::c_int,
51 timeout: *libc::timeval) -> libc::c_int;
52 pub fn getsockopt(sockfd: libc::c_int,
55 optval: *mut libc::c_void,
56 optlen: *mut libc::socklen_t) -> libc::c_int;
57 pub fn ioctl(fd: libc::c_int, req: libc::c_ulong, ...) -> libc::c_int;
60 pub fn waitpid(pid: libc::pid_t, status: *mut libc::c_int,
61 options: libc::c_int) -> libc::pid_t;
63 pub fn sigaction(signum: libc::c_int,
65 oldact: *mut sigaction) -> libc::c_int;
67 pub fn sigaddset(set: *mut sigset_t, signum: libc::c_int) -> libc::c_int;
68 pub fn sigdelset(set: *mut sigset_t, signum: libc::c_int) -> libc::c_int;
69 pub fn sigemptyset(set: *mut sigset_t) -> libc::c_int;
72 #[cfg(target_os = "macos")]
74 pub static FD_SETSIZE: uint = 1024;
77 fds_bits: [i32, ..(FD_SETSIZE / 32)]
80 pub fn fd_set(set: &mut fd_set, fd: i32) {
81 set.fds_bits[(fd / 32) as uint] |= 1 << (fd % 32);
85 #[cfg(target_os = "android")]
86 #[cfg(target_os = "freebsd")]
87 #[cfg(target_os = "linux")]
91 pub static FD_SETSIZE: uint = 1024;
94 fds_bits: [uint, ..(FD_SETSIZE / uint::BITS)]
97 pub fn fd_set(set: &mut fd_set, fd: i32) {
99 set.fds_bits[fd / uint::BITS] |= 1 << (fd % uint::BITS);
103 #[cfg(target_os = "linux")]
104 #[cfg(target_os = "android")]
108 pub static SA_NOCLDSTOP: libc::c_ulong = 0x00000001;
109 pub static SA_NOCLDWAIT: libc::c_ulong = 0x00000002;
110 pub static SA_NODEFER: libc::c_ulong = 0x40000000;
111 pub static SA_ONSTACK: libc::c_ulong = 0x08000000;
112 pub static SA_RESETHAND: libc::c_ulong = 0x80000000;
113 pub static SA_RESTART: libc::c_ulong = 0x10000000;
114 pub static SA_SIGINFO: libc::c_ulong = 0x00000004;
115 pub static SIGCHLD: libc::c_int = 17;
117 // This definition is not as accurate as it could be, {pid, uid, status} is
118 // actually a giant union. Currently we're only interested in these fields,
121 si_signo: libc::c_int,
122 si_errno: libc::c_int,
123 si_code: libc::c_int,
124 pub pid: libc::pid_t,
125 pub uid: libc::uid_t,
126 pub status: libc::c_int,
129 pub struct sigaction {
130 pub sa_handler: extern fn(libc::c_int),
131 pub sa_mask: sigset_t,
132 pub sa_flags: libc::c_ulong,
133 sa_restorer: *mut libc::c_void,
136 #[cfg(target_word_size = "32")]
137 pub struct sigset_t {
138 __val: [libc::c_ulong, ..32],
140 #[cfg(target_word_size = "64")]
141 pub struct sigset_t {
142 __val: [libc::c_ulong, ..16],
146 #[cfg(target_os = "macos")]
147 #[cfg(target_os = "freebsd")]
151 pub static SA_ONSTACK: libc::c_int = 0x0001;
152 pub static SA_RESTART: libc::c_int = 0x0002;
153 pub static SA_RESETHAND: libc::c_int = 0x0004;
154 pub static SA_NOCLDSTOP: libc::c_int = 0x0008;
155 pub static SA_NODEFER: libc::c_int = 0x0010;
156 pub static SA_NOCLDWAIT: libc::c_int = 0x0020;
157 pub static SA_SIGINFO: libc::c_int = 0x0040;
158 pub static SIGCHLD: libc::c_int = 20;
160 #[cfg(target_os = "macos")]
161 pub type sigset_t = u32;
162 #[cfg(target_os = "freebsd")]
163 pub struct sigset_t {
167 // This structure has more fields, but we're not all that interested in
170 pub si_signo: libc::c_int,
171 pub si_errno: libc::c_int,
172 pub si_code: libc::c_int,
173 pub pid: libc::pid_t,
174 pub uid: libc::uid_t,
175 pub status: libc::c_int,
178 #[cfg(target_os = "macos")]
179 pub struct sigaction {
180 pub sa_handler: extern fn(libc::c_int),
181 sa_tramp: *mut libc::c_void,
182 pub sa_mask: sigset_t,
183 pub sa_flags: libc::c_int,
186 #[cfg(target_os = "freebsd")]
187 pub struct sigaction {
188 pub sa_handler: extern fn(libc::c_int),
189 pub sa_flags: libc::c_int,
190 pub sa_mask: sigset_t,