Skip to content

Commit 3064c91

Browse files
committed
Cast to per-target major and minor return types.
1 parent f71815c commit 3064c91

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

libc-test/test/makedev.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,50 @@
11
//! Compare libc's makedev, major, minor functions against the actual C macros, for various
22
//! inputs.
33
4+
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
5+
mod ret {
6+
pub type MajorRetType = libc::major_t;
7+
pub type MinorRetType = libc::minor_t;
8+
}
9+
10+
#[cfg(any(
11+
target_os = "linux",
12+
target_os = "l4re",
13+
target_os = "emscripten",
14+
target_os = "fuchsia",
15+
target_os = "aix",
16+
target_os = "nto",
17+
target_os = "hurd",
18+
target_os = "openbsd",
19+
))]
20+
mod ret {
21+
pub type MajorRetType = libc::c_uint;
22+
pub type MinorRetType = libc::c_uint;
23+
}
24+
25+
#[cfg(any(
26+
target_os = "android",
27+
target_os = "dragonfly",
28+
target_os = "netbsd",
29+
target_os = "freebsd",
30+
))]
31+
mod ret {
32+
pub type MajorRetType = libc::c_int;
33+
pub type MinorRetType = libc::c_int;
34+
}
35+
36+
#[cfg(any(
37+
target_os = "macos",
38+
target_os = "ios",
39+
target_os = "tvos",
40+
target_os = "watchos",
41+
target_os = "visionos"
42+
))]
43+
mod ret {
44+
pub type MajorRetType = i32;
45+
pub type MinorRetType = i32;
46+
}
47+
448
#[cfg(any(
549
target_os = "android",
650
target_os = "dragonfly",
@@ -14,6 +58,8 @@
1458
mod t {
1559
use libc::{self, c_uint, dev_t};
1660

61+
use super::ret::*;
62+
1763
extern "C" {
1864
pub fn makedev_ffi(major: c_uint, minor: c_uint) -> dev_t;
1965
pub fn major_ffi(dev: dev_t) -> c_uint;
@@ -24,9 +70,9 @@ mod t {
2470
let dev = unsafe { makedev_ffi(major, minor) };
2571
assert_eq!(libc::makedev(major, minor), dev);
2672
let major = unsafe { major_ffi(dev) };
27-
assert_eq!(libc::major(dev) as i64, major as i64);
73+
assert_eq!(libc::major(dev), major as MajorRetType);
2874
let minor = unsafe { minor_ffi(dev) };
29-
assert_eq!(libc::minor(dev) as i64, minor as i64);
75+
assert_eq!(libc::minor(dev), minor as MinorRetType);
3076
}
3177

3278
// Every OS should be able to handle 8 bit major and minor numbers

0 commit comments

Comments
 (0)