2 #![allow(missing_docs, nonstandard_style)]
4 use crate::io::ErrorKind;
6 pub use self::rand::hashmap_random_keys;
7 pub use crate::os::vxworks as platform;
16 pub mod fast_thread_local;
29 pub mod stack_overflow;
35 pub use crate::sys_common::os_str_bytes as os_str;
41 assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR);
47 pub fn decode_error_kind(errno: i32) -> ErrorKind {
48 match errno as libc::c_int {
49 libc::ECONNREFUSED => ErrorKind::ConnectionRefused,
50 libc::ECONNRESET => ErrorKind::ConnectionReset,
51 libc::EPERM | libc::EACCES => ErrorKind::PermissionDenied,
52 libc::EPIPE => ErrorKind::BrokenPipe,
53 libc::ENOTCONN => ErrorKind::NotConnected,
54 libc::ECONNABORTED => ErrorKind::ConnectionAborted,
55 libc::EADDRNOTAVAIL => ErrorKind::AddrNotAvailable,
56 libc::EADDRINUSE => ErrorKind::AddrInUse,
57 libc::ENOENT => ErrorKind::NotFound,
58 libc::EINTR => ErrorKind::Interrupted,
59 libc::EINVAL => ErrorKind::InvalidInput,
60 libc::ETIMEDOUT => ErrorKind::TimedOut,
61 libc::EEXIST => ErrorKind::AlreadyExists,
63 // These two constants can have the same value on some systems,
64 // but different values on others, so we can't use a match
66 x if x == libc::EAGAIN || x == libc::EWOULDBLOCK => ErrorKind::WouldBlock,
68 _ => ErrorKind::Other,
73 pub trait IsMinusOne {
74 fn is_minus_one(&self) -> bool;
77 macro_rules! impl_is_minus_one {
78 ($($t:ident)*) => ($(impl IsMinusOne for $t {
79 fn is_minus_one(&self) -> bool {
85 impl_is_minus_one! { i8 i16 i32 i64 isize }
87 pub fn cvt<T: IsMinusOne>(t: T) -> crate::io::Result<T> {
88 if t.is_minus_one() { Err(crate::io::Error::last_os_error()) } else { Ok(t) }
91 pub fn cvt_r<T, F>(mut f: F) -> crate::io::Result<T>
98 Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
99 other => return other,
104 // On Unix-like platforms, libc::abort will unregister signal handlers
105 // including the SIGABRT handler, preventing the abort from being blocked, and
106 // fclose streams, with the side effect of flushing them so libc buffered
107 // output will be printed. Additionally the shell will generally print a more
108 // understandable error message like "Abort trap" rather than "Illegal
109 // instruction" that intrinsics::abort would cause, as intrinsics::abort is
110 // implemented as an illegal instruction.
111 pub unsafe fn abort_internal() -> ! {