Skip to content

Commit d625194

Browse files
author
Bryant Mairs
committed
Use libc function declarations for errno getters
1 parent 1e382ff commit d625194

File tree

1 file changed

+26
-31
lines changed

1 file changed

+26
-31
lines changed

src/errno.rs

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,35 @@
1-
use libc::c_int;
1+
use libc::{self, c_int};
22
use std::{fmt, io, error};
33
use {Error, Result};
44

55
pub use self::consts::*;
66
pub use self::consts::Errno::*;
77

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+
}
3833
}
3934

4035
/// Sets the platform-specific errno to no-error

0 commit comments

Comments
 (0)