| 1 |
cfg_if! { |
| 2 |
if #[cfg(any(target_os = "netbsd", target_os = "openbsd", target_os = "android", target_os = "cygwin"))] { |
| 3 |
use libc::__errno as errno_location; |
| 4 |
} else if #[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "hurd", target_os = "redox", target_os = "dragonfly"))] { |
| 5 |
use libc::__errno_location as errno_location; |
| 6 |
} else if #[cfg(target_os = "illumos")] { |
| 7 |
use libc::___errno as errno_location; |
| 8 |
} else if #[cfg(any(target_os = "macos", target_os = "freebsd"))] { |
| 9 |
use libc::__error as errno_location; |
| 10 |
} else if #[cfg(target_os = "haiku")] { |
| 11 |
use libc::_errnop as errno_location; |
| 12 |
} else if #[cfg(target_os = "nto")] { |
| 13 |
use libc::__get_errno_ptr as errno_location; |
| 14 |
} else if #[cfg(any(all(target_os = "horizon", target_arch = "arm"), target_os = "vita"))] { |
| 15 |
unsafe extern "C" { |
| 16 |
// Not provided by libc: https://github.com/rust-lang/libc/issues/1995 |
| 17 |
fn __errno() -> *mut libc::c_int; |
| 18 |
} |
| 19 |
use __errno as errno_location; |
| 20 |
} else if #[cfg(target_os = "aix")] { |
| 21 |
use libc::_Errno as errno_location; |
| 22 |
} else { |
| 23 |
compile_error!("errno_location is not provided for the target"); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
pub(crate) fn get_errno() -> libc::c_int { |
| 28 |
unsafe { core::ptr::read(errno_location()) } |
| 29 |
} |