@@ -2010,56 +2010,10 @@ mod remove_dir_impl {
20102010 use crate :: sys:: common:: small_c_string:: run_path_with_cstr;
20112011 use crate :: sys:: { cvt, cvt_r} ;
20122012
2013- #[ cfg( not( any(
2014- all( target_os = "linux" , target_env = "gnu" ) ,
2015- all( target_os = "macos" , not( target_arch = "aarch64" ) )
2016- ) ) ) ]
2013+ #[ cfg( not( all( target_os = "linux" , target_env = "gnu" ) ) ) ]
20172014 use libc:: { fdopendir, openat, unlinkat} ;
20182015 #[ cfg( all( target_os = "linux" , target_env = "gnu" ) ) ]
20192016 use libc:: { fdopendir, openat64 as openat, unlinkat} ;
2020- #[ cfg( all( target_os = "macos" , not( target_arch = "aarch64" ) ) ) ]
2021- use macos_weak:: { fdopendir, openat, unlinkat} ;
2022-
2023- #[ cfg( all( target_os = "macos" , not( target_arch = "aarch64" ) ) ) ]
2024- mod macos_weak {
2025- use crate :: sys:: weak:: weak;
2026- use libc:: { c_char, c_int, DIR } ;
2027-
2028- fn get_openat_fn ( ) -> Option < unsafe extern "C" fn ( c_int , * const c_char , c_int ) -> c_int > {
2029- weak ! ( fn openat( c_int, * const c_char, c_int) -> c_int) ;
2030- openat. get ( )
2031- }
2032-
2033- pub fn has_openat ( ) -> bool {
2034- get_openat_fn ( ) . is_some ( )
2035- }
2036-
2037- pub unsafe fn openat ( dirfd : c_int , pathname : * const c_char , flags : c_int ) -> c_int {
2038- get_openat_fn ( ) . map ( |openat| openat ( dirfd, pathname, flags) ) . unwrap_or_else ( || {
2039- crate :: sys:: pal:: unix:: os:: set_errno ( libc:: ENOSYS ) ;
2040- -1
2041- } )
2042- }
2043-
2044- pub unsafe fn fdopendir ( fd : c_int ) -> * mut DIR {
2045- #[ cfg( all( target_os = "macos" , target_arch = "x86" ) ) ]
2046- weak ! ( fn fdopendir( c_int) -> * mut DIR , "fdopendir$INODE64$UNIX2003" ) ;
2047- #[ cfg( all( target_os = "macos" , target_arch = "x86_64" ) ) ]
2048- weak ! ( fn fdopendir( c_int) -> * mut DIR , "fdopendir$INODE64" ) ;
2049- fdopendir. get ( ) . map ( |fdopendir| fdopendir ( fd) ) . unwrap_or_else ( || {
2050- crate :: sys:: pal:: unix:: os:: set_errno ( libc:: ENOSYS ) ;
2051- crate :: ptr:: null_mut ( )
2052- } )
2053- }
2054-
2055- pub unsafe fn unlinkat ( dirfd : c_int , pathname : * const c_char , flags : c_int ) -> c_int {
2056- weak ! ( fn unlinkat( c_int, * const c_char, c_int) -> c_int) ;
2057- unlinkat. get ( ) . map ( |unlinkat| unlinkat ( dirfd, pathname, flags) ) . unwrap_or_else ( || {
2058- crate :: sys:: pal:: unix:: os:: set_errno ( libc:: ENOSYS ) ;
2059- -1
2060- } )
2061- }
2062- }
20632017
20642018 pub fn openat_nofollow_dironly ( parent_fd : Option < RawFd > , p : & CStr ) -> io:: Result < OwnedFd > {
20652019 let fd = cvt_r ( || unsafe {
@@ -2172,19 +2126,7 @@ mod remove_dir_impl {
21722126 }
21732127 }
21742128
2175- #[ cfg( not( all( target_os = "macos" , not( target_arch = "aarch64" ) ) ) ) ]
21762129 pub fn remove_dir_all ( p : & Path ) -> io:: Result < ( ) > {
21772130 remove_dir_all_modern ( p)
21782131 }
2179-
2180- #[ cfg( all( target_os = "macos" , not( target_arch = "aarch64" ) ) ) ]
2181- pub fn remove_dir_all ( p : & Path ) -> io:: Result < ( ) > {
2182- if macos_weak:: has_openat ( ) {
2183- // openat() is available with macOS 10.10+, just like unlinkat() and fdopendir()
2184- remove_dir_all_modern ( p)
2185- } else {
2186- // fall back to classic implementation
2187- crate :: sys_common:: fs:: remove_dir_all ( p)
2188- }
2189- }
21902132}
0 commit comments