diff options
| author | Jeremy Soller <jackpot51@gmail.com> | 2016-10-28 14:17:34 -0600 |
|---|---|---|
| committer | Jeremy Soller <jackpot51@gmail.com> | 2016-10-28 14:17:34 -0600 |
| commit | a5de9bb591c9752d39c87339fd8f5ff49ea4b2da (patch) | |
| tree | 69c296d20f5fe58d0bbd2b603bd4143430a5d6a2 /src/libstd/sys/redox/mod.rs | |
| parent | 8b09e01fef9912e7c3eef997c40f9f4f91d09e4c (diff) | |
| download | rust-a5de9bb591c9752d39c87339fd8f5ff49ea4b2da.tar.gz rust-a5de9bb591c9752d39c87339fd8f5ff49ea4b2da.zip | |
Remove unsafe libc layer
Diffstat (limited to 'src/libstd/sys/redox/mod.rs')
| -rw-r--r-- | src/libstd/sys/redox/mod.rs | 39 |
1 files changed, 3 insertions, 36 deletions
diff --git a/src/libstd/sys/redox/mod.rs b/src/libstd/sys/redox/mod.rs index 108ebb0800e..f7465d01fad 100644 --- a/src/libstd/sys/redox/mod.rs +++ b/src/libstd/sys/redox/mod.rs @@ -41,9 +41,7 @@ pub fn init() { use intrinsics; let msg = "fatal runtime error: out of memory\n"; unsafe { - libc::write(libc::STDERR_FILENO, - msg.as_ptr() as *const libc::c_void, - msg.len()); + let _ = libc::write(libc::STDERR_FILENO, msg.as_bytes()); intrinsics::abort(); } } @@ -75,37 +73,6 @@ pub fn decode_error_kind(errno: i32) -> 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 cvt<T: IsMinusOne>(t: T) -> io::Result<T> { - if t.is_minus_one() { - Err(io::Error::last_os_error()) - } else { - Ok(t) - } -} - -pub fn cvt_r<T, F>(mut f: F) -> io::Result<T> - where T: IsMinusOne, - F: FnMut() -> T -{ - loop { - match cvt(f()) { - Err(ref e) if e.kind() == ErrorKind::Interrupted => {} - other => return other, - } - } +pub fn cvt(result: Result<usize, libc::Error>) -> io::Result<usize> { + result.map_err(|err| io::Error::from_raw_os_error(err.errno as i32)) } |
