Skip to content

Commit 0fb0122

Browse files
authored
Rollup merge of #87631 - :solarish_upd_fs, r=joshtriplett
os current_exe using same approach as linux to get always the full ab… …solute path
2 parents a804c4b + cb4519e commit 0fb0122

File tree

1 file changed

+17
-13
lines changed
  • library/std/src/sys/unix

1 file changed

+17
-13
lines changed

library/std/src/sys/unix/os.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -380,20 +380,24 @@ pub fn current_exe() -> io::Result<PathBuf> {
380380

381381
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
382382
pub fn current_exe() -> io::Result<PathBuf> {
383-
extern "C" {
384-
fn getexecname() -> *const c_char;
385-
}
386-
unsafe {
387-
let path = getexecname();
388-
if path.is_null() {
389-
Err(io::Error::last_os_error())
390-
} else {
391-
let filename = CStr::from_ptr(path).to_bytes();
392-
let path = PathBuf::from(<OsStr as OsStrExt>::from_bytes(filename));
383+
if let Ok(path) = crate::fs::read_link("/proc/self/path/a.out") {
384+
Ok(path)
385+
} else {
386+
extern "C" {
387+
fn getexecname() -> *const c_char;
388+
}
389+
unsafe {
390+
let path = getexecname();
391+
if path.is_null() {
392+
Err(io::Error::last_os_error())
393+
} else {
394+
let filename = CStr::from_ptr(path).to_bytes();
395+
let path = PathBuf::from(<OsStr as OsStrExt>::from_bytes(filename));
393396

394-
// Prepend a current working directory to the path if
395-
// it doesn't contain an absolute pathname.
396-
if filename[0] == b'/' { Ok(path) } else { getcwd().map(|cwd| cwd.join(path)) }
397+
// Prepend a current working directory to the path if
398+
// it doesn't contain an absolute pathname.
399+
if filename[0] == b'/' { Ok(path) } else { getcwd().map(|cwd| cwd.join(path)) }
400+
}
397401
}
398402
}
399403
}

0 commit comments

Comments
 (0)