@@ -451,7 +451,7 @@ pub fn current_exe() -> io::Result<PathBuf> {
451451 super :: unsupported:: unsupported ( )
452452}
453453
454- #[ cfg( target_os = "fuchsia" ) ]
454+ #[ cfg( target_os = "fuchsia" , target_os = "aix" ) ]
455455pub fn current_exe ( ) -> io:: Result < PathBuf > {
456456 use crate :: io:: ErrorKind ;
457457
@@ -468,31 +468,19 @@ pub fn current_exe() -> io::Result<PathBuf> {
468468 let path = PathBuf :: from ( exe_path) ;
469469
470470 // 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+ }
483474
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) ;
489475 if path. is_absolute ( ) {
490476 return path. canonicalize ( ) ;
491477 }
478+
492479 // Search PWD to infer current_exe.
493480 if let Some ( pstr) = path. to_str ( ) && pstr. contains ( "/" ) {
494481 return getcwd ( ) . map ( |cwd| cwd. join ( path) ) ?. canonicalize ( ) ;
495482 }
483+
496484 // Search PATH to infer current_exe.
497485 if let Some ( p) = getenv ( OsStr :: from_bytes ( "PATH" . as_bytes ( ) ) ) {
498486 for search_path in split_paths ( & p) {
@@ -503,9 +491,8 @@ pub fn current_exe() -> io::Result<PathBuf> {
503491 }
504492 }
505493 }
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" ) ) ;
509496}
510497
511498pub struct Env {
0 commit comments