1 // Copyright 2014-2015 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.
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.
11 //! C definitions used by libnative that don't belong in liblibc
14 #![allow(non_camel_case_types)]
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}
;
23 #[cfg(any(target_os = "macos",
25 target_os
= "freebsd",
26 target_os
= "dragonfly",
28 target_os
= "openbsd"))]
31 pub const FIONBIO
: libc
::c_ulong
= 0x8004667e;
32 pub const FIOCLEX
: libc
::c_ulong
= 0x20006601;
33 pub const FIONCLEX
: libc
::c_ulong
= 0x20006602;
35 #[cfg(any(all(target_os = "linux",
36 any(target_arch
= "x86",
37 target_arch
= "x86_64",
39 target_arch
= "aarch64")),
40 target_os
= "android"))]
43 pub const FIONBIO
: libc
::c_ulong
= 0x5421;
44 pub const FIOCLEX
: libc
::c_ulong
= 0x5451;
45 pub const FIONCLEX
: libc
::c_ulong
= 0x5450;
47 #[cfg(all(target_os = "linux",
48 any(target_arch
= "mips",
49 target_arch
= "mipsel",
50 target_arch
= "powerpc")))]
53 pub const FIONBIO
: libc
::c_ulong
= 0x667e;
54 pub const FIOCLEX
: libc
::c_ulong
= 0x6601;
55 pub const FIONCLEX
: libc
::c_ulong
= 0x6600;
57 pub use self::consts
::*;
59 #[cfg(any(target_os = "macos",
61 target_os
= "freebsd",
62 target_os
= "dragonfly",
64 target_os
= "openbsd"))]
65 pub const MSG_DONTWAIT
: libc
::c_int
= 0x80;
66 #[cfg(any(target_os = "linux", target_os = "android"))]
67 pub const MSG_DONTWAIT
: libc
::c_int
= 0x40;
69 pub const WNOHANG
: libc
::c_int
= 1;
71 #[cfg(target_os = "linux")]
72 pub const _SC_GETPW_R_SIZE_MAX
: libc
::c_int
= 70;
73 #[cfg(any(target_os = "macos",
74 target_os
= "freebsd",
75 target_os
= "dragonfly"))]
76 pub const _SC_GETPW_R_SIZE_MAX
: libc
::c_int
= 71;
77 #[cfg(any(target_os = "bitrig",
78 target_os
= "openbsd"))]
79 pub const _SC_GETPW_R_SIZE_MAX
: libc
::c_int
= 101;
80 #[cfg(target_os = "android")]
81 pub const _SC_GETPW_R_SIZE_MAX
: libc
::c_int
= 0x0048;
84 #[cfg(target_os = "linux")]
86 pub pw_name
: *mut libc
::c_char
,
87 pub pw_passwd
: *mut libc
::c_char
,
88 pub pw_uid
: libc
::uid_t
,
89 pub pw_gid
: libc
::gid_t
,
90 pub pw_gecos
: *mut libc
::c_char
,
91 pub pw_dir
: *mut libc
::c_char
,
92 pub pw_shell
: *mut libc
::c_char
,
96 #[cfg(any(target_os = "macos",
97 target_os
= "freebsd",
98 target_os
= "dragonfly",
100 target_os
= "openbsd"))]
102 pub pw_name
: *mut libc
::c_char
,
103 pub pw_passwd
: *mut libc
::c_char
,
104 pub pw_uid
: libc
::uid_t
,
105 pub pw_gid
: libc
::gid_t
,
106 pub pw_change
: libc
::time_t
,
107 pub pw_class
: *mut libc
::c_char
,
108 pub pw_gecos
: *mut libc
::c_char
,
109 pub pw_dir
: *mut libc
::c_char
,
110 pub pw_shell
: *mut libc
::c_char
,
111 pub pw_expire
: libc
::time_t
,
115 #[cfg(target_os = "android")]
117 pub pw_name
: *mut libc
::c_char
,
118 pub pw_passwd
: *mut libc
::c_char
,
119 pub pw_uid
: libc
::uid_t
,
120 pub pw_gid
: libc
::gid_t
,
121 pub pw_dir
: *mut libc
::c_char
,
122 pub pw_shell
: *mut libc
::c_char
,
126 pub fn gettimeofday(timeval
: *mut libc
::timeval
,
127 tzp
: *mut libc
::c_void
) -> libc
::c_int
;
128 pub fn select(nfds
: libc
::c_int
,
129 readfds
: *mut fd_set
,
130 writefds
: *mut fd_set
,
131 errorfds
: *mut fd_set
,
132 timeout
: *mut libc
::timeval
) -> libc
::c_int
;
133 pub fn getsockopt(sockfd
: libc
::c_int
,
135 optname
: libc
::c_int
,
136 optval
: *mut libc
::c_void
,
137 optlen
: *mut libc
::socklen_t
) -> libc
::c_int
;
138 pub fn ioctl(fd
: libc
::c_int
, req
: libc
::c_ulong
, ...) -> libc
::c_int
;
141 pub fn waitpid(pid
: libc
::pid_t
, status
: *mut libc
::c_int
,
142 options
: libc
::c_int
) -> libc
::pid_t
;
144 pub fn sigaction(signum
: libc
::c_int
,
145 act
: *const sigaction
,
146 oldact
: *mut sigaction
) -> libc
::c_int
;
148 pub fn sigaddset(set
: *mut sigset_t
, signum
: libc
::c_int
) -> libc
::c_int
;
149 pub fn sigdelset(set
: *mut sigset_t
, signum
: libc
::c_int
) -> libc
::c_int
;
150 pub fn sigemptyset(set
: *mut sigset_t
) -> libc
::c_int
;
152 #[cfg(not(target_os = "ios"))]
153 pub fn getpwuid_r(uid
: libc
::uid_t
,
155 buf
: *mut libc
::c_char
,
156 buflen
: libc
::size_t
,
157 result
: *mut *mut passwd
) -> libc
::c_int
;
159 pub fn utimes(filename
: *const libc
::c_char
,
160 times
: *const libc
::timeval
) -> libc
::c_int
;
161 pub fn gai_strerror(errcode
: libc
::c_int
) -> *const libc
::c_char
;
162 pub fn setgroups(ngroups
: libc
::c_int
,
163 ptr
: *const libc
::c_void
) -> libc
::c_int
;
164 pub fn realpath(pathname
: *const libc
::c_char
, resolved
: *mut libc
::c_char
)
165 -> *mut libc
::c_char
;
168 #[cfg(any(target_os = "macos", target_os = "ios"))]
170 pub const FD_SETSIZE
: usize = 1024;
174 fds_bits
: [i32; (FD_SETSIZE
/ 32)]
177 pub fn fd_set(set
: &mut fd_set
, fd
: i32) {
178 set
.fds_bits
[(fd
/ 32) as usize] |= 1 << ((fd
% 32) as usize);
182 #[cfg(any(target_os = "android",
183 target_os
= "freebsd",
184 target_os
= "dragonfly",
185 target_os
= "bitrig",
186 target_os
= "openbsd",
187 target_os
= "linux"))]
192 pub const FD_SETSIZE
: usize = 1024;
196 // FIXME: shouldn't this be a c_ulong?
197 fds_bits
: [libc
::uintptr_t
; (FD_SETSIZE
/ usize::BITS
)]
200 pub fn fd_set(set
: &mut fd_set
, fd
: i32) {
201 let fd
= fd
as usize;
202 set
.fds_bits
[fd
/ usize::BITS
] |= 1 << (fd
% usize::BITS
);
206 #[cfg(any(all(target_os = "linux",
207 any(target_arch
= "x86",
208 target_arch
= "x86_64",
210 target_arch
= "aarch64")),
211 target_os
= "android"))]
215 pub const SA_NOCLDSTOP
: libc
::c_ulong
= 0x00000001;
216 pub const SA_NOCLDWAIT
: libc
::c_ulong
= 0x00000002;
217 pub const SA_NODEFER
: libc
::c_ulong
= 0x40000000;
218 pub const SA_ONSTACK
: libc
::c_ulong
= 0x08000000;
219 pub const SA_RESETHAND
: libc
::c_ulong
= 0x80000000;
220 pub const SA_RESTART
: libc
::c_ulong
= 0x10000000;
221 pub const SA_SIGINFO
: libc
::c_ulong
= 0x00000004;
222 pub const SIGCHLD
: libc
::c_int
= 17;
224 // This definition is not as accurate as it could be, {pid, uid, status} is
225 // actually a giant union. Currently we're only interested in these fields,
229 si_signo
: libc
::c_int
,
230 si_errno
: libc
::c_int
,
231 si_code
: libc
::c_int
,
232 pub pid
: libc
::pid_t
,
233 pub uid
: libc
::uid_t
,
234 pub status
: libc
::c_int
,
238 pub struct sigaction
{
239 pub sa_handler
: extern fn(libc
::c_int
),
240 pub sa_mask
: sigset_t
,
241 pub sa_flags
: libc
::c_ulong
,
242 sa_restorer
: *mut libc
::c_void
,
245 unsafe impl ::marker
::Send
for sigaction { }
246 unsafe impl ::marker
::Sync
for sigaction { }
249 #[cfg(target_pointer_width = "32")]
250 pub struct sigset_t
{
251 __val
: [libc
::c_ulong
; 32],
255 #[cfg(target_pointer_width = "64")]
256 pub struct sigset_t
{
257 __val
: [libc
::c_ulong
; 16],
261 #[cfg(all(target_os = "linux",
262 any(target_arch
= "mips",
263 target_arch
= "mipsel",
264 target_arch
= "powerpc")))]
268 pub const SA_NOCLDSTOP
: libc
::c_ulong
= 0x00000001;
269 pub const SA_NOCLDWAIT
: libc
::c_ulong
= 0x00010000;
270 pub const SA_NODEFER
: libc
::c_ulong
= 0x40000000;
271 pub const SA_ONSTACK
: libc
::c_ulong
= 0x08000000;
272 pub const SA_RESETHAND
: libc
::c_ulong
= 0x80000000;
273 pub const SA_RESTART
: libc
::c_ulong
= 0x10000000;
274 pub const SA_SIGINFO
: libc
::c_ulong
= 0x00000008;
275 pub const SIGCHLD
: libc
::c_int
= 18;
277 // This definition is not as accurate as it could be, {pid, uid, status} is
278 // actually a giant union. Currently we're only interested in these fields,
282 si_signo
: libc
::c_int
,
283 si_code
: libc
::c_int
,
284 si_errno
: libc
::c_int
,
285 pub pid
: libc
::pid_t
,
286 pub uid
: libc
::uid_t
,
287 pub status
: libc
::c_int
,
291 pub struct sigaction
{
292 pub sa_flags
: libc
::c_uint
,
293 pub sa_handler
: extern fn(libc
::c_int
),
294 pub sa_mask
: sigset_t
,
295 sa_restorer
: *mut libc
::c_void
,
296 sa_resv
: [libc
::c_int
; 1],
299 unsafe impl ::marker
::Send
for sigaction { }
300 unsafe impl ::marker
::Sync
for sigaction { }
303 pub struct sigset_t
{
304 __val
: [libc
::c_ulong
; 32],
308 #[cfg(any(target_os = "macos",
310 target_os
= "freebsd",
311 target_os
= "dragonfly"))]
315 pub const SA_ONSTACK
: libc
::c_int
= 0x0001;
316 pub const SA_RESTART
: libc
::c_int
= 0x0002;
317 pub const SA_RESETHAND
: libc
::c_int
= 0x0004;
318 pub const SA_NOCLDSTOP
: libc
::c_int
= 0x0008;
319 pub const SA_NODEFER
: libc
::c_int
= 0x0010;
320 pub const SA_NOCLDWAIT
: libc
::c_int
= 0x0020;
321 pub const SA_SIGINFO
: libc
::c_int
= 0x0040;
322 pub const SIGCHLD
: libc
::c_int
= 20;
324 #[cfg(any(target_os = "macos",
326 pub type sigset_t
= u32;
327 #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
329 pub struct sigset_t
{
333 // This structure has more fields, but we're not all that interested in
337 pub si_signo
: libc
::c_int
,
338 pub si_errno
: libc
::c_int
,
339 pub si_code
: libc
::c_int
,
340 pub pid
: libc
::pid_t
,
341 pub uid
: libc
::uid_t
,
342 pub status
: libc
::c_int
,
346 pub struct sigaction
{
347 pub sa_handler
: extern fn(libc
::c_int
),
348 pub sa_flags
: libc
::c_int
,
349 pub sa_mask
: sigset_t
,
353 #[cfg(any(target_os = "bitrig", target_os = "openbsd"))]
357 pub const SA_ONSTACK
: libc
::c_int
= 0x0001;
358 pub const SA_RESTART
: libc
::c_int
= 0x0002;
359 pub const SA_RESETHAND
: libc
::c_int
= 0x0004;
360 pub const SA_NOCLDSTOP
: libc
::c_int
= 0x0008;
361 pub const SA_NODEFER
: libc
::c_int
= 0x0010;
362 pub const SA_NOCLDWAIT
: libc
::c_int
= 0x0020;
363 pub const SA_SIGINFO
: libc
::c_int
= 0x0040;
364 pub const SIGCHLD
: libc
::c_int
= 20;
366 pub type sigset_t
= libc
::c_uint
;
368 // This structure has more fields, but we're not all that interested in
372 pub si_signo
: libc
::c_int
,
373 pub si_code
: libc
::c_int
,
374 pub si_errno
: libc
::c_int
,
375 // FIXME: Bitrig has a crazy union here in the siginfo, I think this
376 // layout will still work tho. The status might be off by the size of
377 // a clock_t by my reading, but we can fix this later.
378 pub pid
: libc
::pid_t
,
379 pub uid
: libc
::uid_t
,
380 pub status
: libc
::c_int
,
384 pub struct sigaction
{
385 pub sa_handler
: extern fn(libc
::c_int
),
386 pub sa_mask
: sigset_t
,
387 pub sa_flags
: libc
::c_int
,