os current_exe using same approach as linux to get always the full absolute path

but in case of failure (e.g. prcfs not mounted) still using
getexecname.
This commit is contained in:
David Carlier 2021-07-30 17:28:44 +01:00
parent b289bb7fdf
commit cb4519e59c

View File

@ -368,6 +368,9 @@ pub fn current_exe() -> io::Result<PathBuf> {
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
pub fn current_exe() -> io::Result<PathBuf> {
if let Ok(path) = crate::fs::read_link("/proc/self/path/a.out") {
Ok(path)
} else {
extern "C" {
fn getexecname() -> *const c_char;
}
@ -384,6 +387,7 @@ pub fn current_exe() -> io::Result<PathBuf> {
if filename[0] == b'/' { Ok(path) } else { getcwd().map(|cwd| cwd.join(path)) }
}
}
}
}
#[cfg(target_os = "haiku")]