File tree Expand file tree Collapse file tree 1 file changed +10
-10
lines changed
library/std/src/sys/pal/unix Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -462,21 +462,21 @@ pub fn current_exe() -> io::Result<PathBuf> {
462462
463463#[ cfg( target_os = "haiku" ) ]
464464pub 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 }
You can’t perform that action at this time.
0 commit comments