|
1 |
| -use libc::c_int; |
| 1 | +use libc::{self, c_int}; |
2 | 2 | use std::{fmt, io, error};
|
3 | 3 | use {Error, Result};
|
4 | 4 |
|
5 | 5 | pub use self::consts::*;
|
6 | 6 | pub use self::consts::Errno::*;
|
7 | 7 |
|
8 |
| -#[cfg(any(target_os = "macos", |
9 |
| - target_os = "ios", |
10 |
| - target_os = "freebsd"))] |
11 |
| -unsafe fn errno_location() -> *mut c_int { |
12 |
| - extern { fn __error() -> *mut c_int; } |
13 |
| - __error() |
14 |
| -} |
15 |
| - |
16 |
| -#[cfg(target_os = "dragonfly")] |
17 |
| -unsafe fn errno_location() -> *mut c_int { |
18 |
| - extern { fn __dfly_error() -> *mut c_int; } |
19 |
| - __dfly_error() |
20 |
| -} |
21 |
| - |
22 |
| -#[cfg(any(target_os = "openbsd", target_os = "netbsd"))] |
23 |
| -unsafe fn errno_location() -> *mut c_int { |
24 |
| - extern { fn __errno() -> *mut c_int; } |
25 |
| - __errno() |
26 |
| -} |
27 |
| - |
28 |
| -#[cfg(target_os = "linux")] |
29 |
| -unsafe fn errno_location() -> *mut c_int { |
30 |
| - extern { fn __errno_location() -> *mut c_int; } |
31 |
| - __errno_location() |
32 |
| -} |
33 |
| - |
34 |
| -#[cfg(target_os = "android")] |
35 |
| -unsafe fn errno_location() -> *mut c_int { |
36 |
| - extern { fn __errno() -> *mut c_int; } |
37 |
| - __errno() |
| 8 | +cfg_if! { |
| 9 | + if #[cfg(any(target_os = "freebsd", |
| 10 | + target_os = "ios", |
| 11 | + target_os = "macos"))] { |
| 12 | + unsafe fn errno_location() -> *mut c_int { |
| 13 | + libc::__error() |
| 14 | + } |
| 15 | + } else if #[cfg(target_os = "dragonfly")] { |
| 16 | + unsafe fn errno_location() -> *mut c_int { |
| 17 | + // FIXME: Replace with errno-dragonfly crate as this is no longer the correct |
| 18 | + // implementation. |
| 19 | + extern { fn __dfly_error() -> *mut c_int; } |
| 20 | + __dfly_error() |
| 21 | + } |
| 22 | + } else if #[cfg(any(target_os = "android", |
| 23 | + target_os = "netbsd", |
| 24 | + target_os = "openbsd"))] { |
| 25 | + unsafe fn errno_location() -> *mut c_int { |
| 26 | + libc::__errno() |
| 27 | + } |
| 28 | + } else if #[cfg(target_os = "linux")] { |
| 29 | + unsafe fn errno_location() -> *mut c_int { |
| 30 | + libc::__errno_location() |
| 31 | + } |
| 32 | + } |
38 | 33 | }
|
39 | 34 |
|
40 | 35 | /// Sets the platform-specific errno to no-error
|
|
0 commit comments