]> git.lizzy.rs Git - rust.git/blob - src/libnative/io/c_unix.rs
Add a few more derivings to AST types
[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 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;
34
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;
47
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;
55
56 pub static WNOHANG: libc::c_int = 1;
57
58 extern {
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,
62                   readfds: *mut fd_set,
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,
67                       level: libc::c_int,
68                       optname: 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;
72
73
74     pub fn waitpid(pid: libc::pid_t, status: *mut libc::c_int,
75                    options: libc::c_int) -> libc::pid_t;
76
77     pub fn sigaction(signum: libc::c_int,
78                      act: *const sigaction,
79                      oldact: *mut sigaction) -> libc::c_int;
80
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;
84 }
85
86 #[cfg(target_os = "macos")]
87 #[cfg(target_os = "ios")]
88 mod select {
89     pub static FD_SETSIZE: uint = 1024;
90
91     pub struct fd_set {
92         fds_bits: [i32, ..(FD_SETSIZE / 32)]
93     }
94
95     pub fn fd_set(set: &mut fd_set, fd: i32) {
96         set.fds_bits[(fd / 32) as uint] |= 1 << ((fd % 32) as uint);
97     }
98 }
99
100 #[cfg(target_os = "android")]
101 #[cfg(target_os = "freebsd")]
102 #[cfg(target_os = "linux")]
103 mod select {
104     use std::uint;
105
106     pub static FD_SETSIZE: uint = 1024;
107
108     pub struct fd_set {
109         fds_bits: [uint, ..(FD_SETSIZE / uint::BITS)]
110     }
111
112     pub fn fd_set(set: &mut fd_set, fd: i32) {
113         let fd = fd as uint;
114         set.fds_bits[fd / uint::BITS] |= 1 << (fd % uint::BITS);
115     }
116 }
117
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")]
122 mod signal {
123     use libc;
124
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;
133
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,
136     // however.
137     pub struct siginfo {
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,
144     }
145
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,
151     }
152
153     #[cfg(target_word_size = "32")]
154     pub struct sigset_t {
155         __val: [libc::c_ulong, ..32],
156     }
157     #[cfg(target_word_size = "64")]
158     pub struct sigset_t {
159         __val: [libc::c_ulong, ..16],
160     }
161 }
162
163 #[cfg(target_os = "linux", target_arch = "mips")]
164 #[cfg(target_os = "linux", target_arch = "mipsel")]
165 mod signal {
166     use libc;
167
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;
176
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,
179     // however.
180     pub struct siginfo {
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,
187     }
188
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],
195     }
196
197     pub struct sigset_t {
198         __val: [libc::c_ulong, ..32],
199     }
200 }
201
202 #[cfg(target_os = "macos")]
203 #[cfg(target_os = "ios")]
204 #[cfg(target_os = "freebsd")]
205 mod signal {
206     use libc;
207
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;
216
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 {
222         bits: [u32, ..4],
223     }
224
225     // This structure has more fields, but we're not all that interested in
226     // them.
227     pub struct siginfo {
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,
234     }
235
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,
243     }
244
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,
250     }
251 }