File tree 1 file changed +17
-13
lines changed
1 file changed +17
-13
lines changed Original file line number Diff line number Diff line change @@ -368,20 +368,24 @@ pub fn current_exe() -> io::Result<PathBuf> {
368
368
369
369
#[ cfg( any( target_os = "solaris" , target_os = "illumos" ) ) ]
370
370
pub fn current_exe ( ) -> io:: Result < PathBuf > {
371
- extern "C" {
372
- fn getexecname ( ) -> * const c_char ;
373
- }
374
- unsafe {
375
- let path = getexecname ( ) ;
376
- if path. is_null ( ) {
377
- Err ( io:: Error :: last_os_error ( ) )
378
- } else {
379
- let filename = CStr :: from_ptr ( path) . to_bytes ( ) ;
380
- let path = PathBuf :: from ( <OsStr as OsStrExt >:: from_bytes ( filename) ) ;
371
+ if let Ok ( path) = crate :: fs:: read_link ( "/proc/self/path/a.out" ) {
372
+ Ok ( path)
373
+ } else {
374
+ extern "C" {
375
+ fn getexecname ( ) -> * const c_char ;
376
+ }
377
+ unsafe {
378
+ let path = getexecname ( ) ;
379
+ if path. is_null ( ) {
380
+ Err ( io:: Error :: last_os_error ( ) )
381
+ } else {
382
+ let filename = CStr :: from_ptr ( path) . to_bytes ( ) ;
383
+ let path = PathBuf :: from ( <OsStr as OsStrExt >:: from_bytes ( filename) ) ;
381
384
382
- // Prepend a current working directory to the path if
383
- // it doesn't contain an absolute pathname.
384
- if filename[ 0 ] == b'/' { Ok ( path) } else { getcwd ( ) . map ( |cwd| cwd. join ( path) ) }
385
+ // Prepend a current working directory to the path if
386
+ // it doesn't contain an absolute pathname.
387
+ if filename[ 0 ] == b'/' { Ok ( path) } else { getcwd ( ) . map ( |cwd| cwd. join ( path) ) }
388
+ }
385
389
}
386
390
}
387
391
}
You can’t perform that action at this time.
0 commit comments