Merge branch 'more-libc' into 'master'

Use libc to be more resilient and compatible.

See merge request redox-os/termion!181
This commit is contained in:
Jeremy Soller 2021-09-27 22:20:18 +00:00
commit 8054e082b0
1 changed files with 3 additions and 13 deletions

View File

@ -1,29 +1,19 @@
use std::{io, mem}; use std::{io, mem};
use super::{cvt, Termios}; use super::{cvt, Termios};
use super::libc::c_int;
pub fn get_terminal_attr() -> io::Result<Termios> { pub fn get_terminal_attr() -> io::Result<Termios> {
extern "C" {
pub fn tcgetattr(fd: c_int, termptr: *mut Termios) -> c_int;
}
unsafe { unsafe {
let mut termios = mem::zeroed(); let mut termios = mem::zeroed();
cvt(tcgetattr(1, &mut termios))?; cvt(libc::tcgetattr(libc::STDOUT_FILENO, &mut termios))?;
Ok(termios) Ok(termios)
} }
} }
pub fn set_terminal_attr(termios: &Termios) -> io::Result<()> { pub fn set_terminal_attr(termios: &Termios) -> io::Result<()> {
extern "C" { cvt(unsafe { libc::tcsetattr(libc::STDOUT_FILENO, libc::TCSANOW, termios) }).and(Ok(()))
pub fn tcsetattr(fd: c_int, opt: c_int, termptr: *const Termios) -> c_int;
}
cvt(unsafe { tcsetattr(1, 0, termios) }).and(Ok(()))
} }
pub fn raw_terminal_attr(termios: &mut Termios) { pub fn raw_terminal_attr(termios: &mut Termios) {
extern "C" { unsafe { libc::cfmakeraw(termios) }
pub fn cfmakeraw(termptr: *mut Termios);
}
unsafe { cfmakeraw(termios) }
} }