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