1 // Copyright 2014 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.
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.
11 #![allow(missing_docs)]
12 #![allow(non_camel_case_types)]
16 use io::{self, ErrorKind};
21 #[cfg(target_os = "android")] pub use os::android as platform;
22 #[cfg(target_os = "bitrig")] pub use os::bitrig as platform;
23 #[cfg(target_os = "dragonfly")] pub use os::dragonfly as platform;
24 #[cfg(target_os = "freebsd")] pub use os::freebsd as platform;
25 #[cfg(target_os = "ios")] pub use os::ios as platform;
26 #[cfg(target_os = "linux")] pub use os::linux as platform;
27 #[cfg(target_os = "macos")] pub use os::macos as platform;
28 #[cfg(target_os = "nacl")] pub use os::nacl as platform;
29 #[cfg(target_os = "netbsd")] pub use os::netbsd as platform;
30 #[cfg(target_os = "openbsd")] pub use os::openbsd as platform;
45 pub mod stack_overflow;
52 pub fn decode_error_kind(errno: i32) -> ErrorKind {
53 match errno as libc::c_int {
54 libc::ECONNREFUSED => ErrorKind::ConnectionRefused,
55 libc::ECONNRESET => ErrorKind::ConnectionReset,
56 libc::EPERM | libc::EACCES => ErrorKind::PermissionDenied,
57 libc::EPIPE => ErrorKind::BrokenPipe,
58 libc::ENOTCONN => ErrorKind::NotConnected,
59 libc::ECONNABORTED => ErrorKind::ConnectionAborted,
60 libc::EADDRNOTAVAIL => ErrorKind::AddrNotAvailable,
61 libc::EADDRINUSE => ErrorKind::AddrInUse,
62 libc::ENOENT => ErrorKind::NotFound,
63 libc::EINTR => ErrorKind::Interrupted,
64 libc::EINVAL => ErrorKind::InvalidInput,
65 libc::ETIMEDOUT => ErrorKind::TimedOut,
66 libc::consts::os::posix88::EEXIST => ErrorKind::AlreadyExists,
68 // These two constants can have the same value on some systems,
69 // but different values on others, so we can't use a match
71 x if x == libc::EAGAIN || x == libc::EWOULDBLOCK =>
72 ErrorKind::WouldBlock,
74 _ => ErrorKind::Other,
78 pub fn cvt<T: One + PartialEq + Neg<Output=T>>(t: T) -> io::Result<T> {
79 let one: T = T::one();
81 Err(io::Error::last_os_error())
88 pub fn cvt_r<T, F>(mut f: F) -> io::Result<T>
89 where T: One + PartialEq + Neg<Output=T>, F: FnMut() -> T
93 Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
94 other => return other,
99 pub fn ms_to_timeval(ms: u64) -> libc::timeval {
101 tv_sec: (ms / 1000) as libc::time_t,
102 tv_usec: ((ms % 1000) * 1000) as libc::suseconds_t,