]> git.lizzy.rs Git - rust.git/blob - src/libnative/io/c_unix.rs
auto merge of #14715 : vhbit/rust/ios-pr2, r=alexcrichton
[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", 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;
31
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;
41
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;
49
50 pub static WNOHANG: libc::c_int = 1;
51
52 extern {
53     pub fn gettimeofday(timeval: *mut libc::timeval,
54                         tzp: *libc::c_void) -> libc::c_int;
55     pub fn select(nfds: libc::c_int,
56                   readfds: *fd_set,
57                   writefds: *fd_set,
58                   errorfds: *fd_set,
59                   timeout: *libc::timeval) -> libc::c_int;
60     pub fn getsockopt(sockfd: libc::c_int,
61                       level: libc::c_int,
62                       optname: 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;
66
67
68     pub fn waitpid(pid: libc::pid_t, status: *mut libc::c_int,
69                    options: libc::c_int) -> libc::pid_t;
70
71     pub fn sigaction(signum: libc::c_int,
72                      act: *sigaction,
73                      oldact: *mut sigaction) -> libc::c_int;
74
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;
78 }
79
80 #[cfg(target_os = "macos")]
81 #[cfg(target_os = "ios")]
82 mod select {
83     pub static FD_SETSIZE: uint = 1024;
84
85     pub struct fd_set {
86         fds_bits: [i32, ..(FD_SETSIZE / 32)]
87     }
88
89     pub fn fd_set(set: &mut fd_set, fd: i32) {
90         set.fds_bits[(fd / 32) as uint] |= 1 << (fd % 32);
91     }
92 }
93
94 #[cfg(target_os = "android")]
95 #[cfg(target_os = "freebsd")]
96 #[cfg(target_os = "linux")]
97 mod select {
98     use std::uint;
99
100     pub static FD_SETSIZE: uint = 1024;
101
102     pub struct fd_set {
103         fds_bits: [uint, ..(FD_SETSIZE / uint::BITS)]
104     }
105
106     pub fn fd_set(set: &mut fd_set, fd: i32) {
107         let fd = fd as uint;
108         set.fds_bits[fd / uint::BITS] |= 1 << (fd % uint::BITS);
109     }
110 }
111
112 #[cfg(target_os = "linux", not(target_arch = "mips"))]
113 #[cfg(target_os = "android")]
114 mod signal {
115     use libc;
116
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;
125
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,
128     // however.
129     pub struct siginfo {
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,
136     }
137
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,
143     }
144
145     #[cfg(target_word_size = "32")]
146     pub struct sigset_t {
147         __val: [libc::c_ulong, ..32],
148     }
149     #[cfg(target_word_size = "64")]
150     pub struct sigset_t {
151         __val: [libc::c_ulong, ..16],
152     }
153 }
154
155 #[cfg(target_os = "linux", target_arch = "mips")]
156 mod signal {
157     use libc;
158
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;
167
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,
170     // however.
171     pub struct siginfo {
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,
178     }
179
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],
186     }
187
188     pub struct sigset_t {
189         __val: [libc::c_ulong, ..32],
190     }
191 }
192
193 #[cfg(target_os = "macos")]
194 #[cfg(target_os = "ios")]
195 #[cfg(target_os = "freebsd")]
196 mod signal {
197     use libc;
198
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;
207
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 {
213         bits: [u32, ..4],
214     }
215
216     // This structure has more fields, but we're not all that interested in
217     // them.
218     pub struct siginfo {
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,
225     }
226
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,
234     }
235
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,
241     }
242 }