]>
git.proxmox.com Git - rustc.git/blob - src/libstd/sys/unix/mod.rs
c1a4e8cee9ed4079fdbac145417ef76c7b520351
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 = "openbsd")] pub use os::openbsd as platform;
44 pub mod stack_overflow
;
51 pub fn decode_error_kind(errno
: i32) -> ErrorKind
{
52 match errno
as libc
::c_int
{
53 libc
::ECONNREFUSED
=> ErrorKind
::ConnectionRefused
,
54 libc
::ECONNRESET
=> ErrorKind
::ConnectionReset
,
55 libc
::EPERM
| libc
::EACCES
=> ErrorKind
::PermissionDenied
,
56 libc
::EPIPE
=> ErrorKind
::BrokenPipe
,
57 libc
::ENOTCONN
=> ErrorKind
::NotConnected
,
58 libc
::ECONNABORTED
=> ErrorKind
::ConnectionAborted
,
59 libc
::EADDRNOTAVAIL
=> ErrorKind
::AddrNotAvailable
,
60 libc
::EADDRINUSE
=> ErrorKind
::AddrInUse
,
61 libc
::ENOENT
=> ErrorKind
::NotFound
,
62 libc
::EINTR
=> ErrorKind
::Interrupted
,
63 libc
::EINVAL
=> ErrorKind
::InvalidInput
,
64 libc
::ETIMEDOUT
=> ErrorKind
::TimedOut
,
65 libc
::consts
::os
::posix88
::EEXIST
=> ErrorKind
::AlreadyExists
,
67 // These two constants can have the same value on some systems,
68 // but different values on others, so we can't use a match
70 x
if x
== libc
::EAGAIN
|| x
== libc
::EWOULDBLOCK
=>
71 ErrorKind
::WouldBlock
,
73 _
=> ErrorKind
::Other
,
77 pub fn cvt
<T
: One
+ PartialEq
+ Neg
<Output
=T
>>(t
: T
) -> io
::Result
<T
> {
78 let one
: T
= T
::one();
80 Err(io
::Error
::last_os_error())
87 pub fn cvt_r
<T
, F
>(mut f
: F
) -> io
::Result
<T
>
88 where T
: One
+ PartialEq
+ Neg
<Output
=T
>, F
: FnMut() -> T
92 Err(ref e
) if e
.kind() == ErrorKind
::Interrupted
=> {}
93 other
=> return other
,
98 pub fn ms_to_timeval(ms
: u64) -> libc
::timeval
{
100 tv_sec
: (ms
/ 1000) as libc
::time_t
,
101 tv_usec
: ((ms
% 1000) * 1000) as libc
::suseconds_t
,