Skip to content

Commit 2ffc966

Browse files
committed
Fix errno location on DragonFly BSD
DragonFlyBSD uses a thread-local variable for errno. libstd uses a feature (`thread_local`) which is not stablized [1]. [1] rust-lang/rust#29594
1 parent a85da94 commit 2ffc966

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

serial-unix/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ categories = ["hardware-support", "os", "os::unix-apis"]
1414
[dependencies]
1515
serial-core = { version = "0.4", path = "../serial-core" }
1616
libc = "0.2.33"
17+
18+
[target.'cfg(target_os="dragonfly")'.dependencies]
19+
errno-dragonfly = "0.1.1"

serial-unix/src/error.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ use std::str;
2828

2929
use libc::{c_int, c_char};
3030

31+
#[cfg(target_os = "dragonfly")]
32+
use dfly::errno_location;
33+
3134
pub fn last_os_error() -> core::Error {
3235
from_raw_os_error(errno())
3336
}
@@ -73,23 +76,12 @@ extern {
7376
fn errno_location() -> *mut c_int;
7477
}
7578

76-
#[cfg(not(target_os = "dragonfly"))]
7779
pub fn errno() -> i32 {
7880
unsafe {
7981
(*errno_location()) as i32
8082
}
8183
}
8284

83-
#[cfg(target_os = "dragonfly")]
84-
pub fn errno() -> i32 {
85-
extern {
86-
#[thread_local]
87-
static errno: c_int;
88-
}
89-
90-
unsafe { errno as i32 }
91-
}
92-
9385
pub fn error_string(errno: i32) -> String {
9486
extern {
9587
#[cfg_attr(any(target_os = "linux", target_env = "newlib"),

serial-unix/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
extern crate serial_core as core;
2525
extern crate libc;
2626

27+
#[cfg(target_os = "dragonfly")]
28+
extern crate errno_dragonfly as dfly;
29+
2730
pub use tty::*;
2831

2932
mod error;

0 commit comments

Comments
 (0)