Skip to content

Commit

Permalink
stty: Support for --file/-F
Browse files Browse the repository at this point in the history
Fixes issue #3863
  • Loading branch information
VorpalBlade committed Feb 21, 2023
1 parent bc0273f commit 003098a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 17 additions & 3 deletions src/uu/stty/src/stty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
mod flags;

use clap::{crate_version, Arg, ArgAction, ArgMatches, Command};
use nix::libc::{c_ushort, TIOCGWINSZ, TIOCSWINSZ};
use nix::libc::{c_ushort, O_NONBLOCK, TIOCGWINSZ, TIOCSWINSZ};
use nix::sys::termios::{
cfgetospeed, tcgetattr, tcsetattr, ControlFlags, InputFlags, LocalFlags, OutputFlags, Termios,
};
use nix::{ioctl_read_bad, ioctl_write_ptr_bad};
use std::io::{self, stdout};
use std::ops::ControlFlow;
use std::os::unix::io::{AsRawFd, RawFd};
use std::os::unix::fs::OpenOptionsExt;
use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
use uucore::error::{UResult, USimpleError};
use uucore::format_usage;

Expand Down Expand Up @@ -102,7 +103,20 @@ impl<'a> Options<'a> {
all: matches.get_flag(options::ALL),
save: matches.get_flag(options::SAVE),
file: match matches.get_one::<String>(options::FILE) {
Some(_f) => todo!(),
// Two notes here:
// 1. O_NONBLOCK is needed because according to GNU docs, a
// POSIX tty can block waiting for carrier-detect if the
// "clocal" flag is not set. If your TTY is not connected
// to a modem, it is probably not relevant though.
// 2. We never close the FD that we open here, but the OS
// will clean up the FD for us on exit, so it doesn't
// matter. The alternative would be to have an enum of
// BorrowedFd/OwnedFd to handle both cases.
Some(f) => std::fs::OpenOptions::new()
.read(true)
.custom_flags(O_NONBLOCK)
.open(f)?
.into_raw_fd(),
None => stdout().as_raw_fd(),
},
settings: matches
Expand Down

0 comments on commit 003098a

Please sign in to comment.