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