Skip to content

Commit

Permalink
Fix errno on DragonFly
Browse files Browse the repository at this point in the history
__dfly_error() was removed from Rust many years ago.

DragonFly uses a thread-local errno variable, but #[thread_local] is
feature-gated and not available in stable Rust as of this writing
(Rust 1.31.0). We have to use a C extension to access it.

Tracking issue for `thread_local` stabilization:

    rust-lang/rust#29594

Once this becomes stable, we can simply use:

    extern { #[thread_local] static errno: c_int; }
  • Loading branch information
mneumann committed Dec 29, 2018
1 parent 0a4420d commit 8819bd5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions members/sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ users = "0.8.1"

[target."cfg(target_os = \"redox\")".dependencies]
redox_syscall = { git = "https://gitlab.redox-os.org/redox-os/syscall.git", branch = "relibc" }


[target."cfg(target_os = \"dragonfly\")".dependencies]
errno-dragonfly = "0.1.1"
4 changes: 3 additions & 1 deletion members/sys/src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
extern crate libc;
#[cfg(target_os = "dragonfly")]
extern crate errno_dragonfly;

pub mod signals;

Expand Down Expand Up @@ -57,7 +59,7 @@ fn errno() -> i32 { unsafe { *libc::__errno() } }
fn errno() -> i32 { unsafe { *libc::__error() } }

#[cfg(target_os = "dragonfly")]
fn errno() -> i32 { unsafe { *libc::__dfly_error() } }
fn errno() -> i32 { unsafe { *errno_dragonfly::errno_location()} }

pub fn strerror(errno: i32) -> &'static str {
unsafe {
Expand Down

0 comments on commit 8819bd5

Please sign in to comment.