summaryrefslogtreecommitdiff
path: root/src/unistd.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/unistd.rs')
-rw-r--r--src/unistd.rs15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/unistd.rs b/src/unistd.rs
index 53ba3344..4d4e7529 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -5,8 +5,8 @@ use fcntl::{fcntl, OFlag, O_NONBLOCK, O_CLOEXEC, FD_CLOEXEC};
use fcntl::FcntlArg::{F_SETFD, F_SETFL};
use libc::{self, c_char, c_void, c_int, c_uint, size_t, pid_t, off_t, uid_t, gid_t, mode_t};
use std::mem;
-use std::ffi::{CString, CStr, OsString, OsStr};
-use std::os::unix::ffi::{OsStringExt, OsStrExt};
+use std::ffi::{CString, CStr, OsString};
+use std::os::unix::ffi::{OsStringExt};
use std::os::unix::io::RawFd;
use std::path::{PathBuf};
use void::Void;
@@ -537,12 +537,11 @@ pub fn sleep(seconds: libc::c_uint) -> c_uint {
pub fn mkstemp<P: ?Sized + NixPath>(template: &P) -> Result<(RawFd, PathBuf)> {
let mut path = try!(template.with_nix_path(|path| {path.to_bytes_with_nul().to_owned()}));
let p = path.as_mut_ptr() as *mut _;
- unsafe {
- let fd = libc::mkstemp(p);
- let pathname = OsStr::from_bytes(CStr::from_ptr(p).to_bytes());
- try!(Errno::result(fd));
- Ok((fd, PathBuf::from(pathname).to_owned()))
- }
+ let fd = unsafe { libc::mkstemp(p) };
+ path.pop(); // drop the trailing nul
+ let pathname = OsString::from_vec(path);
+ try!(Errno::result(fd));
+ Ok((fd, PathBuf::from(pathname)))
}
#[cfg(any(target_os = "linux", target_os = "android"))]