diff options
Diffstat (limited to 'src/sys/stat.rs')
-rw-r--r-- | src/sys/stat.rs | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/sys/stat.rs b/src/sys/stat.rs index ca17039c..1397ad24 100644 --- a/src/sys/stat.rs +++ b/src/sys/stat.rs @@ -3,11 +3,10 @@ pub use libc::stat as FileStat; use std::fmt; use std::mem; -use std::old_path::Path; +use errno::Errno; use libc::mode_t; -use errno::{SysResult, SysError, from_ffi}; use fcntl::Fd; -use utils::ToCStr; +use {NixError, NixResult, NixPath, from_ffi}; mod ffi { use libc::{c_char, c_int, mode_t, dev_t}; @@ -58,8 +57,12 @@ impl fmt::Debug for SFlag { } } -pub fn mknod(path: &Path, kind: SFlag, perm: Mode, dev: dev_t) -> SysResult<()> { - let res = unsafe { ffi::mknod(path.to_c_str().as_ptr(), kind.bits | perm.bits() as mode_t, dev) }; +pub fn mknod<P: NixPath>(path: P, kind: SFlag, perm: Mode, dev: dev_t) -> NixResult<()> { + let res = try!(path.with_nix_path(|ptr| { + unsafe { + ffi::mknod(ptr, kind.bits | perm.bits() as mode_t, dev) + } + })); from_ffi(res) } @@ -76,23 +79,27 @@ pub fn umask(mode: Mode) -> Mode { Mode::from_bits(prev).expect("[BUG] umask returned invalid Mode") } -pub fn stat(path: &Path) -> SysResult<FileStat> { +pub fn stat<P: NixPath>(path: P) -> NixResult<FileStat> { let mut dst = unsafe { mem::uninitialized() }; - let res = unsafe { ffi::stat(path.to_c_str().as_ptr(), &mut dst as *mut FileStat) }; + let res = try!(path.with_nix_path(|ptr| { + unsafe { + ffi::stat(ptr, &mut dst as *mut FileStat) + } + })); if res < 0 { - return Err(SysError::last()); + return Err(NixError::Sys(Errno::last())); } Ok(dst) } -pub fn fstat(fd: Fd) -> SysResult<FileStat> { +pub fn fstat(fd: Fd) -> NixResult<FileStat> { let mut dst = unsafe { mem::uninitialized() }; let res = unsafe { ffi::fstat(fd, &mut dst as *mut FileStat) }; if res < 0 { - return Err(SysError::last()); + return Err(NixError::Sys(Errno::last())); } Ok(dst) |