Lines Matching defs:termios
3 //! This interface provides a safe wrapper around the termios subsystem defined by POSIX. The
7 //! If you are unfamiliar with the `termios` API, you should first read the
8 //! [API documentation](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/termios.h.html) and
14 //! standard fields of the underlying `termios` struct and uses safe type wrappers for those fields.
16 //! copied into the underlying `termios` struct, then the operation is done, and the data is copied
17 //! back (with additional sanity checking) into the safe wrapper types. The `termios` struct is
26 //! # use self::nix::sys::termios::SpecialCharacterIndices::VEOF;
27 //! # use self::nix::sys::termios::{_POSIX_VDISABLE, Termios};
28 //! # let mut termios: Termios = unsafe { std::mem::zeroed() };
29 //! termios.control_chars[VEOF as usize] = _POSIX_VDISABLE;
40 //! # use self::nix::sys::termios::{ControlFlags, Termios};
41 //! # let mut termios: Termios = unsafe { std::mem::zeroed() };
42 //! termios.control_flags & ControlFlags::CSIZE == ControlFlags::CS5;
43 //! termios.control_flags |= ControlFlags::CS5;
49 //! only support the rates specified by the `BaudRate` enum through their termios API while the BSDs
51 //! value of the constant (`B9600` == `9600`). Therefore the `nix::termios` API uses the following
64 //! # use nix::sys::termios::{BaudRate, cfsetispeed, cfsetospeed, cfsetspeed, Termios};
76 //! # use nix::sys::termios::{BaudRate, cfgetispeed, cfgetospeed, cfsetispeed, cfsetspeed, Termios};
110 //! # use nix::sys::termios::{BaudRate, cfgetispeed, cfgetospeed, cfsetspeed, Termios};
143 //! # use nix::sys::termios::{BaudRate, cfgetispeed, cfgetospeed, cfsetspeed, Termios};
176 //! # use nix::sys::termios::{BaudRate, cfgetispeed, cfsetspeed, Termios};
210 //! # use nix::sys::termios::{cfsetispeed, cfsetospeed, cfsetspeed, Termios};
230 /// Stores settings for the termios API
232 /// This is a wrapper around the `libc::termios` struct that provides a safe interface for the
237 inner: RefCell<libc::termios>,
238 /// Input mode flags (see `termios.c_iflag` documentation)
240 /// Output mode flags (see `termios.c_oflag` documentation)
242 /// Control mode flags (see `termios.c_cflag` documentation)
244 /// Local mode flags (see `termios.c_lflag` documentation)
246 /// Control characters (see `termios.c_cc` documentation)
248 /// Line discipline (see `termios.c_line` documentation)
251 /// Line discipline (see `termios.c_line` documentation)
257 /// Exposes an immutable reference to the underlying `libc::termios` data structure.
261 pub(crate) fn get_libc_termios(&self) -> Ref<libc::termios> {
263 let mut termios = self.inner.borrow_mut();
264 termios.c_iflag = self.input_flags.bits();
265 termios.c_oflag = self.output_flags.bits();
266 termios.c_cflag = self.control_flags.bits();
267 termios.c_lflag = self.local_flags.bits();
268 termios.c_cc = self.control_chars;
275 termios.c_line = self.line_discipline;
281 /// Exposes the inner `libc::termios` datastore within `Termios`.
283 /// This is unsafe because if this is used to modify the inner `libc::termios` struct, it will
287 pub(crate) unsafe fn get_libc_termios_mut(&mut self) -> *mut libc::termios {
289 let mut termios = self.inner.borrow_mut();
290 termios.c_iflag = self.input_flags.bits();
291 termios.c_oflag = self.output_flags.bits();
292 termios.c_cflag = self.control_flags.bits();
293 termios.c_lflag = self.local_flags.bits();
294 termios.c_cc = self.control_chars;
301 termios.c_line = self.line_discipline;
307 /// Updates the wrapper values from the internal `libc::termios` data structure.
309 let termios = *self.inner.borrow_mut();
310 self.input_flags = InputFlags::from_bits_truncate(termios.c_iflag);
311 self.output_flags = OutputFlags::from_bits_truncate(termios.c_oflag);
312 self.control_flags = ControlFlags::from_bits_truncate(termios.c_cflag);
313 self.local_flags = LocalFlags::from_bits_truncate(termios.c_lflag);
314 self.control_chars = termios.c_cc;
321 self.line_discipline = termios.c_line;
326 impl From<libc::termios> for Termios {
327 fn from(termios: libc::termios) -> Self {
329 inner: RefCell::new(termios),
330 input_flags: InputFlags::from_bits_truncate(termios.c_iflag),
331 output_flags: OutputFlags::from_bits_truncate(termios.c_oflag),
332 control_flags: ControlFlags::from_bits_truncate(termios.c_cflag),
333 local_flags: LocalFlags::from_bits_truncate(termios.c_lflag),
334 control_chars: termios.c_cc,
340 line_discipline: termios.c_line,
345 impl From<Termios> for libc::termios {
346 fn from(termios: Termios) -> Self {
347 termios.inner.into_inner()
541 /// Indices into the `termios.c_cc` array for special characters.
1005 pub fn cfgetispeed(termios: &Termios) -> u32 {
1006 let inner_termios = termios.get_libc_termios();
1016 pub fn cfgetospeed(termios: &Termios) -> u32 {
1017 let inner_termios = termios.get_libc_termios();
1025 pub fn cfsetispeed<T: Into<u32>>(termios: &mut Termios, baud: T) -> Result<()> {
1026 let inner_termios = unsafe { termios.get_libc_termios_mut() };
1028 termios.update_wrapper();
1035 /// `cfsetospeed()` sets the output baud rate in the given termios structure.
1036 pub fn cfsetospeed<T: Into<u32>>(termios: &mut Termios, baud: T) -> Result<()> {
1037 let inner_termios = unsafe { termios.get_libc_termios_mut() };
1039 termios.update_wrapper();
1044 /// [termios(3)](https://www.freebsd.org/cgi/man.cgi?query=cfsetspeed)).
1046 /// `cfsetspeed()` sets the input and output baud rate in the given termios structure. Note that
1048 pub fn cfsetspeed<T: Into<u32>>(termios: &mut Termios, baud: T) -> Result<()> {
1049 let inner_termios = unsafe { termios.get_libc_termios_mut() };
1051 termios.update_wrapper();
1061 pub fn cfgetispeed(termios: &Termios) -> BaudRate {
1062 let inner_termios = termios.get_libc_termios();
1070 pub fn cfgetospeed(termios: &Termios) -> BaudRate {
1071 let inner_termios = termios.get_libc_termios();
1079 pub fn cfsetispeed(termios: &mut Termios, baud: BaudRate) -> Result<()> {
1080 let inner_termios = unsafe { termios.get_libc_termios_mut() };
1082 termios.update_wrapper();
1090 pub fn cfsetospeed(termios: &mut Termios, baud: BaudRate) -> Result<()> {
1091 let inner_termios = unsafe { termios.get_libc_termios_mut() };
1093 termios.update_wrapper();
1098 /// [termios(3)](https://www.freebsd.org/cgi/man.cgi?query=cfsetspeed)).
1103 pub fn cfsetspeed(termios: &mut Termios, baud: BaudRate) -> Result<()> {
1104 let inner_termios = unsafe { termios.get_libc_termios_mut() };
1106 termios.update_wrapper();
1113 /// [termios(3)](https://man7.org/linux/man-pages/man3/termios.3.html)).
1115 /// `cfmakeraw()` configures the termios structure such that input is available character-by-
1118 pub fn cfmakeraw(termios: &mut Termios) {
1119 let inner_termios = unsafe { termios.get_libc_termios_mut() };
1123 termios.update_wrapper();
1132 pub fn cfmakesane(termios: &mut Termios) {
1133 let inner_termios = unsafe { termios.get_libc_termios_mut() };
1137 termios.update_wrapper();
1147 let mut termios = mem::MaybeUninit::uninit();
1149 let res = unsafe { libc::tcgetattr(fd, termios.as_mut_ptr()) };
1153 unsafe { Ok(termios.assume_init().into()) }
1162 pub fn tcsetattr(fd: RawFd, actions: SetArg, termios: &Termios) -> Result<()> {
1163 let inner_termios = termios.get_libc_termios();