@@ -531,17 +531,17 @@ impl Drop for Dir {
531531
532532impl DirEntry {
533533 pub fn path ( & self ) -> PathBuf {
534- self . dir . root . join ( OsStr :: from_bytes ( self . name_bytes ( ) ) )
534+ self . dir . root . join ( self . file_name_os_str ( ) )
535535 }
536536
537537 pub fn file_name ( & self ) -> OsString {
538- OsStr :: from_bytes ( self . name_bytes ( ) ) . to_os_string ( )
538+ self . file_name_os_str ( ) . to_os_string ( )
539539 }
540540
541541 #[ cfg( any( target_os = "linux" , target_os = "emscripten" , target_os = "android" ) ) ]
542542 pub fn metadata ( & self ) -> io:: Result < FileAttr > {
543543 let fd = cvt ( unsafe { dirfd ( self . dir . dirp . 0 ) } ) ?;
544- let name = self . entry . d_name . as_ptr ( ) ;
544+ let name = self . name_cstr ( ) . as_ptr ( ) ;
545545
546546 cfg_has_statx ! {
547547 if let Some ( ret) = unsafe { try_statx(
@@ -639,26 +639,16 @@ impl DirEntry {
639639 )
640640 }
641641 }
642- #[ cfg( any(
643- target_os = "android" ,
644- target_os = "linux" ,
645- target_os = "emscripten" ,
646- target_os = "l4re" ,
647- target_os = "haiku" ,
648- target_os = "vxworks" ,
649- target_os = "espidf"
650- ) ) ]
651- fn name_bytes ( & self ) -> & [ u8 ] {
652- unsafe { CStr :: from_ptr ( self . entry . d_name . as_ptr ( ) ) . to_bytes ( ) }
653- }
654- #[ cfg( any(
655- target_os = "solaris" ,
656- target_os = "illumos" ,
657- target_os = "fuchsia" ,
658- target_os = "redox"
659- ) ) ]
642+ #[ cfg( not( any(
643+ target_os = "macos" ,
644+ target_os = "ios" ,
645+ target_os = "netbsd" ,
646+ target_os = "openbsd" ,
647+ target_os = "freebsd" ,
648+ target_os = "dragonfly"
649+ ) ) ) ]
660650 fn name_bytes ( & self ) -> & [ u8 ] {
661- self . name . as_bytes ( )
651+ self . name_cstr ( ) . to_bytes ( )
662652 }
663653
664654 #[ cfg( not( any(
@@ -670,7 +660,12 @@ impl DirEntry {
670660 fn name_cstr ( & self ) -> & CStr {
671661 unsafe { CStr :: from_ptr ( self . entry . d_name . as_ptr ( ) ) }
672662 }
673- #[ cfg( any( target_os = "solaris" , target_os = "illumos" , target_os = "fuchsia" ) ) ]
663+ #[ cfg( any(
664+ target_os = "solaris" ,
665+ target_os = "illumos" ,
666+ target_os = "fuchsia" ,
667+ target_os = "redox"
668+ ) ) ]
674669 fn name_cstr ( & self ) -> & CStr {
675670 & self . name
676671 }
0 commit comments