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;
78
78
*
79
79
*/
80
80
81
- use libc:: { c_char , PATH_MAX } ;
81
+ use libc:: PATH_MAX ;
82
82
83
- use std:: { ptr , result} ;
83
+ use std:: result;
84
84
use std:: ffi:: { CStr , OsStr } ;
85
85
use std:: os:: unix:: ffi:: OsStrExt ;
86
86
use std:: path:: { Path , PathBuf } ;
@@ -184,16 +184,10 @@ impl NixPath for [u8] {
184
184
return Err ( Errno :: ENAMETOOLONG )
185
185
}
186
186
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 ) ,
197
191
}
198
192
}
199
193
}
You can’t perform that action at this time.
0 commit comments