From e1755da9f1c2755f72cbf843dd653c3f6f71c7e8 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 15 Nov 2021 21:42:32 +0100 Subject: add KDGKBTYPE wrapper --- src/lib.rs | 22 ++++++++++++++-------- 1 file 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(fd: &F) -> io::Result + { + 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(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>(path: P) -> io::Result -- cgit v1.2.3