@@ -58,7 +58,7 @@ pub fn make_target_bin_path(sysroot: &Path, target_triple: &str) -> PathBuf {
58
58
sysroot. join ( rustlib_path) . join ( "bin" )
59
59
}
60
60
61
- #[ cfg( all ( unix, not ( target_os = "cygwin" ) ) ) ]
61
+ #[ cfg( unix) ]
62
62
fn current_dll_path ( ) -> Result < PathBuf , String > {
63
63
use std:: sync:: OnceLock ;
64
64
@@ -78,10 +78,16 @@ fn current_dll_path() -> Result<PathBuf, String> {
78
78
if libc:: dladdr ( addr, & mut info) == 0 {
79
79
return Err ( "dladdr failed" . into ( ) ) ;
80
80
}
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 ( ) ;
85
91
let os = OsStr :: from_bytes ( bytes) ;
86
92
Ok ( PathBuf :: from ( os) )
87
93
}
@@ -132,23 +138,6 @@ fn current_dll_path() -> Result<PathBuf, String> {
132
138
. clone ( )
133
139
}
134
140
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
-
152
141
#[ cfg( windows) ]
153
142
fn current_dll_path ( ) -> Result < PathBuf , String > {
154
143
use std:: ffi:: OsString ;
0 commit comments