diff options
author | arcnmx <arcnmx@users.noreply.github.com> | 2016-01-25 21:57:17 -0500 |
---|---|---|
committer | Kamal Marhubi <kamal@marhubi.com> | 2016-01-28 00:44:44 -0500 |
commit | 136bb454d98a9032843259e71f12d8e33cd90f27 (patch) | |
tree | 942872a1bad2de7b3417f248dda6d70b8ac01d54 /src/sys/stat.rs | |
parent | 01e841679633b459470120a305ff22dd12138422 (diff) | |
download | nix-136bb454d98a9032843259e71f12d8e33cd90f27.zip |
Errno::result()
Diffstat (limited to 'src/sys/stat.rs')
-rw-r--r-- | src/sys/stat.rs | 19 |
1 files changed, 7 insertions, 12 deletions
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<P: ?Sized + NixPath>(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<P: ?Sized + NixPath>(path: &P) -> Result<FileStat> { } })); - if res < 0 { - return Err(Error::Sys(Errno::last())); - } + try!(Errno::result(res)); Ok(dst) } @@ -95,9 +94,7 @@ pub fn lstat<P: ?Sized + NixPath>(path: &P) -> Result<FileStat> { } })); - 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<FileStat> { 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) } |