Skip to content

Commit

Permalink
Fix errno location on DragonFly BSD
Browse files Browse the repository at this point in the history
DragonFlyBSD uses a thread-local variable for errno. libstd uses a
feature (`thread_local`) which is not stablized [1].

[1] rust-lang/rust#29594
  • Loading branch information
dcuddeback committed Jun 22, 2018
1 parent a85da94 commit 2ffc966
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
3 changes: 3 additions & 0 deletions serial-unix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
14 changes: 3 additions & 11 deletions serial-unix/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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"),
Expand Down
3 changes: 3 additions & 0 deletions serial-unix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2ffc966

Please sign in to comment.