]>
Commit | Line | Data |
---|---|---|
2c00a5a8 XL |
1 | // Copyright 2018 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 | use io; | |
12 | use libc; | |
13 | use mem; | |
14 | ||
a1dfa0c6 XL |
15 | #[path = "../unix/alloc.rs"] |
16 | pub mod alloc; | |
2c00a5a8 XL |
17 | pub mod args; |
18 | #[cfg(feature = "backtrace")] | |
19 | pub mod backtrace; | |
20 | #[path = "../unix/cmath.rs"] | |
21 | pub mod cmath; | |
22 | pub mod condvar; | |
23 | #[path = "../unix/memchr.rs"] | |
24 | pub mod memchr; | |
25 | pub mod mutex; | |
26 | pub mod os; | |
27 | #[path = "../unix/os_str.rs"] | |
28 | pub mod os_str; | |
29 | pub mod rwlock; | |
30 | pub mod stack_overflow; | |
31 | pub mod stdio; | |
32 | pub mod thread; | |
33 | #[path = "../unix/thread_local.rs"] | |
34 | pub mod thread_local; | |
35 | pub mod time; | |
36 | ||
37 | mod abi; | |
38 | ||
39 | mod shims; | |
40 | pub use self::shims::*; | |
41 | ||
42 | #[allow(dead_code)] | |
43 | pub fn init() {} | |
44 | ||
45 | pub fn decode_error_kind(errno: i32) -> io::ErrorKind { | |
46 | match errno { | |
47 | x if x == abi::errno::ACCES as i32 => io::ErrorKind::PermissionDenied, | |
48 | x if x == abi::errno::ADDRINUSE as i32 => io::ErrorKind::AddrInUse, | |
49 | x if x == abi::errno::ADDRNOTAVAIL as i32 => io::ErrorKind::AddrNotAvailable, | |
50 | x if x == abi::errno::AGAIN as i32 => io::ErrorKind::WouldBlock, | |
51 | x if x == abi::errno::CONNABORTED as i32 => io::ErrorKind::ConnectionAborted, | |
52 | x if x == abi::errno::CONNREFUSED as i32 => io::ErrorKind::ConnectionRefused, | |
53 | x if x == abi::errno::CONNRESET as i32 => io::ErrorKind::ConnectionReset, | |
54 | x if x == abi::errno::EXIST as i32 => io::ErrorKind::AlreadyExists, | |
55 | x if x == abi::errno::INTR as i32 => io::ErrorKind::Interrupted, | |
56 | x if x == abi::errno::INVAL as i32 => io::ErrorKind::InvalidInput, | |
57 | x if x == abi::errno::NOENT as i32 => io::ErrorKind::NotFound, | |
58 | x if x == abi::errno::NOTCONN as i32 => io::ErrorKind::NotConnected, | |
59 | x if x == abi::errno::PERM as i32 => io::ErrorKind::PermissionDenied, | |
60 | x if x == abi::errno::PIPE as i32 => io::ErrorKind::BrokenPipe, | |
61 | x if x == abi::errno::TIMEDOUT as i32 => io::ErrorKind::TimedOut, | |
62 | _ => io::ErrorKind::Other, | |
63 | } | |
64 | } | |
65 | ||
66 | pub unsafe fn abort_internal() -> ! { | |
67 | ::core::intrinsics::abort(); | |
68 | } | |
69 | ||
70 | pub use libc::strlen; | |
71 | ||
72 | pub fn hashmap_random_keys() -> (u64, u64) { | |
73 | unsafe { | |
74 | let mut v = mem::uninitialized(); | |
75 | libc::arc4random_buf(&mut v as *mut _ as *mut libc::c_void, mem::size_of_val(&v)); | |
76 | v | |
77 | } | |
78 | } |