@@ -531,17 +531,17 @@ impl Drop for Dir {
531
531
532
532
impl DirEntry {
533
533
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 ( ) )
535
535
}
536
536
537
537
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 ( )
539
539
}
540
540
541
541
#[ cfg( any( target_os = "linux" , target_os = "emscripten" , target_os = "android" ) ) ]
542
542
pub fn metadata ( & self ) -> io:: Result < FileAttr > {
543
543
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 ( ) ;
545
545
546
546
cfg_has_statx ! {
547
547
if let Some ( ret) = unsafe { try_statx(
@@ -639,26 +639,16 @@ impl DirEntry {
639
639
)
640
640
}
641
641
}
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
+ ) ) ) ]
660
650
fn name_bytes ( & self ) -> & [ u8 ] {
661
- self . name . as_bytes ( )
651
+ self . name_cstr ( ) . to_bytes ( )
662
652
}
663
653
664
654
#[ cfg( not( any(
@@ -670,7 +660,12 @@ impl DirEntry {
670
660
fn name_cstr ( & self ) -> & CStr {
671
661
unsafe { CStr :: from_ptr ( self . entry . d_name . as_ptr ( ) ) }
672
662
}
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
+ ) ) ]
674
669
fn name_cstr ( & self ) -> & CStr {
675
670
& self . name
676
671
}
0 commit comments