|
80 | 80 | //! The return value for `ioctl` functions generated by the `ioctl!` macro are `nix::Error`s.
|
81 | 81 | //! These are generated by assuming the return value of the ioctl is `-1` on error and everything
|
82 | 82 | //! else is a valid return value. If this is not the case, `Result::map` can be used to map some
|
83 |
| -//! of the range of "good" values (-2..-Inf, 0..Inf) into a smaller range in a helper function. |
| 83 | +//! of the range of "good" values (-Inf..-2, 0..Inf) into a smaller range in a helper function. |
| 84 | +//! |
| 85 | +//! Writing `ioctl`s generally use pointers as their data source and these should use the |
| 86 | +//! `write_ptr` variant. But in some cases an `int` is passed directly. For these `ioctl`s use the |
| 87 | +//! `write_int` variant of the `ioctl!` macro. This variant does not take a type as the last argument: |
| 88 | +//! |
| 89 | +//! ``` |
| 90 | +//! # #[macro_use] extern crate nix; |
| 91 | +//! const HCI_IOC_MAGIC: u8 = b'k'; |
| 92 | +//! const HCI_IOC_HCIDEVUP: u8 = 1; |
| 93 | +//! ioctl!(write_int hci_dev_up with HCI_IOC_MAGIC, HCI_IOC_HCIDEVUP); |
| 94 | +//! # fn main() {} |
| 95 | +//! ``` |
| 96 | +//! |
| 97 | +//! Some `ioctl`s don't transfer any data, and those should use the `none` variant. This variant |
| 98 | +//! doesn't take a type and so it is declared similar to the `write_int` variant shown above. |
84 | 99 | //!
|
85 | 100 | //! The mode for a given `ioctl` should be clear from the documentation if it has good
|
86 | 101 | //! documentation. Otherwise it will be clear based on the macro used to generate the `ioctl`
|
@@ -196,13 +211,20 @@ macro_rules! ioctl {
|
196 | 211 | convert_ioctl_res!($crate::libc::ioctl(fd, ior!($ioty, $nr, ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data))
|
197 | 212 | }
|
198 | 213 | );
|
199 |
| - (write $name:ident with $ioty:expr, $nr:expr; $ty:ty) => ( |
| 214 | + (write_ptr $name:ident with $ioty:expr, $nr:expr; $ty:ty) => ( |
200 | 215 | pub unsafe fn $name(fd: $crate::libc::c_int,
|
201 |
| - data: $ty) |
| 216 | + data: *const $ty) |
202 | 217 | -> $crate::Result<$crate::libc::c_int> {
|
203 | 218 | convert_ioctl_res!($crate::libc::ioctl(fd, iow!($ioty, $nr, ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data))
|
204 | 219 | }
|
205 | 220 | );
|
| 221 | + (write_int $name:ident with $ioty:expr, $nr:expr) => ( |
| 222 | + pub unsafe fn $name(fd: $crate::libc::c_int, |
| 223 | + data: $crate::libc::c_int) |
| 224 | + -> $crate::Result<$crate::libc::c_int> { |
| 225 | + convert_ioctl_res!($crate::libc::ioctl(fd, iow!($ioty, $nr, ::std::mem::size_of::<$crate::libc::c_int>()) as $crate::sys::ioctl::ioctl_num_type, data)) |
| 226 | + } |
| 227 | + ); |
206 | 228 | (readwrite $name:ident with $ioty:expr, $nr:expr; $ty:ty) => (
|
207 | 229 | pub unsafe fn $name(fd: $crate::libc::c_int,
|
208 | 230 | data: *mut $ty)
|
|
0 commit comments