]> git.lizzy.rs Git - rust.git/blob - src/libnative/io/c_unix.rs
Removed some unnecessary RefCells from resolve
[rust.git] / src / libnative / io / c_unix.rs
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.
4 //
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.
10
11 //! C definitions used by libnative that don't belong in liblibc
12
13 #![allow(dead_code)]
14
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};
19
20 use libc;
21
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;
35
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;
49
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;
58
59 pub static WNOHANG: libc::c_int = 1;
60
61 extern {
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,
65                   readfds: *mut fd_set,
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,
70                       level: libc::c_int,
71                       optname: 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;
75
76
77     pub fn waitpid(pid: libc::pid_t, status: *mut libc::c_int,
78                    options: libc::c_int) -> libc::pid_t;
79
80     pub fn sigaction(signum: libc::c_int,
81                      act: *const sigaction,
82                      oldact: *mut sigaction) -> libc::c_int;
83
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;
87 }
88
89 #[cfg(target_os = "macos")]
90 #[cfg(target_os = "ios")]
91 mod select {
92     pub static FD_SETSIZE: uint = 1024;
93
94     #[repr(C)]
95     pub struct fd_set {
96         fds_bits: [i32, ..(FD_SETSIZE / 32)]
97     }
98
99     pub fn fd_set(set: &mut fd_set, fd: i32) {
100         set.fds_bits[(fd / 32) as uint] |= 1 << ((fd % 32) as uint);
101     }
102 }
103
104 #[cfg(target_os = "android")]
105 #[cfg(target_os = "freebsd")]
106 #[cfg(target_os = "dragonfly")]
107 #[cfg(target_os = "linux")]
108 mod select {
109     use std::uint;
110     use libc;
111
112     pub static FD_SETSIZE: uint = 1024;
113
114     #[repr(C)]
115     pub struct fd_set {
116         // FIXME: shouldn't this be a c_ulong?
117         fds_bits: [libc::uintptr_t, ..(FD_SETSIZE / uint::BITS)]
118     }
119
120     pub fn fd_set(set: &mut fd_set, fd: i32) {
121         let fd = fd as uint;
122         set.fds_bits[fd / uint::BITS] |= 1 << (fd % uint::BITS);
123     }
124 }
125
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")]
130 mod signal {
131     use libc;
132
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;
141
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,
144     // however.
145     #[repr(C)]
146     pub struct siginfo {
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,
153     }
154
155     #[repr(C)]
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,
161     }
162
163     #[repr(C)]
164     #[cfg(target_word_size = "32")]
165     pub struct sigset_t {
166         __val: [libc::c_ulong, ..32],
167     }
168
169     #[repr(C)]
170     #[cfg(target_word_size = "64")]
171     pub struct sigset_t {
172         __val: [libc::c_ulong, ..16],
173     }
174 }
175
176 #[cfg(target_os = "linux", target_arch = "mips")]
177 #[cfg(target_os = "linux", target_arch = "mipsel")]
178 mod signal {
179     use libc;
180
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;
189
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,
192     // however.
193     #[repr(C)]
194     pub struct siginfo {
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,
201     }
202
203     #[repr(C)]
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],
210     }
211
212     #[repr(C)]
213     pub struct sigset_t {
214         __val: [libc::c_ulong, ..32],
215     }
216 }
217
218 #[cfg(target_os = "macos")]
219 #[cfg(target_os = "ios")]
220 #[cfg(target_os = "freebsd")]
221 #[cfg(target_os = "dragonfly")]
222 mod signal {
223     use libc;
224
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;
233
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")]
239     #[repr(C)]
240     pub struct sigset_t {
241         bits: [u32, ..4],
242     }
243
244     // This structure has more fields, but we're not all that interested in
245     // them.
246     #[repr(C)]
247     pub struct siginfo {
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,
254     }
255
256     #[cfg(target_os = "macos")]
257     #[cfg(target_os = "ios")]
258     #[repr(C)]
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,
264     }
265
266     #[cfg(target_os = "freebsd")]
267     #[cfg(target_os = "dragonfly")]
268     #[repr(C)]
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,
273     }
274 }