@@ -7,17 +7,6 @@ use crate::ffi::{CStr, OsStr, OsString};
77use crate :: fmt;
88use crate :: io:: { self , BorrowedCursor , Error , IoSlice , IoSliceMut , SeekFrom } ;
99use crate :: mem;
10- #[ cfg( any(
11- target_os = "android" ,
12- target_os = "linux" ,
13- target_os = "solaris" ,
14- target_os = "fuchsia" ,
15- target_os = "redox" ,
16- target_os = "illumos" ,
17- target_os = "nto" ,
18- target_os = "vita" ,
19- ) ) ]
20- use crate :: mem:: MaybeUninit ;
2110use crate :: os:: unix:: io:: { AsFd , AsRawFd , BorrowedFd , FromRawFd , IntoRawFd } ;
2211use crate :: path:: { Path , PathBuf } ;
2312use crate :: ptr;
@@ -712,22 +701,10 @@ impl Iterator for ReadDir {
712701 // requires the full extent of *entry_ptr to be in bounds of the same
713702 // allocation, which is not necessarily the case here.
714703 //
715- // Absent any other way to obtain a pointer to `(*entry_ptr).d_name`
716- // legally in Rust analogously to how it would be done in C, we instead
717- // need to make our own non-libc allocation that conforms to the weird
718- // imaginary definition of dirent64, and use that for a field offset
719- // computation.
704+ // Instead we must access fields individually through their offsets.
720705 macro_rules! offset_ptr {
721706 ( $entry_ptr: expr, $field: ident) => { {
722- const OFFSET : isize = {
723- let delusion = MaybeUninit :: <dirent64>:: uninit( ) ;
724- let entry_ptr = delusion. as_ptr( ) ;
725- unsafe {
726- ptr:: addr_of!( ( * entry_ptr) . $field)
727- . cast:: <u8 >( )
728- . offset_from( entry_ptr. cast:: <u8 >( ) )
729- }
730- } ;
707+ const OFFSET : isize = mem:: offset_of!( dirent64, $field) as isize ;
731708 if true {
732709 // Cast to the same type determined by the else branch.
733710 $entry_ptr. byte_offset( OFFSET ) . cast:: <_>( )
0 commit comments