From 3064c9153e0f536f468dd5dc323ec9d60a6e7050 Mon Sep 17 00:00:00 2001 From: Ivan Gankevich Date: Mon, 24 Feb 2025 08:10:49 +0100 Subject: [PATCH] Cast to per-target `major` and `minor` return types. --- libc-test/test/makedev.rs | 50 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/libc-test/test/makedev.rs b/libc-test/test/makedev.rs index 021495e586b8f..44297a2163aa2 100644 --- a/libc-test/test/makedev.rs +++ b/libc-test/test/makedev.rs @@ -1,6 +1,50 @@ //! Compare libc's makedev, major, minor functions against the actual C macros, for various //! inputs. +#[cfg(any(target_os = "solaris", target_os = "illumos"))] +mod ret { + pub type MajorRetType = libc::major_t; + pub type MinorRetType = libc::minor_t; +} + +#[cfg(any( + target_os = "linux", + target_os = "l4re", + target_os = "emscripten", + target_os = "fuchsia", + target_os = "aix", + target_os = "nto", + target_os = "hurd", + target_os = "openbsd", +))] +mod ret { + pub type MajorRetType = libc::c_uint; + pub type MinorRetType = libc::c_uint; +} + +#[cfg(any( + target_os = "android", + target_os = "dragonfly", + target_os = "netbsd", + target_os = "freebsd", +))] +mod ret { + pub type MajorRetType = libc::c_int; + pub type MinorRetType = libc::c_int; +} + +#[cfg(any( + target_os = "macos", + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos" +))] +mod ret { + pub type MajorRetType = i32; + pub type MinorRetType = i32; +} + #[cfg(any( target_os = "android", target_os = "dragonfly", @@ -14,6 +58,8 @@ mod t { use libc::{self, c_uint, dev_t}; + use super::ret::*; + extern "C" { pub fn makedev_ffi(major: c_uint, minor: c_uint) -> dev_t; pub fn major_ffi(dev: dev_t) -> c_uint; @@ -24,9 +70,9 @@ mod t { let dev = unsafe { makedev_ffi(major, minor) }; assert_eq!(libc::makedev(major, minor), dev); let major = unsafe { major_ffi(dev) }; - assert_eq!(libc::major(dev) as i64, major as i64); + assert_eq!(libc::major(dev), major as MajorRetType); let minor = unsafe { minor_ffi(dev) }; - assert_eq!(libc::minor(dev) as i64, minor as i64); + assert_eq!(libc::minor(dev), minor as MinorRetType); } // Every OS should be able to handle 8 bit major and minor numbers