Skip to content

Commit 8819bd5

Browse files
committed
Fix errno on DragonFly
__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; }
1 parent 0a4420d commit 8819bd5

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

members/sys/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ users = "0.8.1"
1212

1313
[target."cfg(target_os = \"redox\")".dependencies]
1414
redox_syscall = { git = "https://gitlab.redox-os.org/redox-os/syscall.git", branch = "relibc" }
15+
16+
17+
[target."cfg(target_os = \"dragonfly\")".dependencies]
18+
errno-dragonfly = "0.1.1"

members/sys/src/sys/unix/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
extern crate libc;
2+
#[cfg(target_os = "dragonfly")]
3+
extern crate errno_dragonfly;
24

35
pub mod signals;
46

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

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

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

0 commit comments

Comments
 (0)