]> git.lizzy.rs Git - rust.git/blob - src/libnative/io/c_unix.rs
auto merge of #15999 : Kimundi/rust/fix_folder, r=nikomatsakis
[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     pub struct fd_set {
95         fds_bits: [i32, ..(FD_SETSIZE / 32)]
96     }
97
98     pub fn fd_set(set: &mut fd_set, fd: i32) {
99         set.fds_bits[(fd / 32) as uint] |= 1 << ((fd % 32) as uint);
100     }
101 }
102
103 #[cfg(target_os = "android")]
104 #[cfg(target_os = "freebsd")]
105 #[cfg(target_os = "dragonfly")]
106 #[cfg(target_os = "linux")]
107 mod select {
108     use std::uint;
109
110     pub static FD_SETSIZE: uint = 1024;
111
112     pub struct fd_set {
113         // FIXME: shouldn't this be a c_ulong?
114         fds_bits: [uint, ..(FD_SETSIZE / uint::BITS)]
115     }
116
117     pub fn fd_set(set: &mut fd_set, fd: i32) {
118         let fd = fd as uint;
119         set.fds_bits[fd / uint::BITS] |= 1 << (fd % uint::BITS);
120     }
121 }
122
123 #[cfg(target_os = "linux", target_arch = "x86")]
124 #[cfg(target_os = "linux", target_arch = "x86_64")]
125 #[cfg(target_os = "linux", target_arch = "arm")]
126 #[cfg(target_os = "android")]
127 mod signal {
128     use libc;
129
130     pub static SA_NOCLDSTOP: libc::c_ulong = 0x00000001;
131     pub static SA_NOCLDWAIT: libc::c_ulong = 0x00000002;
132     pub static SA_NODEFER: libc::c_ulong = 0x40000000;
133     pub static SA_ONSTACK: libc::c_ulong = 0x08000000;
134     pub static SA_RESETHAND: libc::c_ulong = 0x80000000;
135     pub static SA_RESTART: libc::c_ulong = 0x10000000;
136     pub static SA_SIGINFO: libc::c_ulong = 0x00000004;
137     pub static SIGCHLD: libc::c_int = 17;
138
139     // This definition is not as accurate as it could be, {pid, uid, status} is
140     // actually a giant union. Currently we're only interested in these fields,
141     // however.
142     pub struct siginfo {
143         si_signo: libc::c_int,
144         si_errno: libc::c_int,
145         si_code: libc::c_int,
146         pub pid: libc::pid_t,
147         pub uid: libc::uid_t,
148         pub status: libc::c_int,
149     }
150
151     pub struct sigaction {
152         pub sa_handler: extern fn(libc::c_int),
153         pub sa_mask: sigset_t,
154         pub sa_flags: libc::c_ulong,
155         sa_restorer: *mut libc::c_void,
156     }
157
158     #[cfg(target_word_size = "32")]
159     pub struct sigset_t {
160         __val: [libc::c_ulong, ..32],
161     }
162     #[cfg(target_word_size = "64")]
163     pub struct sigset_t {
164         __val: [libc::c_ulong, ..16],
165     }
166 }
167
168 #[cfg(target_os = "linux", target_arch = "mips")]
169 #[cfg(target_os = "linux", target_arch = "mipsel")]
170 mod signal {
171     use libc;
172
173     pub static SA_NOCLDSTOP: libc::c_ulong = 0x00000001;
174     pub static SA_NOCLDWAIT: libc::c_ulong = 0x00010000;
175     pub static SA_NODEFER: libc::c_ulong = 0x40000000;
176     pub static SA_ONSTACK: libc::c_ulong = 0x08000000;
177     pub static SA_RESETHAND: libc::c_ulong = 0x80000000;
178     pub static SA_RESTART: libc::c_ulong = 0x10000000;
179     pub static SA_SIGINFO: libc::c_ulong = 0x00000008;
180     pub static SIGCHLD: libc::c_int = 18;
181
182     // This definition is not as accurate as it could be, {pid, uid, status} is
183     // actually a giant union. Currently we're only interested in these fields,
184     // however.
185     pub struct siginfo {
186         si_signo: libc::c_int,
187         si_code: libc::c_int,
188         si_errno: libc::c_int,
189         pub pid: libc::pid_t,
190         pub uid: libc::uid_t,
191         pub status: libc::c_int,
192     }
193
194     pub struct sigaction {
195         pub sa_flags: libc::c_uint,
196         pub sa_handler: extern fn(libc::c_int),
197         pub sa_mask: sigset_t,
198         sa_restorer: *mut libc::c_void,
199         sa_resv: [libc::c_int, ..1],
200     }
201
202     pub struct sigset_t {
203         __val: [libc::c_ulong, ..32],
204     }
205 }
206
207 #[cfg(target_os = "macos")]
208 #[cfg(target_os = "ios")]
209 #[cfg(target_os = "freebsd")]
210 #[cfg(target_os = "dragonfly")]
211 mod signal {
212     use libc;
213
214     pub static SA_ONSTACK: libc::c_int = 0x0001;
215     pub static SA_RESTART: libc::c_int = 0x0002;
216     pub static SA_RESETHAND: libc::c_int = 0x0004;
217     pub static SA_NOCLDSTOP: libc::c_int = 0x0008;
218     pub static SA_NODEFER: libc::c_int = 0x0010;
219     pub static SA_NOCLDWAIT: libc::c_int = 0x0020;
220     pub static SA_SIGINFO: libc::c_int = 0x0040;
221     pub static SIGCHLD: libc::c_int = 20;
222
223     #[cfg(target_os = "macos")]
224     #[cfg(target_os = "ios")]
225     pub type sigset_t = u32;
226     #[cfg(target_os = "freebsd")]
227     #[cfg(target_os = "dragonfly")]
228     pub struct sigset_t {
229         bits: [u32, ..4],
230     }
231
232     // This structure has more fields, but we're not all that interested in
233     // them.
234     pub struct siginfo {
235         pub si_signo: libc::c_int,
236         pub si_errno: libc::c_int,
237         pub si_code: libc::c_int,
238         pub pid: libc::pid_t,
239         pub uid: libc::uid_t,
240         pub status: libc::c_int,
241     }
242
243     #[cfg(target_os = "macos")]
244     #[cfg(target_os = "ios")]
245     pub struct sigaction {
246         pub sa_handler: extern fn(libc::c_int),
247         sa_tramp: *mut libc::c_void,
248         pub sa_mask: sigset_t,
249         pub sa_flags: libc::c_int,
250     }
251
252     #[cfg(target_os = "freebsd")]
253     #[cfg(target_os = "dragonfly")]
254     pub struct sigaction {
255         pub sa_handler: extern fn(libc::c_int),
256         pub sa_flags: libc::c_int,
257         pub sa_mask: sigset_t,
258     }
259 }