diff --git a/src/error.rs b/src/error.rs index f99feac78c..9b3051edb0 100644 --- a/src/error.rs +++ b/src/error.rs @@ -7,17 +7,26 @@ pub struct Errno(pub c_int); #[cfg(target_os = "redox")] impl From for Errno { + #[inline] fn from(value: syscall::Error) -> Self { Errno(value.errno) } } #[cfg(target_os = "redox")] impl From for syscall::Error { + #[inline] fn from(value: Errno) -> Self { syscall::Error::new(value.0) } } +impl From for crate::io::Error { + #[inline] + fn from(Errno(errno): Errno) -> Self { + Self::from_raw_os_error(errno) + } +} + pub trait ResultExt { fn or_minus_one_errno(self) -> T; } @@ -25,10 +34,10 @@ impl> ResultExt for Result { fn or_minus_one_errno(self) -> T { match self { Self::Ok(v) => v, - Self::Err(Errno(errno)) => unsafe { + Self::Err(Errno(errno)) => { crate::platform::ERRNO.set(errno); T::from(-1) - }, + } } } }