@@ -58,7 +58,7 @@ pub fn make_target_bin_path(sysroot: &Path, target_triple: &str) -> PathBuf {
5858 sysroot. join ( rustlib_path) . join ( "bin" )
5959}
6060
61- #[ cfg( all ( unix, not ( target_os = "cygwin" ) ) ) ]
61+ #[ cfg( unix) ]
6262fn current_dll_path ( ) -> Result < PathBuf , String > {
6363 use std:: sync:: OnceLock ;
6464
@@ -78,10 +78,16 @@ fn current_dll_path() -> Result<PathBuf, String> {
7878 if libc:: dladdr ( addr, & mut info) == 0 {
7979 return Err ( "dladdr failed" . into ( ) ) ;
8080 }
81- if info. dli_fname . is_null ( ) {
82- return Err ( "dladdr returned null pointer" . into ( ) ) ;
83- }
84- let bytes = CStr :: from_ptr ( info. dli_fname ) . to_bytes ( ) ;
81+ #[ cfg( target_os = "cygwin" ) ]
82+ let fname_ptr = info. dli_fname . as_ptr ( ) ;
83+ #[ cfg( not( target_os = "cygwin" ) ) ]
84+ let fname_ptr = {
85+ if info. dli_fname . is_null ( ) {
86+ return Err ( "dladdr returned null pointer" . into ( ) ) ;
87+ }
88+ info. dli_fname
89+ } ;
90+ let bytes = CStr :: from_ptr ( fname_ptr) . to_bytes ( ) ;
8591 let os = OsStr :: from_bytes ( bytes) ;
8692 Ok ( PathBuf :: from ( os) )
8793 }
@@ -132,23 +138,6 @@ fn current_dll_path() -> Result<PathBuf, String> {
132138 . clone ( )
133139}
134140
135- #[ cfg( target_os = "cygwin" ) ]
136- fn current_dll_path ( ) -> Result < PathBuf , String > {
137- use std:: ffi:: { CStr , OsStr } ;
138- use std:: os:: unix:: prelude:: * ;
139-
140- unsafe {
141- let addr = current_dll_path as usize as * mut _ ;
142- let mut info = std:: mem:: zeroed ( ) ;
143- if libc:: dladdr ( addr, & mut info) == 0 {
144- return Err ( "dladdr failed" . into ( ) ) ;
145- }
146- let bytes = CStr :: from_ptr ( info. dli_fname . as_ptr ( ) ) . to_bytes ( ) ;
147- let os = OsStr :: from_bytes ( bytes) ;
148- Ok ( PathBuf :: from ( os) )
149- }
150- }
151-
152141#[ cfg( windows) ]
153142fn current_dll_path ( ) -> Result < PathBuf , String > {
154143 use std:: ffi:: OsString ;
0 commit comments