1 #![allow(missing_docs, nonstandard_style)]
3 use crate::io::ErrorKind;
5 #[cfg(any(rustdoc, target_os = "linux"))] pub use crate::os::linux as platform;
7 #[cfg(all(not(rustdoc), target_os = "android"))] pub use crate::os::android as platform;
8 #[cfg(all(not(rustdoc), target_os = "bitrig"))] pub use crate::os::bitrig as platform;
9 #[cfg(all(not(rustdoc), target_os = "dragonfly"))] pub use crate::os::dragonfly as platform;
10 #[cfg(all(not(rustdoc), target_os = "freebsd"))] pub use crate::os::freebsd as platform;
11 #[cfg(all(not(rustdoc), target_os = "haiku"))] pub use crate::os::haiku as platform;
12 #[cfg(all(not(rustdoc), target_os = "ios"))] pub use crate::os::ios as platform;
13 #[cfg(all(not(rustdoc), target_os = "macos"))] pub use crate::os::macos as platform;
14 #[cfg(all(not(rustdoc), target_os = "netbsd"))] pub use crate::os::netbsd as platform;
15 #[cfg(all(not(rustdoc), target_os = "openbsd"))] pub use crate::os::openbsd as platform;
16 #[cfg(all(not(rustdoc), target_os = "solaris"))] pub use crate::os::solaris as platform;
17 #[cfg(all(not(rustdoc), target_os = "emscripten"))] pub use crate::os::emscripten as platform;
18 #[cfg(all(not(rustdoc), target_os = "fuchsia"))] pub use crate::os::fuchsia as platform;
19 #[cfg(all(not(rustdoc), target_os = "l4re"))] pub use crate::os::linux as platform;
20 #[cfg(all(not(rustdoc), target_os = "hermit"))] pub use crate::os::hermit as platform;
22 pub use self::rand::hashmap_random_keys;
31 #[cfg(feature = "backtrace")]
37 pub mod fast_thread_local;
43 #[cfg(not(target_os = "l4re"))]
45 #[cfg(target_os = "l4re")]
47 #[cfg(target_os = "l4re")]
48 pub use self::l4re::net;
56 pub mod stack_overflow;
64 // By default, some platforms will send a *signal* when an EPIPE error
65 // would otherwise be delivered. This runtime doesn't install a SIGPIPE
66 // handler, causing it to kill the program, which isn't exactly what we
69 // Hence, we set SIGPIPE to ignore when the program starts up in order
70 // to prevent this problem.
75 #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia")))]
76 unsafe fn reset_sigpipe() {
77 assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR);
79 #[cfg(any(target_os = "emscripten", target_os = "fuchsia"))]
80 unsafe fn reset_sigpipe() {}
83 #[cfg(target_os = "android")]
84 pub use crate::sys::android::signal;
85 #[cfg(not(target_os = "android"))]
88 pub fn decode_error_kind(errno: i32) -> ErrorKind {
89 match errno as libc::c_int {
90 libc::ECONNREFUSED => ErrorKind::ConnectionRefused,
91 libc::ECONNRESET => ErrorKind::ConnectionReset,
92 libc::EPERM | libc::EACCES => ErrorKind::PermissionDenied,
93 libc::EPIPE => ErrorKind::BrokenPipe,
94 libc::ENOTCONN => ErrorKind::NotConnected,
95 libc::ECONNABORTED => ErrorKind::ConnectionAborted,
96 libc::EADDRNOTAVAIL => ErrorKind::AddrNotAvailable,
97 libc::EADDRINUSE => ErrorKind::AddrInUse,
98 libc::ENOENT => ErrorKind::NotFound,
99 libc::EINTR => ErrorKind::Interrupted,
100 libc::EINVAL => ErrorKind::InvalidInput,
101 libc::ETIMEDOUT => ErrorKind::TimedOut,
102 libc::EEXIST => ErrorKind::AlreadyExists,
104 // These two constants can have the same value on some systems,
105 // but different values on others, so we can't use a match
107 x if x == libc::EAGAIN || x == libc::EWOULDBLOCK =>
108 ErrorKind::WouldBlock,
110 _ => ErrorKind::Other,
115 pub trait IsMinusOne {
116 fn is_minus_one(&self) -> bool;
119 macro_rules! impl_is_minus_one {
120 ($($t:ident)*) => ($(impl IsMinusOne for $t {
121 fn is_minus_one(&self) -> bool {
127 impl_is_minus_one! { i8 i16 i32 i64 isize }
129 pub fn cvt<T: IsMinusOne>(t: T) -> crate::io::Result<T> {
130 if t.is_minus_one() {
131 Err(crate::io::Error::last_os_error())
137 pub fn cvt_r<T, F>(mut f: F) -> crate::io::Result<T>
143 Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
144 other => return other,
149 // On Unix-like platforms, libc::abort will unregister signal handlers
150 // including the SIGABRT handler, preventing the abort from being blocked, and
151 // fclose streams, with the side effect of flushing them so libc bufferred
152 // output will be printed. Additionally the shell will generally print a more
153 // understandable error message like "Abort trap" rather than "Illegal
154 // instruction" that intrinsics::abort would cause, as intrinsics::abort is
155 // implemented as an illegal instruction.
156 pub unsafe fn abort_internal() -> ! {