summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2021-11-15 21:42:32 +0100
committerPhilipp Gesang <phg@phi-gamma.net>2021-11-15 21:42:32 +0100
commite1755da9f1c2755f72cbf843dd653c3f6f71c7e8 (patch)
treee191a5a74dff53bdd54c88409f3eddd61be986e8
parent5ad720d81e57be1b45e78df9204709af6c4cdc35 (diff)
downloadvtcol-e1755da9f1c2755f72cbf843dd653c3f6f71c7e8.tar.gz
add KDGKBTYPE wrapper
-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>