-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmod.rs
More file actions
93 lines (80 loc) · 1.85 KB
/
mod.rs
File metadata and controls
93 lines (80 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#![allow(unused)]
#[path = "../unix/weak.rs"]
#[macro_use]
pub mod weak;
pub mod alloc;
pub mod args;
#[path = "../unix/cmath.rs"]
pub mod cmath;
pub mod env;
pub mod fs;
pub mod io;
pub mod locks;
pub mod net;
pub mod os;
#[path = "../unix/os_str.rs"]
pub mod os_str;
#[path = "../unix/path.rs"]
pub mod path;
pub mod pipe;
pub mod process;
pub mod rand;
pub mod stdio;
pub mod thread;
#[cfg(target_thread_local)]
pub mod thread_local_dtor;
pub mod thread_local_key;
pub mod time;
pub use rand::hashmap_random_keys;
mod common;
pub use common::*;
pub mod fd;
use crate::ffi::CStr;
use crate::io::ErrorKind;
#[doc(hidden)]
pub trait IsMinusOne {
fn is_minus_one(&self) -> bool;
}
macro_rules! impl_is_minus_one {
($($t:ident)*) => ($(impl IsMinusOne for $t {
fn is_minus_one(&self) -> bool {
*self == -1
}
})*)
}
impl_is_minus_one! { i8 i16 i32 i64 isize }
pub fn real_last_os_error_use_carefully() -> crate::io::Error {
crate::io::Error::from_raw_os_error(os::real_errno_use_carefully())
}
// TODO: audit these and think about them more...
pub use {cvt_unsup as cvt, cvt_unsup_r as cvt_r};
pub fn cvt_unsup<T: IsMinusOne>(t: T) -> crate::io::Result<T> {
if t.is_minus_one() {
unsupported()
} else {
Ok(t)
}
}
pub fn cvt_unsup_r<T, F>(mut f: F) -> crate::io::Result<T>
where
T: IsMinusOne,
F: FnMut() -> T,
{
loop {
if f().is_minus_one() {
let e = real_last_os_error_use_carefully();
if e.kind() != ErrorKind::Interrupted {
return unsupported();
}
}
}
}
// #[allow(dead_code)] // Not used on all platforms.
// pub fn cvt_nz(error: libc::c_int) -> crate::io::Result<()> {
// if error == 0 {
// Ok(())
// } else {
// Err(crate::io::Error::from_raw_os_error(error))
// }
// }
pub use libc::strlen;