uapi/errno/
mod.rs

1use crate::c;
2
3/// Gets a pointer to the current thread's errno
4pub fn errno_location() -> *mut c::c_int {
5    #[cfg(any(target_os = "dragonfly", target_os = "linux"))]
6    unsafe {
7        c::__errno_location()
8    }
9
10    #[cfg(any(target_os = "android", target_os = "netbsd", target_os = "openbsd"))]
11    unsafe {
12        c::__errno()
13    }
14
15    #[cfg(any(target_os = "freebsd", target_os = "ios", target_os = "macos"))]
16    unsafe {
17        c::__error()
18    }
19}
20
21/// Gets the current thread's errno
22pub fn get_errno() -> c::c_int {
23    unsafe { *errno_location() }
24}
25
26/// Sets the current thread's errno
27pub fn set_errno(val: c::c_int) {
28    unsafe { *errno_location() = val };
29}