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.
This commit is contained in:
parent
655600c5cb
commit
75607b7a5a
@ -462,21 +462,21 @@ pub fn current_exe() -> io::Result<PathBuf> {
|
|||||||
|
|
||||||
#[cfg(target_os = "haiku")]
|
#[cfg(target_os = "haiku")]
|
||||||
pub fn current_exe() -> io::Result<PathBuf> {
|
pub fn current_exe() -> io::Result<PathBuf> {
|
||||||
|
let mut name = vec![0; libc::PATH_MAX as usize];
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut info: mem::MaybeUninit<libc::image_info> = mem::MaybeUninit::uninit();
|
let result = libc::find_path(
|
||||||
let mut cookie: i32 = 0;
|
std::ptr::null_mut(),
|
||||||
// the executable can be found at team id 0
|
libc::path_base_directory::B_FIND_PATH_IMAGE_PATH,
|
||||||
let result = libc::_get_next_image_info(
|
std::ptr::null_mut(),
|
||||||
0,
|
name.as_mut_ptr(),
|
||||||
&mut cookie,
|
name.len(),
|
||||||
info.as_mut_ptr(),
|
|
||||||
mem::size_of::<libc::image_info>(),
|
|
||||||
);
|
);
|
||||||
if result != 0 {
|
if result != libc::B_OK {
|
||||||
use crate::io::ErrorKind;
|
use crate::io::ErrorKind;
|
||||||
Err(io::const_io_error!(ErrorKind::Uncategorized, "Error getting executable path"))
|
Err(io::const_io_error!(ErrorKind::Uncategorized, "Error getting executable path"))
|
||||||
} else {
|
} 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)))
|
Ok(PathBuf::from(OsStr::from_bytes(name)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user