summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib.rs22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 03c9524..699b462 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,4 +1,3 @@
-use libc::ioctl;
use std::{convert::TryFrom,
fmt,
io::{self, BufWriter, Error, Write},
@@ -56,6 +55,17 @@ pub mod ioctl
pub const PIO_CMAP: libc::c_ulong = 0x00004B71; /* kd.h */
pub const KB_101: libc::c_char = 0x0002; /* kd.h */
+ pub fn kdgkbtype<F: AsRawFd>(fd: &F) -> io::Result<libc::c_char>
+ {
+ let mut kb: libc::c_char = 0;
+
+ let _ = cvt_r(&mut || unsafe {
+ ioctl(fd.as_raw_fd(), KDGKBTYPE, &mut kb as *mut _)
+ })?;
+
+ Ok(kb)
+ }
+
pub fn pio_cmap<F: AsRawFd>(fd: &F, pal: &Palette) -> io::Result<()>
{
/* cvt_r because technically it can’t be ruled out that we hit EINTR. */
@@ -616,14 +626,10 @@ impl Console
return Err(Error::last_os_error());
}
- let mut tty_type: libc::c_char = 0;
-
- let _ = cvt_r(&mut || unsafe {
- ioctl(fd, ioctl::KDGKBTYPE, &mut tty_type as *mut _)
- })?;
+ let fd = Self(fd);
/* Sanity check. */
- if tty_type != ioctl::KB_101 {
+ if ioctl::kdgkbtype(&fd)? != ioctl::KB_101 {
return Err(io::Error::new(
io::ErrorKind::Other,
format!(
@@ -633,7 +639,7 @@ impl Console
));
}
- Ok(Self(fd))
+ Ok(fd)
}
fn from_path<P: AsRef<Path>>(path: P) -> io::Result<Self>