summaryrefslogtreecommitdiff
path: root/src/sys/ioctl/platform/linux.rs
diff options
context:
space:
mode:
authorBryant Mairs <bryant@mai.rs>2017-07-11 16:46:17 -0700
committerMarcin Mielniczuk <marmistrz.dev@zoho.eu>2017-07-25 09:09:52 +0200
commit82e0139bedfd6f13dd8cd501148ea09619b1d91b (patch)
tree0f27287eb18145ae4910a30a938df628232fa1f1 /src/sys/ioctl/platform/linux.rs
parentcaaffb883d78e09140b6a2fa77cc9fdb74d411fb (diff)
downloadnix-82e0139bedfd6f13dd8cd501148ea09619b1d91b.zip
Use the proper ioctl number type depending on target
This also means that we need to properly mask off bits to the valid range of ioctl numbers.
Diffstat (limited to 'src/sys/ioctl/platform/linux.rs')
-rw-r--r--src/sys/ioctl/platform/linux.rs36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/sys/ioctl/platform/linux.rs b/src/sys/ioctl/platform/linux.rs
index e3a130a9..6daa9257 100644
--- a/src/sys/ioctl/platform/linux.rs
+++ b/src/sys/ioctl/platform/linux.rs
@@ -1,7 +1,15 @@
+/// The datatype used for the ioctl number
+#[cfg(any(target_os = "android", target_env = "musl"))]
#[doc(hidden)]
-pub const NRBITS: u32 = 8;
+pub type ioctl_num_type = ::libc::c_int;
+#[cfg(not(any(target_os = "android", target_env = "musl")))]
#[doc(hidden)]
-pub const TYPEBITS: u32 = 8;
+pub type ioctl_num_type = ::libc::c_ulong;
+
+#[doc(hidden)]
+pub const NRBITS: ioctl_num_type = 8;
+#[doc(hidden)]
+pub const TYPEBITS: ioctl_num_type = 8;
#[cfg(any(target_arch = "mips", target_arch = "mips64", target_arch = "powerpc", target_arch = "powerpc64"))]
mod consts {
@@ -50,32 +58,32 @@ mod consts {
pub use self::consts::*;
#[doc(hidden)]
-pub const NRSHIFT: u32 = 0;
+pub const NRSHIFT: ioctl_num_type = 0;
#[doc(hidden)]
-pub const TYPESHIFT: u32 = NRSHIFT + NRBITS as u32;
+pub const TYPESHIFT: ioctl_num_type = NRSHIFT + NRBITS as ioctl_num_type;
#[doc(hidden)]
-pub const SIZESHIFT: u32 = TYPESHIFT + TYPEBITS as u32;
+pub const SIZESHIFT: ioctl_num_type = TYPESHIFT + TYPEBITS as ioctl_num_type;
#[doc(hidden)]
-pub const DIRSHIFT: u32 = SIZESHIFT + SIZEBITS as u32;
+pub const DIRSHIFT: ioctl_num_type = SIZESHIFT + SIZEBITS as ioctl_num_type;
#[doc(hidden)]
-pub const NRMASK: u32 = (1 << NRBITS) - 1;
+pub const NRMASK: ioctl_num_type = (1 << NRBITS) - 1;
#[doc(hidden)]
-pub const TYPEMASK: u32 = (1 << TYPEBITS) - 1;
+pub const TYPEMASK: ioctl_num_type = (1 << TYPEBITS) - 1;
#[doc(hidden)]
-pub const SIZEMASK: u32 = (1 << SIZEBITS) - 1;
+pub const SIZEMASK: ioctl_num_type = (1 << SIZEBITS) - 1;
#[doc(hidden)]
-pub const DIRMASK: u32 = (1 << DIRBITS) - 1;
+pub const DIRMASK: ioctl_num_type = (1 << DIRBITS) - 1;
/// Encode an ioctl command.
#[macro_export]
#[doc(hidden)]
macro_rules! ioc {
($dir:expr, $ty:expr, $nr:expr, $sz:expr) => (
- (($dir as u32) << $crate::sys::ioctl::DIRSHIFT) |
- (($ty as u32) << $crate::sys::ioctl::TYPESHIFT) |
- (($nr as u32) << $crate::sys::ioctl::NRSHIFT) |
- (($sz as u32) << $crate::sys::ioctl::SIZESHIFT))
+ (($dir as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::DIRMASK) << $crate::sys::ioctl::DIRSHIFT) |
+ (($ty as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::TYPEMASK) << $crate::sys::ioctl::TYPESHIFT) |
+ (($nr as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::NRMASK) << $crate::sys::ioctl::NRSHIFT) |
+ (($sz as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::SIZEMASK) << $crate::sys::ioctl::SIZESHIFT))
}
/// Encode an ioctl command that has no associated data.