File tree Expand file tree Collapse file tree 1 file changed +6
-12
lines changed Expand file tree Collapse file tree 1 file changed +6
-12
lines changed Original file line number Diff line number Diff line change @@ -78,9 +78,9 @@ pub mod unistd;
7878 *
7979 */
8080
81- use libc:: { c_char , PATH_MAX } ;
81+ use libc:: PATH_MAX ;
8282
83- use std:: { ptr , result} ;
83+ use std:: result;
8484use std:: ffi:: { CStr , OsStr } ;
8585use std:: os:: unix:: ffi:: OsStrExt ;
8686use std:: path:: { Path , PathBuf } ;
@@ -184,16 +184,10 @@ impl NixPath for [u8] {
184184 return Err ( Errno :: ENAMETOOLONG )
185185 }
186186
187- match self . iter ( ) . position ( |b| * b == 0 ) {
188- Some ( _) => Err ( Errno :: EINVAL ) ,
189- None => {
190- unsafe {
191- // TODO: Replace with bytes::copy_memory. rust-lang/rust#24028
192- ptr:: copy_nonoverlapping ( self . as_ptr ( ) , buf. as_mut_ptr ( ) , self . len ( ) ) ;
193- Ok ( f ( CStr :: from_ptr ( buf. as_ptr ( ) as * const c_char ) ) )
194- }
195-
196- }
187+ buf[ ..self . len ( ) ] . copy_from_slice ( self ) ;
188+ match CStr :: from_bytes_with_nul ( & buf[ ..=self . len ( ) ] ) {
189+ Ok ( s) => Ok ( f ( s) ) ,
190+ Err ( _) => Err ( Errno :: EINVAL ) ,
197191 }
198192 }
199193}
You can’t perform that action at this time.
0 commit comments