@@ -5,8 +5,8 @@ use fcntl::{fcntl, OFlag, O_NONBLOCK, O_CLOEXEC, FD_CLOEXEC};
5
5
use fcntl:: FcntlArg :: { F_SETFD , F_SETFL } ;
6
6
use libc:: { self , c_char, c_void, c_int, c_uint, size_t, pid_t, off_t, uid_t, gid_t, mode_t} ;
7
7
use std:: mem;
8
- use std:: ffi:: { CString , CStr , OsString , OsStr } ;
9
- use std:: os:: unix:: ffi:: { OsStringExt , OsStrExt } ;
8
+ use std:: ffi:: { CString , CStr , OsString } ;
9
+ use std:: os:: unix:: ffi:: { OsStringExt } ;
10
10
use std:: os:: unix:: io:: RawFd ;
11
11
use std:: path:: { PathBuf } ;
12
12
use void:: Void ;
@@ -537,12 +537,11 @@ pub fn sleep(seconds: libc::c_uint) -> c_uint {
537
537
pub fn mkstemp < P : ?Sized + NixPath > ( template : & P ) -> Result < ( RawFd , PathBuf ) > {
538
538
let mut path = try!( template. with_nix_path ( |path| { path. to_bytes_with_nul ( ) . to_owned ( ) } ) ) ;
539
539
let p = path. as_mut_ptr ( ) as * mut _ ;
540
- unsafe {
541
- let fd = libc:: mkstemp ( p) ;
542
- let pathname = OsStr :: from_bytes ( CStr :: from_ptr ( p) . to_bytes ( ) ) ;
543
- try!( Errno :: result ( fd) ) ;
544
- Ok ( ( fd, PathBuf :: from ( pathname) . to_owned ( ) ) )
545
- }
540
+ let fd = unsafe { libc:: mkstemp ( p) } ;
541
+ path. pop ( ) ; // drop the trailing nul
542
+ let pathname = OsString :: from_vec ( path) ;
543
+ try!( Errno :: result ( fd) ) ;
544
+ Ok ( ( fd, PathBuf :: from ( pathname) ) )
546
545
}
547
546
548
547
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
0 commit comments