1 #![allow(missing_docs, nonstandard_style)]
3 use crate::io::ErrorKind;
5 #[cfg(any(doc, target_os = "linux"))]
6 pub use crate::os::linux as platform;
8 #[cfg(all(not(doc), target_os = "android"))]
9 pub use crate::os::android as platform;
10 #[cfg(all(not(doc), target_os = "dragonfly"))]
11 pub use crate::os::dragonfly as platform;
12 #[cfg(all(not(doc), target_os = "emscripten"))]
13 pub use crate::os::emscripten as platform;
14 #[cfg(all(not(doc), target_os = "freebsd"))]
15 pub use crate::os::freebsd as platform;
16 #[cfg(all(not(doc), target_os = "fuchsia"))]
17 pub use crate::os::fuchsia as platform;
18 #[cfg(all(not(doc), target_os = "haiku"))]
19 pub use crate::os::haiku as platform;
20 #[cfg(all(not(doc), target_os = "ios"))]
21 pub use crate::os::ios as platform;
22 #[cfg(all(not(doc), target_os = "l4re"))]
23 pub use crate::os::linux as platform;
24 #[cfg(all(not(doc), target_os = "macos"))]
25 pub use crate::os::macos as platform;
26 #[cfg(all(not(doc), target_os = "netbsd"))]
27 pub use crate::os::netbsd as platform;
28 #[cfg(all(not(doc), target_os = "openbsd"))]
29 pub use crate::os::openbsd as platform;
30 #[cfg(all(not(doc), target_os = "redox"))]
31 pub use crate::os::redox as platform;
32 #[cfg(all(not(doc), target_os = "solaris"))]
33 pub use crate::os::solaris as platform;
35 pub use self::rand::hashmap_random_keys;
48 pub mod fast_thread_local;
52 #[cfg(target_os = "l4re")]
56 #[cfg(not(target_os = "l4re"))]
58 #[cfg(target_os = "l4re")]
59 pub use self::l4re::net;
66 pub mod stack_overflow;
72 pub use crate::sys_common::os_str_bytes as os_str;
76 // By default, some platforms will send a *signal* when an EPIPE error
77 // would otherwise be delivered. This runtime doesn't install a SIGPIPE
78 // handler, causing it to kill the program, which isn't exactly what we
81 // Hence, we set SIGPIPE to ignore when the program starts up in order
82 // to prevent this problem.
87 #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia")))]
88 unsafe fn reset_sigpipe() {
89 assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR);
91 #[cfg(any(target_os = "emscripten", target_os = "fuchsia"))]
92 unsafe fn reset_sigpipe() {}
95 #[cfg(target_os = "android")]
96 pub use crate::sys::android::signal;
97 #[cfg(not(target_os = "android"))]
100 pub fn decode_error_kind(errno: i32) -> ErrorKind {
101 match errno as libc::c_int {
102 libc::ECONNREFUSED => ErrorKind::ConnectionRefused,
103 libc::ECONNRESET => ErrorKind::ConnectionReset,
104 libc::EPERM | libc::EACCES => ErrorKind::PermissionDenied,
105 libc::EPIPE => ErrorKind::BrokenPipe,
106 libc::ENOTCONN => ErrorKind::NotConnected,
107 libc::ECONNABORTED => ErrorKind::ConnectionAborted,
108 libc::EADDRNOTAVAIL => ErrorKind::AddrNotAvailable,
109 libc::EADDRINUSE => ErrorKind::AddrInUse,
110 libc::ENOENT => ErrorKind::NotFound,
111 libc::EINTR => ErrorKind::Interrupted,
112 libc::EINVAL => ErrorKind::InvalidInput,
113 libc::ETIMEDOUT => ErrorKind::TimedOut,
114 libc::EEXIST => ErrorKind::AlreadyExists,
116 // These two constants can have the same value on some systems,
117 // but different values on others, so we can't use a match
119 x if x == libc::EAGAIN || x == libc::EWOULDBLOCK => ErrorKind::WouldBlock,
121 _ => ErrorKind::Other,
126 pub trait IsMinusOne {
127 fn is_minus_one(&self) -> bool;
130 macro_rules! impl_is_minus_one {
131 ($($t:ident)*) => ($(impl IsMinusOne for $t {
132 fn is_minus_one(&self) -> bool {
138 impl_is_minus_one! { i8 i16 i32 i64 isize }
140 pub fn cvt<T: IsMinusOne>(t: T) -> crate::io::Result<T> {
141 if t.is_minus_one() { Err(crate::io::Error::last_os_error()) } else { Ok(t) }
144 pub fn cvt_r<T, F>(mut f: F) -> crate::io::Result<T>
151 Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
152 other => return other,
157 // On Unix-like platforms, libc::abort will unregister signal handlers
158 // including the SIGABRT handler, preventing the abort from being blocked, and
159 // fclose streams, with the side effect of flushing them so libc buffered
160 // output will be printed. Additionally the shell will generally print a more
161 // understandable error message like "Abort trap" rather than "Illegal
162 // instruction" that intrinsics::abort would cause, as intrinsics::abort is
163 // implemented as an illegal instruction.
164 pub unsafe fn abort_internal() -> ! {