Use from_bits_retain for all Termios wrapper fields.
In case there are any unrecognised bits, they should be kept when
setting fields of the underlying libc termios struct in
get_libc_termios, rather than being dropped. This ensures that termios
can be roundtripped even with unrecognised bits set.
Test: Treehugger
Change-Id: I478b660042edac07b82dedf5fe997e5deac14777
diff --git a/src/sys/termios.rs b/src/sys/termios.rs
index ecaa3ea..74c5fc5 100644
--- a/src/sys/termios.rs
+++ b/src/sys/termios.rs
@@ -307,10 +307,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(
target_os = "linux",
@@ -327,10 +327,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(
target_os = "linux",