Skip to content

Commit 604de7c

Browse files
stty: fix output redirection
1 parent 685df65 commit 604de7c

1 file changed

Lines changed: 13 additions & 35 deletions

File tree

src/uu/stty/src/stty.rs

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ use nix::sys::termios::{
1515
};
1616
use nix::{ioctl_read_bad, ioctl_write_ptr_bad};
1717
use std::fs::File;
18-
use std::io::{self, Stdout, stdout};
18+
use std::io::Result;
1919
use std::ops::ControlFlow;
20-
use std::os::fd::{AsFd, BorrowedFd};
20+
use std::os::fd::AsFd;
2121
use std::os::unix::fs::OpenOptionsExt;
22-
use std::os::unix::io::{AsRawFd, RawFd};
22+
use std::os::unix::io::AsRawFd;
2323
use uucore::error::{UResult, USimpleError};
2424
use uucore::{format_usage, help_about, help_usage};
2525

@@ -94,35 +94,12 @@ mod options {
9494
struct Options<'a> {
9595
all: bool,
9696
save: bool,
97-
file: Device,
97+
file: File,
9898
settings: Option<Vec<&'a str>>,
9999
}
100100

101-
enum Device {
102-
File(File),
103-
Stdout(Stdout),
104-
}
105-
106-
impl AsFd for Device {
107-
fn as_fd(&self) -> BorrowedFd<'_> {
108-
match self {
109-
Self::File(f) => f.as_fd(),
110-
Self::Stdout(stdout) => stdout.as_fd(),
111-
}
112-
}
113-
}
114-
115-
impl AsRawFd for Device {
116-
fn as_raw_fd(&self) -> RawFd {
117-
match self {
118-
Self::File(f) => f.as_raw_fd(),
119-
Self::Stdout(stdout) => stdout.as_raw_fd(),
120-
}
121-
}
122-
}
123-
124101
impl<'a> Options<'a> {
125-
fn from(matches: &'a ArgMatches) -> io::Result<Self> {
102+
fn from(matches: &'a ArgMatches) -> Result<Self> {
126103
Ok(Self {
127104
all: matches.get_flag(options::ALL),
128105
save: matches.get_flag(options::SAVE),
@@ -136,13 +113,14 @@ impl<'a> Options<'a> {
136113
// will clean up the FD for us on exit, so it doesn't
137114
// matter. The alternative would be to have an enum of
138115
// BorrowedFd/OwnedFd to handle both cases.
139-
Some(f) => Device::File(
140-
std::fs::OpenOptions::new()
141-
.read(true)
142-
.custom_flags(O_NONBLOCK)
143-
.open(f)?,
144-
),
145-
None => Device::Stdout(stdout()),
116+
Some(f) => std::fs::OpenOptions::new()
117+
.read(true)
118+
.custom_flags(O_NONBLOCK)
119+
.open(f)?,
120+
None => std::fs::OpenOptions::new()
121+
.read(true)
122+
.custom_flags(O_NONBLOCK)
123+
.open("/dev/tty")?,
146124
},
147125
settings: matches
148126
.get_many::<String>(options::SETTINGS)

0 commit comments

Comments
 (0)