diff --git a/c-scape/Cargo.toml b/c-scape/Cargo.toml index c7d29ae..cf525e8 100644 --- a/c-scape/Cargo.toml +++ b/c-scape/Cargo.toml @@ -64,7 +64,7 @@ static_assertions = "1.1.0" [features] default = ["thread", "std", "coexist-with-libc", "threadsafe-setenv", "use-compiler-builtins"] -thread = [] +thread = ["origin/unstable-errno"] std = ["rustix/std", "printf-compat/std"] # In "take-charge" mode, this enables code in c-scape to define the diff --git a/c-scape/src/errno_.rs b/c-scape/src/errno_.rs index f5fb970..d2d6ed7 100644 --- a/c-scape/src/errno_.rs +++ b/c-scape/src/errno_.rs @@ -1,7 +1,7 @@ use alloc::borrow::ToOwned; use alloc::format; use core::cell::SyncUnsafeCell; -use core::ptr::{addr_of_mut, copy_nonoverlapping, null_mut}; +use core::ptr::{copy_nonoverlapping, null_mut}; use libc::{c_char, c_int}; /// Return the address of the thread-local `errno` state. @@ -13,9 +13,14 @@ use libc::{c_char, c_int}; unsafe extern "C" fn __errno_location() -> *mut c_int { libc!(libc::__errno_location()); - #[cfg_attr(feature = "thread", thread_local)] - static mut ERRNO: i32 = 0; - addr_of_mut!(ERRNO) + #[cfg(feature = "thread")] + return origin::thread::errno_location(); + + #[cfg(not(feature = "thread"))] + { + static mut ERRNO: i32 = 0; + return core::ptr::addr_of_mut!(ERRNO); + } } #[no_mangle]