1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::fmt;
use errno::Errno;
#[macro_use(io, iow, ioc)]
extern crate ioctl_sys;
#[macro_use]
mod macros {
#[cfg(target_env = "gnu")]
#[macro_export]
macro_rules! IOCTL {
($name:ident, $ty:expr, $nr:expr) => (
const $name: std::os::raw::c_ulong = io!($ty, $nr) as std::os::raw::c_ulong;
);
($name:ident, $ty:expr, $nr:expr, $arg:ty) => (
const $name: std::os::raw::c_ulong = iow!($ty, $nr, std::mem::size_of::<$arg>()) as std::os::raw::c_ulong;
);
}
#[cfg(target_env = "musl")]
#[macro_export]
macro_rules! IOCTL {
($name:ident, $ty:expr, $nr:expr) => (
const $name: std::os::raw::c_int = io!($ty, $nr) as std::os::raw::c_int;
);
($name:ident, $ty:expr, $nr:expr, $arg:ty) => (
const $name: std::os::raw::c_int = iow!($ty, $nr, std::mem::size_of::<$arg>()) as std::os::raw::c_int;
);
}
}
pub mod map;
pub mod ffi;
pub mod sys;
#[derive(Debug)]
pub struct Error(Errno);
impl From<Errno> for Error {
fn from(err: Errno) -> Self {
Self(err)
}
}
impl std::error::Error for Error {}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}