diff options
| author | bors <bors@rust-lang.org> | 2021-08-07 12:44:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-08-07 12:44:09 +0000 |
| commit | 508b328c398b84126011f6fe74d018fe855bc242 (patch) | |
| tree | 6b1c1e475fbbda9e5bdf59d2de3339fb36b12caf /library/std/src/sys | |
| parent | 6b20506d17f4e5e5bf5bcad7e94add4d754b0ae3 (diff) | |
| parent | 5501eba6452d5877b3c45aabadb105d3daa71b4b (diff) | |
| download | rust-508b328c398b84126011f6fe74d018fe855bc242.tar.gz rust-508b328c398b84126011f6fe74d018fe855bc242.zip | |
Auto merge of #87810 - devnexen:haiku_os_simpl, r=Mark-Simulacrum
current_exe haiku code path simplification all of these part of libc
Diffstat (limited to 'library/std/src/sys')
| -rw-r--r-- | library/std/src/sys/unix/os.rs | 41 |
1 files changed, 8 insertions, 33 deletions
diff --git a/library/std/src/sys/unix/os.rs b/library/std/src/sys/unix/os.rs index dfbd93c90e6..bbfe846e315 100644 --- a/library/std/src/sys/unix/os.rs +++ b/library/std/src/sys/unix/os.rs @@ -388,46 +388,21 @@ pub fn current_exe() -> io::Result<PathBuf> { #[cfg(target_os = "haiku")] pub fn current_exe() -> io::Result<PathBuf> { - // Use Haiku's image info functions - #[repr(C)] - struct image_info { - id: i32, - type_: i32, - sequence: i32, - init_order: i32, - init_routine: *mut libc::c_void, // function pointer - term_routine: *mut libc::c_void, // function pointer - device: libc::dev_t, - node: libc::ino_t, - name: [libc::c_char; 1024], // MAXPATHLEN - text: *mut libc::c_void, - data: *mut libc::c_void, - text_size: i32, - data_size: i32, - api_version: i32, - abi: i32, - } - unsafe { - extern "C" { - fn _get_next_image_info( - team_id: i32, - cookie: *mut i32, - info: *mut image_info, - size: i32, - ) -> i32; - } - - let mut info: image_info = mem::zeroed(); + 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 = - _get_next_image_info(0, &mut cookie, &mut info, mem::size_of::<image_info>() as i32); + let result = libc::_get_next_image_info( + 0, + &mut cookie, + info.as_mut_ptr(), + mem::size_of::<libc::image_info>(), + ); if result != 0 { use crate::io::ErrorKind; Err(io::Error::new_const(ErrorKind::Uncategorized, &"Error getting executable path")) } else { - let name = CStr::from_ptr(info.name.as_ptr()).to_bytes(); + let name = CStr::from_ptr((*info.as_ptr()).name.as_ptr()).to_bytes(); Ok(PathBuf::from(OsStr::from_bytes(name))) } } |
