Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
//! println!("Error {}: {}", code, e);
//! ```

#![cfg_attr(target_os = "wasi", feature(thread_local))]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg_attr(unix, path = "unix.rs")]
Expand Down
11 changes: 3 additions & 8 deletions src/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,16 @@ where
pub const STRERROR_NAME: &str = "strerror_r";

pub fn errno() -> Errno {
// libc_errno is thread-local, so simply read its value.
unsafe { Errno(libc_errno) }
unsafe { Errno(*__errno_location()) }
}

pub fn set_errno(Errno(new_errno): Errno) {
// libc_errno is thread-local, so simply assign to it.
unsafe {
libc_errno = new_errno;
*__errno_location() = new_errno;
}
}

extern "C" {
#[thread_local]
#[link_name = "errno"]
static mut libc_errno: c_int;

fn __errno_location() -> *mut c_int;
fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: size_t) -> c_int;
}