]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/unix/c.rs
rollup merge of #20350: fhahn/issue-20340-rustdoc-version
[rust.git] / src / libstd / sys / unix / c.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 #![allow(non_camel_case_types)]
15
16 pub use self::select::fd_set;
17 pub use self::signal::{sigaction, siginfo, sigset_t};
18 pub use self::signal::{SA_ONSTACK, SA_RESTART, SA_RESETHAND, SA_NOCLDSTOP};
19 pub use self::signal::{SA_NODEFER, SA_NOCLDWAIT, SA_SIGINFO, SIGCHLD};
20
21 use libc;
22
23 #[cfg(any(target_os = "macos",
24           target_os = "ios",
25           target_os = "freebsd",
26           target_os = "dragonfly"))]
27 pub const FIONBIO: libc::c_ulong = 0x8004667e;
28 #[cfg(any(all(target_os = "linux",
29               any(target_arch = "x86",
30                   target_arch = "x86_64",
31                   target_arch = "arm")),
32           target_os = "android"))]
33 pub const FIONBIO: libc::c_ulong = 0x5421;
34 #[cfg(all(target_os = "linux",
35           any(target_arch = "mips", target_arch = "mipsel")))]
36 pub const FIONBIO: libc::c_ulong = 0x667e;
37
38 #[cfg(any(target_os = "macos",
39           target_os = "ios",
40           target_os = "freebsd",
41           target_os = "dragonfly"))]
42 pub const FIOCLEX: libc::c_ulong = 0x20006601;
43 #[cfg(any(all(target_os = "linux",
44               any(target_arch = "x86",
45                   target_arch = "x86_64",
46                   target_arch = "arm")),
47           target_os = "android"))]
48 pub const FIOCLEX: libc::c_ulong = 0x5451;
49 #[cfg(all(target_os = "linux",
50           any(target_arch = "mips", target_arch = "mipsel")))]
51 pub const FIOCLEX: libc::c_ulong = 0x6601;
52
53 #[cfg(any(target_os = "macos",
54           target_os = "ios",
55           target_os = "freebsd",
56           target_os = "dragonfly"))]
57 pub const MSG_DONTWAIT: libc::c_int = 0x80;
58 #[cfg(any(target_os = "linux", target_os = "android"))]
59 pub const MSG_DONTWAIT: libc::c_int = 0x40;
60
61 pub const WNOHANG: libc::c_int = 1;
62
63 extern {
64     pub fn gettimeofday(timeval: *mut libc::timeval,
65                         tzp: *mut libc::c_void) -> libc::c_int;
66     pub fn select(nfds: libc::c_int,
67                   readfds: *mut fd_set,
68                   writefds: *mut fd_set,
69                   errorfds: *mut fd_set,
70                   timeout: *mut libc::timeval) -> libc::c_int;
71     pub fn getsockopt(sockfd: libc::c_int,
72                       level: libc::c_int,
73                       optname: libc::c_int,
74                       optval: *mut libc::c_void,
75                       optlen: *mut libc::socklen_t) -> libc::c_int;
76     pub fn ioctl(fd: libc::c_int, req: libc::c_ulong, ...) -> libc::c_int;
77
78
79     pub fn waitpid(pid: libc::pid_t, status: *mut libc::c_int,
80                    options: libc::c_int) -> libc::pid_t;
81
82     pub fn sigaction(signum: libc::c_int,
83                      act: *const sigaction,
84                      oldact: *mut sigaction) -> libc::c_int;
85
86     pub fn sigaddset(set: *mut sigset_t, signum: libc::c_int) -> libc::c_int;
87     pub fn sigdelset(set: *mut sigset_t, signum: libc::c_int) -> libc::c_int;
88     pub fn sigemptyset(set: *mut sigset_t) -> libc::c_int;
89 }
90
91 #[cfg(any(target_os = "macos", target_os = "ios"))]
92 mod select {
93     pub const FD_SETSIZE: uint = 1024;
94
95     #[repr(C)]
96     pub struct fd_set {
97         fds_bits: [i32, ..(FD_SETSIZE / 32)]
98     }
99
100     pub fn fd_set(set: &mut fd_set, fd: i32) {
101         set.fds_bits[(fd / 32) as uint] |= 1 << ((fd % 32) as uint);
102     }
103 }
104
105 #[cfg(any(target_os = "android",
106           target_os = "freebsd",
107           target_os = "dragonfly",
108           target_os = "linux"))]
109 mod select {
110     use uint;
111     use libc;
112
113     pub const FD_SETSIZE: uint = 1024;
114
115     #[repr(C)]
116     pub struct fd_set {
117         // FIXME: shouldn't this be a c_ulong?
118         fds_bits: [libc::uintptr_t, ..(FD_SETSIZE / uint::BITS)]
119     }
120
121     pub fn fd_set(set: &mut fd_set, fd: i32) {
122         let fd = fd as uint;
123         set.fds_bits[fd / uint::BITS] |= 1 << (fd % uint::BITS);
124     }
125 }
126
127 #[cfg(any(all(target_os = "linux",
128               any(target_arch = "x86",
129                   target_arch = "x86_64",
130                   target_arch = "arm")),
131           target_os = "android"))]
132 mod signal {
133     use libc;
134
135     pub const SA_NOCLDSTOP: libc::c_ulong = 0x00000001;
136     pub const SA_NOCLDWAIT: libc::c_ulong = 0x00000002;
137     pub const SA_NODEFER: libc::c_ulong = 0x40000000;
138     pub const SA_ONSTACK: libc::c_ulong = 0x08000000;
139     pub const SA_RESETHAND: libc::c_ulong = 0x80000000;
140     pub const SA_RESTART: libc::c_ulong = 0x10000000;
141     pub const SA_SIGINFO: libc::c_ulong = 0x00000004;
142     pub const SIGCHLD: libc::c_int = 17;
143
144     // This definition is not as accurate as it could be, {pid, uid, status} is
145     // actually a giant union. Currently we're only interested in these fields,
146     // however.
147     #[repr(C)]
148     pub struct siginfo {
149         si_signo: libc::c_int,
150         si_errno: libc::c_int,
151         si_code: libc::c_int,
152         pub pid: libc::pid_t,
153         pub uid: libc::uid_t,
154         pub status: libc::c_int,
155     }
156
157     #[repr(C)]
158     pub struct sigaction {
159         pub sa_handler: extern fn(libc::c_int),
160         pub sa_mask: sigset_t,
161         pub sa_flags: libc::c_ulong,
162         sa_restorer: *mut libc::c_void,
163     }
164
165     unsafe impl ::kinds::Send for sigaction { }
166     unsafe impl ::kinds::Sync for sigaction { }
167
168     #[repr(C)]
169     #[cfg(target_word_size = "32")]
170     pub struct sigset_t {
171         __val: [libc::c_ulong, ..32],
172     }
173
174     #[repr(C)]
175     #[cfg(target_word_size = "64")]
176     pub struct sigset_t {
177         __val: [libc::c_ulong, ..16],
178     }
179 }
180
181 #[cfg(all(target_os = "linux",
182           any(target_arch = "mips", target_arch = "mipsel")))]
183 mod signal {
184     use libc;
185
186     pub const SA_NOCLDSTOP: libc::c_ulong = 0x00000001;
187     pub const SA_NOCLDWAIT: libc::c_ulong = 0x00010000;
188     pub const SA_NODEFER: libc::c_ulong = 0x40000000;
189     pub const SA_ONSTACK: libc::c_ulong = 0x08000000;
190     pub const SA_RESETHAND: libc::c_ulong = 0x80000000;
191     pub const SA_RESTART: libc::c_ulong = 0x10000000;
192     pub const SA_SIGINFO: libc::c_ulong = 0x00000008;
193     pub const SIGCHLD: libc::c_int = 18;
194
195     // This definition is not as accurate as it could be, {pid, uid, status} is
196     // actually a giant union. Currently we're only interested in these fields,
197     // however.
198     #[repr(C)]
199     pub struct siginfo {
200         si_signo: libc::c_int,
201         si_code: libc::c_int,
202         si_errno: libc::c_int,
203         pub pid: libc::pid_t,
204         pub uid: libc::uid_t,
205         pub status: libc::c_int,
206     }
207
208     #[repr(C)]
209     pub struct sigaction {
210         pub sa_flags: libc::c_uint,
211         pub sa_handler: extern fn(libc::c_int),
212         pub sa_mask: sigset_t,
213         sa_restorer: *mut libc::c_void,
214         sa_resv: [libc::c_int, ..1],
215     }
216
217     unsafe impl ::kinds::Send for sigaction { }
218     unsafe impl ::kinds::Sync for sigaction { }
219
220     #[repr(C)]
221     pub struct sigset_t {
222         __val: [libc::c_ulong, ..32],
223     }
224 }
225
226 #[cfg(any(target_os = "macos",
227           target_os = "ios",
228           target_os = "freebsd",
229           target_os = "dragonfly"))]
230 mod signal {
231     use libc;
232
233     pub const SA_ONSTACK: libc::c_int = 0x0001;
234     pub const SA_RESTART: libc::c_int = 0x0002;
235     pub const SA_RESETHAND: libc::c_int = 0x0004;
236     pub const SA_NOCLDSTOP: libc::c_int = 0x0008;
237     pub const SA_NODEFER: libc::c_int = 0x0010;
238     pub const SA_NOCLDWAIT: libc::c_int = 0x0020;
239     pub const SA_SIGINFO: libc::c_int = 0x0040;
240     pub const SIGCHLD: libc::c_int = 20;
241
242     #[cfg(any(target_os = "macos", target_os = "ios"))]
243     pub type sigset_t = u32;
244     #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
245     #[repr(C)]
246     pub struct sigset_t {
247         bits: [u32, ..4],
248     }
249
250     // This structure has more fields, but we're not all that interested in
251     // them.
252     #[repr(C)]
253     pub struct siginfo {
254         pub si_signo: libc::c_int,
255         pub si_errno: libc::c_int,
256         pub si_code: libc::c_int,
257         pub pid: libc::pid_t,
258         pub uid: libc::uid_t,
259         pub status: libc::c_int,
260     }
261
262     #[repr(C)]
263     pub struct sigaction {
264         pub sa_handler: extern fn(libc::c_int),
265         pub sa_flags: libc::c_int,
266         pub sa_mask: sigset_t,
267     }
268 }