Skip to content

Commit 2d270c9

Browse files
committed
Merge #798
798: More libc ffi r=Susurrus a=Susurrus Blocking on rust-lang/libc#850 for Android support.
2 parents b335685 + d625194 commit 2d270c9

File tree

2 files changed

+27
-43
lines changed

2 files changed

+27
-43
lines changed

src/errno.rs

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,37 @@
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 = "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+
}
2332
}
2433
}
2534

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-
5035
/// Sets the platform-specific errno to no-error
5136
unsafe fn clear() -> () {
5237
*errno_location() = 0;
@@ -520,7 +505,7 @@ fn desc(errno: Errno) -> &'static str {
520505

521506
#[cfg(target_os = "dragonfly")]
522507
EUNUSED94 | EUNUSED95 | EUNUSED96 | EUNUSED97 | EUNUSED98 => "Unused",
523-
508+
524509
#[cfg(target_os = "dragonfly")]
525510
EASYNC => "Async",
526511
}

src/sys/aio.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ libc_enum! {
1919
/// do it like `fsync`
2020
O_SYNC,
2121
/// on supported operating systems only, do it like `fdatasync`
22-
#[cfg(any(target_os = "bitrig",
23-
target_os = "ios",
22+
#[cfg(any(target_os = "ios",
2423
target_os = "linux",
2524
target_os = "macos",
2625
target_os = "netbsd",

0 commit comments

Comments
 (0)