@@ -388,46 +388,21 @@ pub fn current_exe() -> io::Result<PathBuf> {
388388
389389#[ cfg( target_os = "haiku" ) ]
390390pub fn current_exe ( ) -> io:: Result < PathBuf > {
391- // Use Haiku's image info functions
392- #[ repr( C ) ]
393- struct image_info {
394- id : i32 ,
395- type_ : i32 ,
396- sequence : i32 ,
397- init_order : i32 ,
398- init_routine : * mut libc:: c_void , // function pointer
399- term_routine : * mut libc:: c_void , // function pointer
400- device : libc:: dev_t ,
401- node : libc:: ino_t ,
402- name : [ libc:: c_char ; 1024 ] , // MAXPATHLEN
403- text : * mut libc:: c_void ,
404- data : * mut libc:: c_void ,
405- text_size : i32 ,
406- data_size : i32 ,
407- api_version : i32 ,
408- abi : i32 ,
409- }
410-
411391 unsafe {
412- extern "C" {
413- fn _get_next_image_info (
414- team_id : i32 ,
415- cookie : * mut i32 ,
416- info : * mut image_info ,
417- size : i32 ,
418- ) -> i32 ;
419- }
420-
421- let mut info: image_info = mem:: zeroed ( ) ;
392+ let mut info: mem:: MaybeUninit < libc:: image_info > = mem:: MaybeUninit :: uninit ( ) ;
422393 let mut cookie: i32 = 0 ;
423394 // the executable can be found at team id 0
424- let result =
425- _get_next_image_info ( 0 , & mut cookie, & mut info, mem:: size_of :: < image_info > ( ) as i32 ) ;
395+ let result = libc:: _get_next_image_info (
396+ 0 ,
397+ & mut cookie,
398+ info. as_mut_ptr ( ) ,
399+ mem:: size_of :: < libc:: image_info > ( ) ,
400+ ) ;
426401 if result != 0 {
427402 use crate :: io:: ErrorKind ;
428403 Err ( io:: Error :: new_const ( ErrorKind :: Uncategorized , & "Error getting executable path" ) )
429404 } else {
430- let name = CStr :: from_ptr ( info. name . as_ptr ( ) ) . to_bytes ( ) ;
405+ let name = CStr :: from_ptr ( ( * info. as_ptr ( ) ) . name . as_ptr ( ) ) . to_bytes ( ) ;
431406 Ok ( PathBuf :: from ( OsStr :: from_bytes ( name) ) )
432407 }
433408 }
0 commit comments