summaryrefslogtreecommitdiff
path: root/src/fcntl.rs
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2015-05-21 16:38:54 -0700
committerCarl Lerche <me@carllerche.com>2015-05-21 16:38:54 -0700
commit21fb1394a111d19079da90a4d31171b0d6adc27c (patch)
treee2c9f436216cb238b6bfe8c27b3a3ce34668aca1 /src/fcntl.rs
parent3fc83b942a57fd76372e83e987fc191f6bdf6a5c (diff)
downloadnix-21fb1394a111d19079da90a4d31171b0d6adc27c.zip
Fix NixPath yield with CStr instead of OsStr
As described in #117, the `AsExtStr` trait is defined to return a raw `*const libc::c_char`. Its impl for `OsStr` simply borrowed the byte slice from its `OsStr` argument and cast it to a `*const libc::c_char`, which does not construct a proper null-terminated C string. Given this, the `AsExtStr` is not necessary and is removed. `NixPath` is updated to yield `CStr`. Fixes #117, #120 Thanks to @dead10ck
Diffstat (limited to 'src/fcntl.rs')
-rw-r--r--src/fcntl.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/fcntl.rs b/src/fcntl.rs
index 73c0619c..76ea9f65 100644
--- a/src/fcntl.rs
+++ b/src/fcntl.rs
@@ -1,4 +1,4 @@
-use {Error, Result, NixPath, AsExtStr};
+use {Error, Result, NixPath};
use errno::Errno;
use libc::mode_t;
use sys::stat::Mode;
@@ -72,8 +72,8 @@ mod ffi {
}
pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag, mode: Mode) -> Result<Fd> {
- let fd = try!(path.with_nix_path(|osstr| {
- unsafe { ffi::open(osstr.as_ext_str(), oflag.bits(), mode.bits() as mode_t) }
+ let fd = try!(path.with_nix_path(|cstr| {
+ unsafe { ffi::open(cstr.as_ptr(), oflag.bits(), mode.bits() as mode_t) }
}));
if fd < 0 {