diff options
Diffstat (limited to 'src/fcntl.rs')
-rw-r--r-- | src/fcntl.rs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/fcntl.rs b/src/fcntl.rs index 471a04d3..ac0e99c2 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -1,8 +1,7 @@ -use std::old_path::Path; use libc::{c_int, mode_t}; -use errno::{SysResult, SysError}; +use errno::Errno; +use {NixError, NixResult, NixPath}; use sys::stat::Mode; -use utils::ToCStr; pub use self::consts::*; pub use self::ffi::flock; @@ -71,11 +70,15 @@ mod ffi { } } -pub fn open(path: &Path, oflag: OFlag, mode: Mode) -> SysResult<Fd> { - let fd = unsafe { ffi::open(path.to_c_str().as_ptr(), oflag.bits(), mode.bits() as mode_t) }; +pub fn open<P: NixPath>(path: P, oflag: OFlag, mode: Mode) -> NixResult<Fd> { + let fd = try!(path.with_nix_path(|ptr| { + unsafe { + ffi::open(ptr, oflag.bits(), mode.bits() as mode_t) + } + })); if fd < 0 { - return Err(SysError::last()); + return Err(NixError::Sys(Errno::last())); } Ok(fd) @@ -102,7 +105,7 @@ pub enum FcntlArg<'a> { } // TODO: Figure out how to handle value fcntl returns -pub fn fcntl(fd: Fd, arg: FcntlArg) -> SysResult<()> { +pub fn fcntl(fd: Fd, arg: FcntlArg) -> NixResult<()> { use self::FcntlArg::*; let res = unsafe { @@ -114,7 +117,7 @@ pub fn fcntl(fd: Fd, arg: FcntlArg) -> SysResult<()> { }; if res < 0 { - return Err(SysError::last()); + return Err(NixError::Sys(Errno::last())); } Ok(()) |