File tree Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -66,8 +66,7 @@ pub use imp::{
6666} ;
6767
6868pub fn read_dir ( path : & Path ) -> io:: Result < ReadDir > {
69- // FIXME: use with_native_path on all platforms
70- imp:: readdir ( path)
69+ with_native_path ( path, & imp:: readdir)
7170}
7271
7372pub fn remove_file ( path : & Path ) -> io:: Result < ( ) > {
Original file line number Diff line number Diff line change @@ -1182,11 +1182,23 @@ impl DirBuilder {
11821182 }
11831183}
11841184
1185- pub fn readdir ( p : & Path ) -> io:: Result < ReadDir > {
1185+ pub fn readdir ( p : & WCStr ) -> io:: Result < ReadDir > {
1186+ let mut p = unsafe { p. to_wchars_with_null_unchecked ( ) } . to_vec ( ) ;
1187+
1188+ // `p` already contains NUL, because before reading directory function,
1189+ // it already passes `maybe_verbatim` that appending zero at the end, it
1190+ // should be refactored.
1191+ if let Some ( pos) = p. iter ( ) . position ( |x| * x == 0 ) {
1192+ p. remove ( pos) ;
1193+ }
1194+
1195+ let p_os_string = OsString :: from_wide ( & p) ;
1196+ let p = Path :: new ( & p_os_string) ;
1197+
11861198 // We push a `*` to the end of the path which cause the empty path to be
11871199 // treated as the current directory. So, for consistency with other platforms,
11881200 // we explicitly error on the empty path.
1189- if p . as_os_str ( ) . is_empty ( ) {
1201+ if p_os_string . is_empty ( ) {
11901202 // Return an error code consistent with other ways of opening files.
11911203 // E.g. fs::metadata or File::open.
11921204 return Err ( io:: Error :: from_raw_os_error ( c:: ERROR_PATH_NOT_FOUND as i32 ) ) ;
Original file line number Diff line number Diff line change 1+ use crate :: alloc_crate:: slice;
12use crate :: ffi:: { OsStr , OsString } ;
23use crate :: path:: { Path , PathBuf } ;
34use crate :: sys:: api:: utf16;
@@ -29,6 +30,10 @@ impl WCStr {
2930 unsafe { & * ( s as * const [ u16 ] as * const Self ) }
3031 }
3132
33+ pub unsafe fn to_wchars_with_null_unchecked ( & self ) -> & [ u16 ] {
34+ unsafe { slice:: from_raw_parts ( self . as_ptr ( ) , self . 0 . len ( ) ) }
35+ }
36+
3237 pub fn as_ptr ( & self ) -> * const u16 {
3338 self . 0 . as_ptr ( )
3439 }
You can’t perform that action at this time.
0 commit comments