|
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 = "bitrig")] |
17 |
| -fn errno_location() -> *mut c_int { |
18 |
| - extern { |
19 |
| - fn __errno() -> *mut c_int; |
20 |
| - } |
21 |
| - unsafe { |
22 |
| - __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 | + } |
23 | 32 | }
|
24 | 33 | }
|
25 | 34 |
|
26 |
| -#[cfg(target_os = "dragonfly")] |
27 |
| -unsafe fn errno_location() -> *mut c_int { |
28 |
| - extern { fn __dfly_error() -> *mut c_int; } |
29 |
| - __dfly_error() |
30 |
| -} |
31 |
| - |
32 |
| -#[cfg(any(target_os = "openbsd", target_os = "netbsd"))] |
33 |
| -unsafe fn errno_location() -> *mut c_int { |
34 |
| - extern { fn __errno() -> *mut c_int; } |
35 |
| - __errno() |
36 |
| -} |
37 |
| - |
38 |
| -#[cfg(target_os = "linux")] |
39 |
| -unsafe fn errno_location() -> *mut c_int { |
40 |
| - extern { fn __errno_location() -> *mut c_int; } |
41 |
| - __errno_location() |
42 |
| -} |
43 |
| - |
44 |
| -#[cfg(target_os = "android")] |
45 |
| -unsafe fn errno_location() -> *mut c_int { |
46 |
| - extern { fn __errno() -> *mut c_int; } |
47 |
| - __errno() |
48 |
| -} |
49 |
| - |
50 | 35 | /// Sets the platform-specific errno to no-error
|
51 | 36 | unsafe fn clear() -> () {
|
52 | 37 | *errno_location() = 0;
|
@@ -520,7 +505,7 @@ fn desc(errno: Errno) -> &'static str {
|
520 | 505 |
|
521 | 506 | #[cfg(target_os = "dragonfly")]
|
522 | 507 | EUNUSED94 | EUNUSED95 | EUNUSED96 | EUNUSED97 | EUNUSED98 => "Unused",
|
523 |
| - |
| 508 | + |
524 | 509 | #[cfg(target_os = "dragonfly")]
|
525 | 510 | EASYNC => "Async",
|
526 | 511 | }
|
|
0 commit comments