summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBryant Mairs <bryantmairs@google.com>2017-11-16 22:02:37 -0800
committerBryant Mairs <bryantmairs@google.com>2017-11-16 22:02:37 -0800
commitd6251948cd942559b94116937ec08fda25ceff30 (patch)
tree224567eb491c1ed43735bcd3b707c70c8c8f8f95 /src
parent1e382ffa14d0e6becc8a15f962dec585b94ec381 (diff)
downloadnix-d6251948cd942559b94116937ec08fda25ceff30.zip
Use libc function declarations for errno getters
Diffstat (limited to 'src')
-rw-r--r--src/errno.rs57
1 files changed, 26 insertions, 31 deletions
diff --git a/src/errno.rs b/src/errno.rs
index a99c2261..e7486c8e 100644
--- a/src/errno.rs
+++ b/src/errno.rs
@@ -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