Skip to content

Commit

Permalink
Correct the third argument to ioctl on appropriate platforms.
Browse files Browse the repository at this point in the history
While usually `ioctl()` passes a pointer, the function call has been
overloaded to allow integers to be passed. For some platforms this
is an `int` and on others it's a `ulong`.
  • Loading branch information
Bryant Mairs committed Jan 31, 2018
1 parent 36bfd5c commit f91530e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/sys/ioctl/bsd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/// The datatype used for the ioctl number
#[doc(hidden)]
pub type ioctl_num_type = ::libc::c_ulong;
/// The datatype used for the 3rd argument
#[doc(hidden)]
pub type ioctl_param_type = ::libc::c_int;

mod consts {
use ::sys::ioctl::ioctl_num_type;
Expand Down
5 changes: 2 additions & 3 deletions src/sys/ioctl/linux.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/// The datatype used for the ioctl number
#[cfg(any(target_os = "android", target_env = "musl"))]
#[doc(hidden)]
pub type ioctl_num_type = ::libc::c_int;
#[cfg(not(any(target_os = "android", target_env = "musl")))]
/// The datatype used for the 3rd argument
#[doc(hidden)]
pub type ioctl_num_type = ::libc::c_ulong;
pub type ioctl_param_type = ::libc::c_ulong;

#[doc(hidden)]
pub const NRBITS: ioctl_num_type = 8;
Expand Down
4 changes: 2 additions & 2 deletions src/sys/ioctl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ cfg_if!{
($(#[$attr:meta])* $name:ident, $ioty:expr, $nr:expr) => (
$(#[$attr])*
pub unsafe fn $name(fd: $crate::libc::c_int,
data: $crate::libc::c_int)
data: $crate::sys::ioctl::ioctl_param_type)
-> $crate::Result<$crate::libc::c_int> {
convert_ioctl_res!($crate::libc::ioctl(fd, request_code_write_int!($ioty, $nr) as $crate::sys::ioctl::ioctl_num_type, data))
}
Expand Down Expand Up @@ -578,7 +578,7 @@ cfg_if!{
($(#[$attr:meta])* $name:ident, $ioty:expr, $nr:expr) => (
$(#[$attr])*
pub unsafe fn $name(fd: $crate::libc::c_int,
data: $crate::libc::c_int)
data: $crate::sys::ioctl::ioctl_param_type)
-> $crate::Result<$crate::libc::c_int> {
convert_ioctl_res!($crate::libc::ioctl(fd, request_code_write!($ioty, $nr, ::std::mem::size_of::<$crate::libc::c_int>()) as $crate::sys::ioctl::ioctl_num_type, data))
}
Expand Down

0 comments on commit f91530e

Please sign in to comment.