Use nix PR #2799 termios.rs changes: https://github.com/nix-rust/nix/pull/2799/files --- build/amd64/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/nix-0.31.3/src/sys/termios.rs.old +++ build/amd64/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/nix-0.31.3/src/sys/termios.rs @@ -219,10 +219,10 @@ /// Updates the wrapper values from the internal `libc::termios` data structure. pub(crate) fn update_wrapper(&mut self) { let termios = *self.inner.borrow_mut(); - self.input_flags = InputFlags::from_bits_truncate(termios.c_iflag); - self.output_flags = OutputFlags::from_bits_truncate(termios.c_oflag); + self.input_flags = InputFlags::from_bits_retain(termios.c_iflag); + self.output_flags = OutputFlags::from_bits_retain(termios.c_oflag); self.control_flags = ControlFlags::from_bits_retain(termios.c_cflag); - self.local_flags = LocalFlags::from_bits_truncate(termios.c_lflag); + self.local_flags = LocalFlags::from_bits_retain(termios.c_lflag); self.control_chars = termios.c_cc; #[cfg(any(linux_android, target_os = "haiku"))] { @@ -235,10 +235,10 @@ fn from(termios: libc::termios) -> Self { Termios { inner: RefCell::new(termios), - input_flags: InputFlags::from_bits_truncate(termios.c_iflag), - output_flags: OutputFlags::from_bits_truncate(termios.c_oflag), - control_flags: ControlFlags::from_bits_truncate(termios.c_cflag), - local_flags: LocalFlags::from_bits_truncate(termios.c_lflag), + input_flags: InputFlags::from_bits_retain(termios.c_iflag), + output_flags: OutputFlags::from_bits_retain(termios.c_oflag), + control_flags: ControlFlags::from_bits_retain(termios.c_cflag), + local_flags: LocalFlags::from_bits_retain(termios.c_lflag), control_chars: termios.c_cc, #[cfg(any(linux_android, target_os = "haiku"))] line_discipline: termios.c_line, @@ -460,9 +460,9 @@ pub const VTIME: SpecialCharacterIndices = SpecialCharacterIndices::VEOL; } -pub use libc::NCCS; #[cfg(any(bsd, linux_android, target_os = "aix", target_os = "solaris"))] pub use libc::_POSIX_VDISABLE; +pub use libc::NCCS; libc_bitflags! { /// Flags for configuring the input mode of a terminal @@ -947,3 +947,40 @@ Errno::result(res).map(Pid::from_raw) } } + +#[cfg(test)] +mod test { + use super::*; + use std::convert::TryFrom; + + #[test] + fn try_from() { + assert_eq!(Ok(BaudRate::B0), BaudRate::try_from(libc::B0)); + #[cfg(not(target_os = "haiku"))] + BaudRate::try_from(999999999).expect_err("assertion failed"); + #[cfg(target_os = "haiku")] + BaudRate::try_from(99).expect_err("assertion failed"); + } + + #[test] + fn roundtrip_termios() { + // A fake termios including flag bits which we don't recognise. + #[allow(clippy::needless_update)] + let original = libc::termios { + c_iflag: 0xf00f, + c_oflag: 0xd00d, + c_cflag: 0x6642, + c_lflag: 0x1234, + c_cc: [0; NCCS], + ..unsafe { std::mem::zeroed() } + }; + + let mut attrs: Termios = original.into(); + let before_update = attrs.get_libc_termios().to_owned(); + attrs.update_wrapper(); + let after_update = attrs.get_libc_termios().to_owned(); + + assert_eq!(before_update, original); + assert_eq!(after_update, original); + } +}