summaryrefslogtreecommitdiff
path: root/src/fcntl.rs
diff options
context:
space:
mode:
authorUtkarsh Kukreti <utkarshkukreti@gmail.com>2015-02-10 12:10:57 +0530
committerCarl Lerche <me@carllerche.com>2015-02-10 22:34:13 -0800
commiteffb423fdb26843612edca6a748e479522089c1d (patch)
treea2ca4f77d2bfd158f42d8a90cd4b4c2df371037d /src/fcntl.rs
parent51becf70d23c1ac6184921fb729fd61324538ddc (diff)
downloadnix-effb423fdb26843612edca6a748e479522089c1d.zip
Add `NixPath`, `NixError`, and `NixResult`.
Diffstat (limited to 'src/fcntl.rs')
-rw-r--r--src/fcntl.rs19
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(())