From 21fb1394a111d19079da90a4d31171b0d6adc27c Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 21 May 2015 16:38:54 -0700 Subject: 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 --- src/unistd.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/unistd.rs') 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 { #[inline] pub fn chdir(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 { } pub fn unlink(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(path: &P) -> Result<()> { #[inline] pub fn chroot(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()) } }) }))); -- cgit v1.2.3