|
12 | 12 | // spell-checker:ignore sigquit sigtstp |
13 | 13 | // spell-checker:ignore cbreak decctlq evenp litout oddp tcsadrain exta extb NCCS cfsetispeed |
14 | 14 | // spell-checker:ignore notaflag notacombo notabaud |
| 15 | +// spell-checker:ignore baudrate TCGETS |
15 | 16 |
|
16 | 17 | mod flags; |
17 | 18 |
|
18 | 19 | use crate::flags::AllFlags; |
19 | 20 | use crate::flags::COMBINATION_SETTINGS; |
20 | 21 | use clap::{Arg, ArgAction, ArgMatches, Command}; |
21 | | -use nix::libc::{O_NONBLOCK, TIOCGWINSZ, TIOCSWINSZ, c_ushort}; |
| 22 | +use nix::libc::{O_NONBLOCK, TCGETS2, TIOCGWINSZ, TIOCSWINSZ, c_ushort, termios2}; |
22 | 23 | use nix::sys::termios::{ |
23 | 24 | ControlFlags, InputFlags, LocalFlags, OutputFlags, SetArg, SpecialCharacterIndices as S, |
24 | | - Termios, cfgetospeed, cfsetispeed, cfsetospeed, tcgetattr, tcsetattr, |
| 25 | + Termios, cfsetispeed, cfsetospeed, tcgetattr, tcsetattr, |
25 | 26 | }; |
26 | 27 | use nix::{ioctl_read_bad, ioctl_write_ptr_bad}; |
27 | 28 | use std::cmp::Ordering; |
@@ -613,16 +614,27 @@ fn print_terminal_size( |
613 | 614 | window_size: Option<&TermSize>, |
614 | 615 | term_size: Option<&TermSize>, |
615 | 616 | ) -> nix::Result<()> { |
616 | | - let speed = cfgetospeed(termios); |
| 617 | + // GNU linked against glibc 2.42 provides us baudrate 51 which panics cfgetospeed |
| 618 | + #[cfg(not(target_os = "linux"))] |
| 619 | + let speed = nix::sys::termios::cfgetospeed(termios); |
| 620 | + #[cfg(target_os = "linux")] |
| 621 | + ioctl_read_bad!(tcgets2, TCGETS2, termios2); |
| 622 | + #[cfg(target_os = "linux")] |
| 623 | + let speed = { |
| 624 | + let mut t2 = unsafe { std::mem::zeroed::<termios2>() }; |
| 625 | + unsafe { tcgets2(opts.file.as_raw_fd(), &mut t2)? }; |
| 626 | + t2.c_ospeed |
| 627 | + }; |
| 628 | + |
617 | 629 | let mut printer = WrappedPrinter::new(window_size); |
618 | 630 |
|
619 | | - // BSDs use a u32 for the baud rate, so we can simply print it. |
620 | | - #[cfg(bsd)] |
| 631 | + // BSDs and Linux use a u32 for the baud rate, so we can simply print it. |
| 632 | + #[cfg(any(target_os = "linux", bsd))] |
621 | 633 | printer.print(&translate!("stty-output-speed", "speed" => speed)); |
622 | 634 |
|
623 | 635 | // Other platforms need to use the baud rate enum, so printing the right value |
624 | 636 | // becomes slightly more complicated. |
625 | | - #[cfg(not(bsd))] |
| 637 | + #[cfg(not(any(target_os = "linux", bsd)))] |
626 | 638 | for (text, baud_rate) in BAUD_RATES { |
627 | 639 | if *baud_rate == speed { |
628 | 640 | printer.print(&translate!("stty-output-speed", "speed" => (*text))); |
|
0 commit comments