summaryrefslogtreecommitdiff
path: root/src/unistd.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/unistd.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/unistd.rs')
-rw-r--r--src/unistd.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/unistd.rs b/src/unistd.rs
index 1852721d..68447f5b 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -1,6 +1,6 @@
//! Standard symbolic constants and types
//!
-use {Error, Result, NixPath, AsExtStr, from_ffi};
+use {Error, Result, NixPath, from_ffi};
use errno::Errno;
use fcntl::{fcntl, Fd, OFlag, O_NONBLOCK, O_CLOEXEC, FD_CLOEXEC};
use fcntl::FcntlArg::{F_SETFD, F_SETFL};
@@ -144,8 +144,8 @@ fn dup3_polyfill(oldfd: Fd, newfd: Fd, flags: OFlag) -> Result<Fd> {
#[inline]
pub fn chdir<P: ?Sized + NixPath>(path: &P) -> Result<()> {
- let res = try!(path.with_nix_path(|osstr| {
- unsafe { ffi::chdir(osstr.as_ext_str()) }
+ let res = try!(path.with_nix_path(|cstr| {
+ unsafe { ffi::chdir(cstr.as_ptr()) }
}));
if res != 0 {
@@ -301,9 +301,9 @@ pub fn isatty(fd: Fd) -> Result<bool> {
}
pub fn unlink<P: ?Sized + NixPath>(path: &P) -> Result<()> {
- let res = try!(path.with_nix_path(|osstr| {
+ let res = try!(path.with_nix_path(|cstr| {
unsafe {
- ffi::unlink(osstr.as_ext_str())
+ ffi::unlink(cstr.as_ptr())
}
}));
from_ffi(res)
@@ -311,8 +311,8 @@ pub fn unlink<P: ?Sized + NixPath>(path: &P) -> Result<()> {
#[inline]
pub fn chroot<P: ?Sized + NixPath>(path: &P) -> Result<()> {
- let res = try!(path.with_nix_path(|osstr| {
- unsafe { ffi::chroot(osstr.as_ext_str()) }
+ let res = try!(path.with_nix_path(|cstr| {
+ unsafe { ffi::chroot(cstr.as_ptr()) }
}));
if res != 0 {
@@ -336,7 +336,7 @@ mod linux {
let res = try!(try!(new_root.with_nix_path(|new_root| {
put_old.with_nix_path(|put_old| {
unsafe {
- syscall(SYSPIVOTROOT, new_root, put_old)
+ syscall(SYSPIVOTROOT, new_root.as_ptr(), put_old.as_ptr())
}
})
})));