]> git.lizzy.rs Git - rust.git/blob - src/libnative/io/c_unix.rs
auto merge of #13391 : smesseim/rust/apache-copyright, 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 pub use self::select::fd_set;
14
15 use libc;
16
17 #[cfg(target_os = "macos")]
18 #[cfg(target_os = "freebsd")]
19 pub static FIONBIO: libc::c_ulong = 0x8004667e;
20 #[cfg(target_os = "linux")]
21 #[cfg(target_os = "android")]
22 pub static FIONBIO: libc::c_ulong = 0x5421;
23 #[cfg(target_os = "macos")]
24 #[cfg(target_os = "freebsd")]
25 pub static FIOCLEX: libc::c_ulong = 0x20006601;
26 #[cfg(target_os = "linux")]
27 #[cfg(target_os = "android")]
28 pub static FIOCLEX: libc::c_ulong = 0x5451;
29
30 extern {
31     pub fn gettimeofday(timeval: *mut libc::timeval,
32                         tzp: *libc::c_void) -> libc::c_int;
33     pub fn select(nfds: libc::c_int,
34                   readfds: *fd_set,
35                   writefds: *fd_set,
36                   errorfds: *fd_set,
37                   timeout: *libc::timeval) -> libc::c_int;
38     pub fn getsockopt(sockfd: libc::c_int,
39                       level: libc::c_int,
40                       optname: libc::c_int,
41                       optval: *mut libc::c_void,
42                       optlen: *mut libc::socklen_t) -> libc::c_int;
43     pub fn ioctl(fd: libc::c_int, req: libc::c_ulong, ...) -> libc::c_int;
44
45 }
46
47 #[cfg(target_os = "macos")]
48 mod select {
49     pub static FD_SETSIZE: uint = 1024;
50
51     pub struct fd_set {
52         fds_bits: [i32, ..(FD_SETSIZE / 32)]
53     }
54
55     pub fn fd_set(set: &mut fd_set, fd: i32) {
56         set.fds_bits[(fd / 32) as uint] |= 1 << (fd % 32);
57     }
58 }
59
60 #[cfg(target_os = "android")]
61 #[cfg(target_os = "freebsd")]
62 #[cfg(target_os = "linux")]
63 mod select {
64     use std::uint;
65
66     pub static FD_SETSIZE: uint = 1024;
67
68     pub struct fd_set {
69         fds_bits: [uint, ..(FD_SETSIZE / uint::BITS)]
70     }
71
72     pub fn fd_set(set: &mut fd_set, fd: i32) {
73         let fd = fd as uint;
74         set.fds_bits[fd / uint::BITS] |= 1 << (fd % uint::BITS);
75     }
76 }