Rollup merge of #126168 - devnexen:current_exe_haiku_simpl, r=ChrisDe… · model-checking/verify-rust-std@818933d (original) (raw)
`@@ -462,21 +462,21 @@ pub fn current_exe() -> io::Result {
`
462
462
``
463
463
`#[cfg(target_os = "haiku")]
`
464
464
`pub fn current_exe() -> io::Result {
`
``
465
`+
let mut name = vec![0; libc::PATH_MAX as usize];
`
465
466
`unsafe {
`
466
``
`-
let mut info: mem::MaybeUninitlibc::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(),
`
474
473
`);
`
475
``
`-
if result != 0 {
`
``
474
`+
if result != libc::B_OK {
`
476
475
`use crate::io::ErrorKind;
`
477
476
`Err(io::const_io_error!(ErrorKind::Uncategorized, "Error getting executable path"))
`
478
477
`} 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();
`
480
480
`Ok(PathBuf::from(OsStr::from_bytes(name)))
`
481
481
`}
`
482
482
`}
`