about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Carlier <devnexen@gmail.com>2024-06-08 17:12:17 +0000
committerDavid Carlier <devnexen@gmail.com>2024-06-08 17:37:48 +0100
commit75607b7a5aed2c585df06c28e8473f503ffd6eb0 (patch)
tree53c5f3cebffca50e878c7501fde639933e642bd8
parent655600c5cba4d1e76fa0652c72258ec4996f48b8 (diff)
downloadrust-75607b7a5aed2c585df06c28e8473f503ffd6eb0.tar.gz
rust-75607b7a5aed2c585df06c28e8473f503ffd6eb0.zip
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.
-rw-r--r--library/std/src/sys/pal/unix/os.rs20
1 files changed, 10 insertions, 10 deletions
diff --git a/library/std/src/sys/pal/unix/os.rs b/library/std/src/sys/pal/unix/os.rs
index b5c7d30da7b..ae1e42c419b 100644
--- a/library/std/src/sys/pal/unix/os.rs
+++ b/library/std/src/sys/pal/unix/os.rs
@@ -462,21 +462,21 @@ pub fn current_exe() -> io::Result<PathBuf> {
 
 #[cfg(target_os = "haiku")]
 pub fn current_exe() -> io::Result<PathBuf> {
+    let mut name = vec![0; libc::PATH_MAX as usize];
     unsafe {
-        let mut info: mem::MaybeUninit<libc::image_info> = mem::MaybeUninit::uninit();
-        let mut cookie: i32 = 0;
-        // the executable can be found at team id 0
-        let result = libc::_get_next_image_info(
-            0,
-            &mut cookie,
-            info.as_mut_ptr(),
-            mem::size_of::<libc::image_info>(),
+        let result = libc::find_path(
+            std::ptr::null_mut(),
+            libc::path_base_directory::B_FIND_PATH_IMAGE_PATH,
+            std::ptr::null_mut(),
+            name.as_mut_ptr(),
+            name.len(),
         );
-        if result != 0 {
+        if result != libc::B_OK {
             use crate::io::ErrorKind;
             Err(io::const_io_error!(ErrorKind::Uncategorized, "Error getting executable path"))
         } else {
-            let name = CStr::from_ptr((*info.as_ptr()).name.as_ptr()).to_bytes();
+            // find_path adds the null terminator.
+            let name = CStr::from_ptr(name.as_ptr()).to_bytes();
             Ok(PathBuf::from(OsStr::from_bytes(name)))
         }
     }