summaryrefslogtreecommitdiff
path: root/src/sys/stat.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/sys/stat.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/sys/stat.rs')
-rw-r--r--src/sys/stat.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/sys/stat.rs b/src/sys/stat.rs
index cafb36d9..60153a61 100644
--- a/src/sys/stat.rs
+++ b/src/sys/stat.rs
@@ -1,7 +1,7 @@
pub use libc::dev_t;
pub use libc::stat as FileStat;
-use {Error, Result, NixPath, AsExtStr, from_ffi};
+use {Error, Result, NixPath, from_ffi};
use errno::Errno;
use fcntl::Fd;
use libc::mode_t;
@@ -58,9 +58,9 @@ impl fmt::Debug for SFlag {
}
pub fn mknod<P: ?Sized + NixPath>(path: &P, kind: SFlag, perm: Mode, dev: dev_t) -> Result<()> {
- let res = try!(path.with_nix_path(|osstr| {
+ let res = try!(path.with_nix_path(|cstr| {
unsafe {
- ffi::mknod(osstr.as_ext_str(), kind.bits | perm.bits() as mode_t, dev)
+ ffi::mknod(cstr.as_ptr(), kind.bits | perm.bits() as mode_t, dev)
}
}));
from_ffi(res)
@@ -81,9 +81,9 @@ pub fn umask(mode: Mode) -> Mode {
pub fn stat<P: ?Sized + NixPath>(path: &P) -> Result<FileStat> {
let mut dst = unsafe { mem::uninitialized() };
- let res = try!(path.with_nix_path(|osstr| {
+ let res = try!(path.with_nix_path(|cstr| {
unsafe {
- ffi::stat(osstr.as_ext_str(), &mut dst as *mut FileStat)
+ ffi::stat(cstr.as_ptr(), &mut dst as *mut FileStat)
}
}));
@@ -96,9 +96,9 @@ pub fn stat<P: ?Sized + NixPath>(path: &P) -> Result<FileStat> {
pub fn lstat<P: ?Sized + NixPath>(path: &P) -> Result<FileStat> {
let mut dst = unsafe { mem::uninitialized() };
- let res = try!(path.with_nix_path(|osstr| {
+ let res = try!(path.with_nix_path(|cstr| {
unsafe {
- ffi::lstat(osstr.as_ext_str(), &mut dst as *mut FileStat)
+ ffi::lstat(cstr.as_ptr(), &mut dst as *mut FileStat)
}
}));