]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/redox/mod.rs
Auto merge of #56838 - Aaron1011:fix/rustdoc-infer-unify, r=nikomatsakis
[rust.git] / src / libstd / sys / redox / mod.rs
1 #![allow(dead_code, missing_docs, nonstandard_style)]
2
3 use io::{self, ErrorKind};
4
5 pub use libc::strlen;
6 pub use self::rand::hashmap_random_keys;
7
8 #[path = "../unix/alloc.rs"]
9 pub mod alloc;
10 pub mod args;
11 #[cfg(feature = "backtrace")]
12 pub mod backtrace;
13 pub mod cmath;
14 pub mod condvar;
15 pub mod env;
16 pub mod ext;
17 pub mod fast_thread_local;
18 pub mod fd;
19 pub mod fs;
20 pub mod memchr;
21 pub mod mutex;
22 pub mod net;
23 pub mod os;
24 pub mod os_str;
25 pub mod path;
26 pub mod pipe;
27 pub mod process;
28 pub mod rand;
29 pub mod rwlock;
30 pub mod stack_overflow;
31 pub mod stdio;
32 pub mod syscall;
33 pub mod thread;
34 pub mod thread_local;
35 pub mod time;
36
37 #[cfg(not(test))]
38 pub fn init() {}
39
40 pub fn decode_error_kind(errno: i32) -> ErrorKind {
41     match errno {
42         syscall::ECONNREFUSED => ErrorKind::ConnectionRefused,
43         syscall::ECONNRESET => ErrorKind::ConnectionReset,
44         syscall::EPERM | syscall::EACCES => ErrorKind::PermissionDenied,
45         syscall::EPIPE => ErrorKind::BrokenPipe,
46         syscall::ENOTCONN => ErrorKind::NotConnected,
47         syscall::ECONNABORTED => ErrorKind::ConnectionAborted,
48         syscall::EADDRNOTAVAIL => ErrorKind::AddrNotAvailable,
49         syscall::EADDRINUSE => ErrorKind::AddrInUse,
50         syscall::ENOENT => ErrorKind::NotFound,
51         syscall::EINTR => ErrorKind::Interrupted,
52         syscall::EINVAL => ErrorKind::InvalidInput,
53         syscall::ETIMEDOUT => ErrorKind::TimedOut,
54         syscall::EEXIST => ErrorKind::AlreadyExists,
55
56         // These two constants can have the same value on some systems,
57         // but different values on others, so we can't use a match
58         // clause
59         x if x == syscall::EAGAIN || x == syscall::EWOULDBLOCK =>
60             ErrorKind::WouldBlock,
61
62         _ => ErrorKind::Other,
63     }
64 }
65
66 pub fn cvt(result: Result<usize, syscall::Error>) -> io::Result<usize> {
67     result.map_err(|err| io::Error::from_raw_os_error(err.errno))
68 }
69
70 #[doc(hidden)]
71 pub trait IsMinusOne {
72     fn is_minus_one(&self) -> bool;
73 }
74
75 macro_rules! impl_is_minus_one {
76     ($($t:ident)*) => ($(impl IsMinusOne for $t {
77         fn is_minus_one(&self) -> bool {
78             *self == -1
79         }
80     })*)
81 }
82
83 impl_is_minus_one! { i8 i16 i32 i64 isize }
84
85 pub fn cvt_libc<T: IsMinusOne>(t: T) -> io::Result<T> {
86     if t.is_minus_one() {
87         Err(io::Error::last_os_error())
88     } else {
89         Ok(t)
90     }
91 }
92
93 /// On Redox, use an illegal instruction to abort
94 pub unsafe fn abort_internal() -> ! {
95     ::core::intrinsics::abort();
96 }