|
1 |
| -//! Compare libc's makdev function against the actual C macros, for various |
| 1 | +//! Compare libc's makedev, major, minor functions against the actual C macros, for various |
2 | 2 | //! inputs.
|
3 | 3 |
|
| 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 | + |
4 | 48 | #[cfg(any(
|
5 | 49 | target_os = "android",
|
6 | 50 | target_os = "dragonfly",
|
|
14 | 58 | mod t {
|
15 | 59 | use libc::{self, c_uint, dev_t};
|
16 | 60 |
|
| 61 | + use super::ret::*; |
| 62 | + |
17 | 63 | extern "C" {
|
18 | 64 | pub fn makedev_ffi(major: c_uint, minor: c_uint) -> dev_t;
|
| 65 | + pub fn major_ffi(dev: dev_t) -> c_uint; |
| 66 | + pub fn minor_ffi(dev: dev_t) -> c_uint; |
19 | 67 | }
|
20 | 68 |
|
21 | 69 | fn compare(major: c_uint, minor: c_uint) {
|
22 |
| - let expected = unsafe { makedev_ffi(major, minor) }; |
23 |
| - assert_eq!(libc::makedev(major, minor), expected); |
| 70 | + let dev = unsafe { makedev_ffi(major, minor) }; |
| 71 | + assert_eq!(libc::makedev(major, minor), dev); |
| 72 | + let major = unsafe { major_ffi(dev) }; |
| 73 | + assert_eq!(libc::major(dev), major as MajorRetType); |
| 74 | + let minor = unsafe { minor_ffi(dev) }; |
| 75 | + assert_eq!(libc::minor(dev), minor as MinorRetType); |
24 | 76 | }
|
25 | 77 |
|
26 | 78 | // Every OS should be able to handle 8 bit major and minor numbers
|
|
0 commit comments