#![allow(dead_code)]
use libc::{input_event, timeval};
use std::fmt::{self, Debug, Display};
use std::fs::File;
use std::io::{ErrorKind, Read};
use std::os::unix::io::{AsRawFd, RawFd};
use std::path::Path;
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId(usize);
pub struct Device {
file: File,
}
impl AsRawFd for Device {
fn as_raw_fd(&self) -> RawFd {
self.file.as_raw_fd()
}
}
impl Device {
pub fn open<P: AsRef<Path>>(path: P, non_block: bool) -> Result<Self, std::io::Error> {
let file = File::open(path)?;
if non_block {
unsafe {
let fd = file.as_raw_fd();
let mut flags = libc::fcntl(fd, libc::F_GETFL, 0);
flags |= libc::O_NONBLOCK;
libc::fcntl(fd, libc::F_SETFL, flags);
}
}
Ok(Self { file })
}
}