@@ -451,7 +451,7 @@ pub fn current_exe() -> io::Result<PathBuf> {
451
451
super :: unsupported:: unsupported ( )
452
452
}
453
453
454
- #[ cfg( target_os = "fuchsia" ) ]
454
+ #[ cfg( target_os = "fuchsia" , target_os = "aix" ) ]
455
455
pub fn current_exe ( ) -> io:: Result < PathBuf > {
456
456
use crate :: io:: ErrorKind ;
457
457
@@ -468,31 +468,19 @@ pub fn current_exe() -> io::Result<PathBuf> {
468
468
let path = PathBuf :: from ( exe_path) ;
469
469
470
470
// Prepend the current working directory to the path if it's not absolute.
471
- if !path. is_absolute ( ) { getcwd ( ) . map ( |cwd| cwd. join ( path) ) } else { Ok ( path) }
472
- }
473
-
474
- #[ cfg( target_os = "aix" ) ]
475
- pub fn current_exe ( ) -> io:: Result < PathBuf > {
476
- use crate :: io:: ErrorKind ;
477
-
478
- #[ cfg( test) ]
479
- use realstd:: env;
480
-
481
- #[ cfg( not( test) ) ]
482
- use crate :: env;
471
+ if cfg ! ( target_os = "fuchsia" ) {
472
+ if !path. is_absolute ( ) { getcwd ( ) . map ( |cwd| cwd. join ( path) ) } else { Ok ( path) }
473
+ }
483
474
484
- let exe_path = env:: args ( ) . next ( ) . ok_or ( io:: const_io_error!(
485
- ErrorKind :: Uncategorized ,
486
- "an executable path was not found because no arguments were provided through argv"
487
- ) ) ?;
488
- let path = PathBuf :: from ( exe_path) ;
489
475
if path. is_absolute ( ) {
490
476
return path. canonicalize ( ) ;
491
477
}
478
+
492
479
// Search PWD to infer current_exe.
493
480
if let Some ( pstr) = path. to_str ( ) && pstr. contains ( "/" ) {
494
481
return getcwd ( ) . map ( |cwd| cwd. join ( path) ) ?. canonicalize ( ) ;
495
482
}
483
+
496
484
// Search PATH to infer current_exe.
497
485
if let Some ( p) = getenv ( OsStr :: from_bytes ( "PATH" . as_bytes ( ) ) ) {
498
486
for search_path in split_paths ( & p) {
@@ -503,9 +491,8 @@ pub fn current_exe() -> io::Result<PathBuf> {
503
491
}
504
492
}
505
493
}
506
- return Err ( io:: const_io_error!(
507
- ErrorKind :: Uncategorized ,
508
- "an executable path was not found" ) ) ;
494
+
495
+ return Err ( io:: const_io_error!( ErrorKind :: Uncategorized , "an executable path was not found" ) ) ;
509
496
}
510
497
511
498
pub struct Env {
0 commit comments