@@ -7,17 +7,6 @@ use crate::ffi::{CStr, OsStr, OsString};
7
7
use crate :: fmt;
8
8
use crate :: io:: { self , BorrowedCursor , Error , IoSlice , IoSliceMut , SeekFrom } ;
9
9
use 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 ;
21
10
use crate :: os:: unix:: io:: { AsFd , AsRawFd , BorrowedFd , FromRawFd , IntoRawFd } ;
22
11
use crate :: path:: { Path , PathBuf } ;
23
12
use crate :: ptr;
@@ -712,22 +701,10 @@ impl Iterator for ReadDir {
712
701
// requires the full extent of *entry_ptr to be in bounds of the same
713
702
// allocation, which is not necessarily the case here.
714
703
//
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.
720
705
macro_rules! offset_ptr {
721
706
( $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 ;
731
708
if true {
732
709
// Cast to the same type determined by the else branch.
733
710
$entry_ptr. byte_offset( OFFSET ) . cast:: <_>( )
0 commit comments