Skip to content

Commit

Permalink
Use origin's errno_location in the __errno_location implementation
Browse files Browse the repository at this point in the history
This will help with integrating the musl dynamic linker until a rust
replacement is written.

cc sunfishcode/origin#110
  • Loading branch information
bjorn3 committed Jun 24, 2024
1 parent 9b8afd4 commit d28a42f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions c-scape/src/errno_.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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]
Expand Down

0 comments on commit d28a42f

Please sign in to comment.