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