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