]> git.proxmox.com Git - rustc.git/blame - src/libstd/sys/vxworks/mod.rs
New upstream version 1.42.0+dfsg1
[rustc.git] / src / libstd / sys / vxworks / mod.rs
CommitLineData
416331ca
XL
1#![allow(dead_code)]
2#![allow(missing_docs, nonstandard_style)]
3
4use crate::io::ErrorKind;
5
416331ca 6pub use self::rand::hashmap_random_keys;
60c5eb7d 7pub use crate::os::vxworks as platform;
416331ca
XL
8pub use libc::strlen;
9
10pub mod alloc;
11pub mod args;
12pub mod cmath;
13pub mod condvar;
14pub mod env;
15pub mod ext;
16pub mod fast_thread_local;
17pub mod fd;
18pub mod fs;
416331ca 19pub mod io;
60c5eb7d 20pub mod memchr;
416331ca
XL
21pub mod mutex;
22pub mod net;
23pub mod os;
24pub mod path;
25pub mod pipe;
26pub mod process;
27pub mod rand;
28pub mod rwlock;
29pub mod stack_overflow;
60c5eb7d 30pub mod stdio;
416331ca
XL
31pub mod thread;
32pub mod thread_local;
33pub mod time;
416331ca
XL
34
35pub use crate::sys_common::os_str_bytes as os_str;
36
37#[cfg(not(test))]
38pub fn init() {
dfeec247 39 // ignore SIGPIPE
416331ca 40 unsafe {
dfeec247 41 assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR);
416331ca 42 }
416331ca
XL
43}
44
45pub use libc::signal;
46
47pub 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,
62
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
65 // clause
60c5eb7d 66 x if x == libc::EAGAIN || x == libc::EWOULDBLOCK => ErrorKind::WouldBlock,
416331ca
XL
67
68 _ => ErrorKind::Other,
69 }
70}
71
72#[doc(hidden)]
73pub trait IsMinusOne {
74 fn is_minus_one(&self) -> bool;
75}
76
77macro_rules! impl_is_minus_one {
78 ($($t:ident)*) => ($(impl IsMinusOne for $t {
79 fn is_minus_one(&self) -> bool {
80 *self == -1
81 }
82 })*)
83}
84
85impl_is_minus_one! { i8 i16 i32 i64 isize }
86
87pub fn cvt<T: IsMinusOne>(t: T) -> crate::io::Result<T> {
60c5eb7d 88 if t.is_minus_one() { Err(crate::io::Error::last_os_error()) } else { Ok(t) }
416331ca
XL
89}
90
91pub fn cvt_r<T, F>(mut f: F) -> crate::io::Result<T>
60c5eb7d
XL
92where
93 T: IsMinusOne,
94 F: FnMut() -> T,
416331ca
XL
95{
96 loop {
97 match cvt(f()) {
98 Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
99 other => return other,
100 }
101 }
102}
103
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 bufferred
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.
111pub unsafe fn abort_internal() -> ! {
112 libc::abort()
113}