1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use crate::c;

/// Gets a pointer to the current thread's errno
pub fn errno_location() -> *mut c::c_int {
    #[cfg(any(target_os = "dragonfly", target_os = "linux"))]
    unsafe {
        c::__errno_location()
    }

    #[cfg(any(target_os = "android", target_os = "netbsd", target_os = "openbsd"))]
    unsafe {
        c::__errno()
    }

    #[cfg(any(target_os = "freebsd", target_os = "ios", target_os = "macos"))]
    unsafe {
        c::__error()
    }
}

/// Gets the current thread's errno
pub fn get_errno() -> c::c_int {
    unsafe { *errno_location() }
}

/// Sets the current thread's errno
pub fn set_errno(val: c::c_int) {
    unsafe { *errno_location() = val };
}