pub const IOCTL_ERROR: i32 = -1;
macro_rules! ioctl_guard {
($func:expr) => {
ioctl_guard!($func, libc::EEXIST)
};
($func:expr, $already_active:expr) => {
if unsafe { $func } == $crate::macros::IOCTL_ERROR {
let io_error = ::std::io::Error::last_os_error();
let error_code = io_error
.raw_os_error()
.expect("Errors created with last_os_error should have errno");
Err($crate::Error::from(if error_code == $already_active {
$crate::ErrorInternal::StateAlreadyActive
} else {
$crate::ErrorInternal::Ioctl(io_error)
}))
} else {
Ok(()) as $crate::Result<()>
}
};
}