Skip to main content

linux_media/
ioctl.rs

1/// A wrapper macro of ioctl.
2/// If the calling ioctl returned -1, it returns [`crate::error::Error`] corresponding to the errno.
3#[macro_export]
4macro_rules! ioctl {
5    ($fd:expr, $kind:expr) => {{
6        let ret = libc::ioctl($fd.as_raw_fd(), $kind);
7        if ret != 0 {
8            Err(crate::error::Error::ioctl_error(
9                $fd.as_raw_fd(),
10                std::io::Error::last_os_error().raw_os_error().unwrap(),
11                $kind,
12            ))
13        } else {
14            Ok(())
15        }
16    }};
17    ($fd:expr, $kind:expr, $arg:expr) => {{
18        let ret = libc::ioctl($fd.as_raw_fd(), $kind, $arg);
19        if ret != 0 {
20            Err(crate::error::Error::ioctl_error(
21                $fd.as_raw_fd(),
22                std::io::Error::last_os_error().raw_os_error().unwrap(),
23                $kind,
24            ))
25        } else {
26            Ok(())
27        }
28    }};
29}