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)]
14 use io::{self, ErrorKind};
19 #[cfg(target_os = "android")] pub use os::android as platform;
20 #[cfg(target_os = "bitrig")] pub use os::bitrig as platform;
21 #[cfg(target_os = "dragonfly")] pub use os::dragonfly as platform;
22 #[cfg(target_os = "freebsd")] pub use os::freebsd as platform;
23 #[cfg(target_os = "ios")] pub use os::ios as platform;
24 #[cfg(target_os = "linux")] pub use os::linux as platform;
25 #[cfg(target_os = "macos")] pub use os::macos as platform;
26 #[cfg(target_os = "nacl")] pub use os::nacl as platform;
27 #[cfg(target_os = "netbsd")] pub use os::netbsd as platform;
28 #[cfg(target_os = "openbsd")] pub use os::openbsd as platform;
42 pub mod stack_overflow;
48 #[cfg(not(target_os = "nacl"))]
51 // By default, some platforms will send a *signal* when an EPIPE error
52 // would otherwise be delivered. This runtime doesn't install a SIGPIPE
53 // handler, causing it to kill the program, which isn't exactly what we
56 // Hence, we set SIGPIPE to ignore when the program starts up in order
57 // to prevent this problem.
59 assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != !0);
62 #[cfg(target_os = "nacl")]
65 pub fn decode_error_kind(errno: i32) -> ErrorKind {
66 match errno as libc::c_int {
67 libc::ECONNREFUSED => ErrorKind::ConnectionRefused,
68 libc::ECONNRESET => ErrorKind::ConnectionReset,
69 libc::EPERM | libc::EACCES => ErrorKind::PermissionDenied,
70 libc::EPIPE => ErrorKind::BrokenPipe,
71 libc::ENOTCONN => ErrorKind::NotConnected,
72 libc::ECONNABORTED => ErrorKind::ConnectionAborted,
73 libc::EADDRNOTAVAIL => ErrorKind::AddrNotAvailable,
74 libc::EADDRINUSE => ErrorKind::AddrInUse,
75 libc::ENOENT => ErrorKind::NotFound,
76 libc::EINTR => ErrorKind::Interrupted,
77 libc::EINVAL => ErrorKind::InvalidInput,
78 libc::ETIMEDOUT => ErrorKind::TimedOut,
79 libc::EEXIST => ErrorKind::AlreadyExists,
81 // These two constants can have the same value on some systems,
82 // but different values on others, so we can't use a match
84 x if x == libc::EAGAIN || x == libc::EWOULDBLOCK =>
85 ErrorKind::WouldBlock,
87 _ => ErrorKind::Other,
91 pub fn cvt<T: One + PartialEq + Neg<Output=T>>(t: T) -> io::Result<T> {
92 let one: T = T::one();
94 Err(io::Error::last_os_error())
100 pub fn cvt_r<T, F>(mut f: F) -> io::Result<T>
101 where T: One + PartialEq + Neg<Output=T>, F: FnMut() -> T
105 Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
106 other => return other,