Skip to content

Commit 56bdaf3

Browse files
committed
std::unix::os current_exe implementation simplification for haiku.
_get_net_image_info is a bit overkill as it allows to get broader informations about the process.
1 parent 67454f5 commit 56bdaf3

File tree

1 file changed

+10
-10
lines changed
  • std/src/sys/pal/unix

1 file changed

+10
-10
lines changed

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -462,21 +462,21 @@ pub fn current_exe() -> io::Result<PathBuf> {
462462

463463
#[cfg(target_os = "haiku")]
464464
pub fn current_exe() -> io::Result<PathBuf> {
465+
let mut name = vec![0; libc::PATH_MAX as usize];
465466
unsafe {
466-
let mut info: mem::MaybeUninit<libc::image_info> = mem::MaybeUninit::uninit();
467-
let mut cookie: i32 = 0;
468-
// the executable can be found at team id 0
469-
let result = libc::_get_next_image_info(
470-
0,
471-
&mut cookie,
472-
info.as_mut_ptr(),
473-
mem::size_of::<libc::image_info>(),
467+
let result = libc::find_path(
468+
std::ptr::null_mut(),
469+
libc::path_base_directory::B_FIND_PATH_IMAGE_PATH,
470+
std::ptr::null_mut(),
471+
name.as_mut_ptr(),
472+
name.len(),
474473
);
475-
if result != 0 {
474+
if result != libc::B_OK {
476475
use crate::io::ErrorKind;
477476
Err(io::const_io_error!(ErrorKind::Uncategorized, "Error getting executable path"))
478477
} else {
479-
let name = CStr::from_ptr((*info.as_ptr()).name.as_ptr()).to_bytes();
478+
// find_path adds the null terminator.
479+
let name = CStr::from_ptr(name.as_ptr()).to_bytes();
480480
Ok(PathBuf::from(OsStr::from_bytes(name)))
481481
}
482482
}

0 commit comments

Comments
 (0)