From 2ffc96616b53c488417b044f320ab0d91e4942e9 Mon Sep 17 00:00:00 2001 From: David Cuddeback Date: Sun, 19 Nov 2017 17:57:09 -0700 Subject: [PATCH] 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] https://github.com/rust-lang/rust/issues/29594 --- serial-unix/Cargo.toml | 3 +++ serial-unix/src/error.rs | 14 +++----------- serial-unix/src/lib.rs | 3 +++ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/serial-unix/Cargo.toml b/serial-unix/Cargo.toml index 05514e1..62f5635 100644 --- a/serial-unix/Cargo.toml +++ b/serial-unix/Cargo.toml @@ -14,3 +14,6 @@ categories = ["hardware-support", "os", "os::unix-apis"] [dependencies] serial-core = { version = "0.4", path = "../serial-core" } libc = "0.2.33" + +[target.'cfg(target_os="dragonfly")'.dependencies] +errno-dragonfly = "0.1.1" diff --git a/serial-unix/src/error.rs b/serial-unix/src/error.rs index 8cebb56..4a32d9a 100644 --- a/serial-unix/src/error.rs +++ b/serial-unix/src/error.rs @@ -28,6 +28,9 @@ use std::str; use libc::{c_int, c_char}; +#[cfg(target_os = "dragonfly")] +use dfly::errno_location; + pub fn last_os_error() -> core::Error { from_raw_os_error(errno()) } @@ -73,23 +76,12 @@ extern { fn errno_location() -> *mut c_int; } -#[cfg(not(target_os = "dragonfly"))] pub fn errno() -> i32 { unsafe { (*errno_location()) as i32 } } -#[cfg(target_os = "dragonfly")] -pub fn errno() -> i32 { - extern { - #[thread_local] - static errno: c_int; - } - - unsafe { errno as i32 } -} - pub fn error_string(errno: i32) -> String { extern { #[cfg_attr(any(target_os = "linux", target_env = "newlib"), diff --git a/serial-unix/src/lib.rs b/serial-unix/src/lib.rs index 0bbbace..837b0b0 100644 --- a/serial-unix/src/lib.rs +++ b/serial-unix/src/lib.rs @@ -24,6 +24,9 @@ extern crate serial_core as core; extern crate libc; +#[cfg(target_os = "dragonfly")] +extern crate errno_dragonfly as dfly; + pub use tty::*; mod error;