macos current_exe using directly libc instead.
This commit is contained in:
@@ -350,17 +350,14 @@ pub fn current_exe() -> io::Result<PathBuf> {
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||
pub fn current_exe() -> io::Result<PathBuf> {
|
||||
extern "C" {
|
||||
fn _NSGetExecutablePath(buf: *mut libc::c_char, bufsize: *mut u32) -> libc::c_int;
|
||||
}
|
||||
unsafe {
|
||||
let mut sz: u32 = 0;
|
||||
_NSGetExecutablePath(ptr::null_mut(), &mut sz);
|
||||
libc::_NSGetExecutablePath(ptr::null_mut(), &mut sz);
|
||||
if sz == 0 {
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
let mut v: Vec<u8> = Vec::with_capacity(sz as usize);
|
||||
let err = _NSGetExecutablePath(v.as_mut_ptr() as *mut i8, &mut sz);
|
||||
let err = libc::_NSGetExecutablePath(v.as_mut_ptr() as *mut i8, &mut sz);
|
||||
if err != 0 {
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user