Skip to content

Commit

Permalink
Use libc function declarations for errno getters
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryant Mairs committed Nov 17, 2017
1 parent 1e382ff commit d625194
Showing 1 changed file with 26 additions and 31 deletions.
57 changes: 26 additions & 31 deletions src/errno.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,35 @@
use libc::c_int;
use libc::{self, c_int};
use std::{fmt, io, error};
use {Error, Result};

pub use self::consts::*;
pub use self::consts::Errno::*;

#[cfg(any(target_os = "macos",
target_os = "ios",
target_os = "freebsd"))]
unsafe fn errno_location() -> *mut c_int {
extern { fn __error() -> *mut c_int; }
__error()
}

#[cfg(target_os = "dragonfly")]
unsafe fn errno_location() -> *mut c_int {
extern { fn __dfly_error() -> *mut c_int; }
__dfly_error()
}

#[cfg(any(target_os = "openbsd", target_os = "netbsd"))]
unsafe fn errno_location() -> *mut c_int {
extern { fn __errno() -> *mut c_int; }
__errno()
}

#[cfg(target_os = "linux")]
unsafe fn errno_location() -> *mut c_int {
extern { fn __errno_location() -> *mut c_int; }
__errno_location()
}

#[cfg(target_os = "android")]
unsafe fn errno_location() -> *mut c_int {
extern { fn __errno() -> *mut c_int; }
__errno()
cfg_if! {
if #[cfg(any(target_os = "freebsd",
target_os = "ios",
target_os = "macos"))] {
unsafe fn errno_location() -> *mut c_int {
libc::__error()
}
} else if #[cfg(target_os = "dragonfly")] {
unsafe fn errno_location() -> *mut c_int {
// FIXME: Replace with errno-dragonfly crate as this is no longer the correct
// implementation.
extern { fn __dfly_error() -> *mut c_int; }
__dfly_error()
}
} else if #[cfg(any(target_os = "android",
target_os = "netbsd",
target_os = "openbsd"))] {
unsafe fn errno_location() -> *mut c_int {
libc::__errno()
}
} else if #[cfg(target_os = "linux")] {
unsafe fn errno_location() -> *mut c_int {
libc::__errno_location()
}
}
}

/// Sets the platform-specific errno to no-error
Expand Down

0 comments on commit d625194

Please sign in to comment.