diff options
-rw-r--r-- | src/sys/termios.rs | 26 | ||||
-rw-r--r-- | test/sys/test_termios.rs | 8 |
2 files changed, 33 insertions, 1 deletions
diff --git a/src/sys/termios.rs b/src/sys/termios.rs index 10adf089..2a815158 100644 --- a/src/sys/termios.rs +++ b/src/sys/termios.rs @@ -776,6 +776,20 @@ pub fn cfgetospeed(termios: &Termios) -> BaudRate { unsafe { libc::cfgetospeed(&*inner_termios) }.into() } +/// Configures the port to something like the "raw" mode of the old Version 7 terminal driver (see +/// [termios(3)](http://man7.org/linux/man-pages/man3/termios.3.html)). +/// +/// `cfmakeraw()` configures the termios structure such that input is available character-by- +/// character, echoing is disabled, and all special input and output processing is disabled. Note +/// that this is a non-standard function, but is available on Linux and BSDs. +pub fn cfmakeraw(termios: &mut Termios) { + let inner_termios = unsafe { termios.get_libc_termios_mut() }; + unsafe { + libc::cfmakeraw(inner_termios); + } + termios.update_wrapper(); +} + /// Set input baud rate (see /// [cfsetispeed(3p)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/cfsetispeed.html)). /// @@ -798,6 +812,18 @@ pub fn cfsetospeed(termios: &mut Termios, baud: BaudRate) -> Result<()> { Errno::result(res).map(drop) } +/// Set both the input and output baud rates (see +/// [termios(3)](http://man7.org/linux/man-pages/man3/termios.3.html)). +/// +/// `cfsetspeed()` sets the input and output baud rate in the given termios structure. Note that +/// this is part of the 4.4BSD standard and not part of POSIX. +pub fn cfsetspeed(termios: &mut Termios, baud: BaudRate) -> Result<()> { + let inner_termios = unsafe { termios.get_libc_termios_mut() }; + let res = unsafe { libc::cfsetspeed(inner_termios, baud as libc::speed_t) }; + termios.update_wrapper(); + Errno::result(res).map(drop) +} + /// Return the configuration of a port /// [tcgetattr(3p)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/tcgetattr.html)). /// diff --git a/test/sys/test_termios.rs b/test/sys/test_termios.rs index 0a2d1855..308cf62c 100644 --- a/test/sys/test_termios.rs +++ b/test/sys/test_termios.rs @@ -3,7 +3,7 @@ use std::os::unix::prelude::*; use nix::{Error, fcntl, unistd}; use nix::errno::Errno; use nix::pty::openpty; -use nix::sys::termios::{self, ECHO, OPOST, OCRNL, tcgetattr}; +use nix::sys::termios::{self, ECHO, OPOST, OCRNL, Termios, tcgetattr}; use nix::unistd::{read, write, close}; /// Helper function analogous to std::io::Write::write_all, but for `RawFd`s @@ -104,3 +104,9 @@ fn test_local_flags() { let read = read(pty.master, &mut buf).unwrap_err(); assert_eq!(read, Error::Sys(Errno::EAGAIN)); } + +#[test] +fn test_cfmakeraw() { + let mut termios = unsafe { Termios::default_uninit() }; + termios::cfmakeraw(&mut termios); +} |