Commit 8054e082 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Merge branch 'more-libc' into 'master'

Use libc to be more resilient and compatible.

See merge request !181
parents e2f84510 4fafb44f
Pipeline #9717 failed with stages
in 60 minutes and 54 seconds
use std::{io, mem};
use super::{cvt, Termios};
use super::libc::c_int;
pub fn get_terminal_attr() -> io::Result<Termios> {
extern "C" {
pub fn tcgetattr(fd: c_int, termptr: *mut Termios) -> c_int;
}
unsafe {
let mut termios = mem::zeroed();
cvt(tcgetattr(1, &mut termios))?;
cvt(libc::tcgetattr(libc::STDOUT_FILENO, &mut termios))?;
Ok(termios)
}
}
pub fn set_terminal_attr(termios: &Termios) -> io::Result<()> {
extern "C" {
pub fn tcsetattr(fd: c_int, opt: c_int, termptr: *const Termios) -> c_int;
}
cvt(unsafe { tcsetattr(1, 0, termios) }).and(Ok(()))
cvt(unsafe { libc::tcsetattr(libc::STDOUT_FILENO, libc::TCSANOW, termios) }).and(Ok(()))
}
pub fn raw_terminal_attr(termios: &mut Termios) {
extern "C" {
pub fn cfmakeraw(termptr: *mut Termios);
}
unsafe { cfmakeraw(termios) }
unsafe { libc::cfmakeraw(termios) }
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment