From 136bb454d98a9032843259e71f12d8e33cd90f27 Mon Sep 17 00:00:00 2001 From: arcnmx Date: Mon, 25 Jan 2016 21:57:17 -0500 Subject: Errno::result() --- src/sys/stat.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'src/sys/stat.rs') diff --git a/src/sys/stat.rs b/src/sys/stat.rs index 2a34d282..391924da 100644 --- a/src/sys/stat.rs +++ b/src/sys/stat.rs @@ -1,8 +1,8 @@ pub use libc::dev_t; pub use libc::stat as FileStat; -use {Error, Result, NixPath, from_ffi}; -use errno::Errno; +use NixPath; +use errno::{Errno, Result}; use libc::mode_t; use std::mem; use std::os::unix::io::RawFd; @@ -56,7 +56,8 @@ pub fn mknod(path: &P, kind: SFlag, perm: Mode, dev: dev_t) ffi::mknod(cstr.as_ptr(), kind.bits | perm.bits() as mode_t, dev) } })); - from_ffi(res) + + Errno::result(res).map(drop) } #[cfg(target_os = "linux")] @@ -80,9 +81,7 @@ pub fn stat(path: &P) -> Result { } })); - if res < 0 { - return Err(Error::Sys(Errno::last())); - } + try!(Errno::result(res)); Ok(dst) } @@ -95,9 +94,7 @@ pub fn lstat(path: &P) -> Result { } })); - if res < 0 { - return Err(Error::Sys(Errno::last())); - } + try!(Errno::result(res)); Ok(dst) } @@ -106,9 +103,7 @@ pub fn fstat(fd: RawFd) -> Result { let mut dst = unsafe { mem::uninitialized() }; let res = unsafe { ffi::fstat(fd, &mut dst as *mut FileStat) }; - if res < 0 { - return Err(Error::Sys(Errno::last())); - } + try!(Errno::result(res)); Ok(dst) } -- cgit v1.2.3