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;