Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

1 change: 1 addition & 0 deletions src/uu/od/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ path = "src/od.rs"
byteorder = { workspace = true }
clap = { workspace = true }
half = { workspace = true }
rustix = { workspace = true, features = ["stdio"] }
uucore = { workspace = true, features = ["parser-size"] }
fluent = { workspace = true }
libc.workspace = true
Expand Down
19 changes: 11 additions & 8 deletions src/uu/od/src/multifile_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use std::fs::File;
use std::io;
#[cfg(unix)]
use std::os::fd::{AsRawFd, FromRawFd};

use uucore::display::Quotable;
use uucore::show_error;
Expand Down Expand Up @@ -56,20 +54,25 @@ impl MultifileReader<'_> {
// For performance reasons we do still do buffered reads from stdin, but
// the buffering is done elsewhere and in a way that is aware of the `-N`
// limit.
let stdin = io::stdin();
#[cfg(unix)]
#[cfg(any(unix, target_os = "wasi"))]
{
let stdin_raw_fd = stdin.as_raw_fd();
let stdin_file = unsafe { File::from_raw_fd(stdin_raw_fd) };
self.curr_file = Some(Box::new(stdin_file));
struct RawReader<'a>(rustix::fd::BorrowedFd<'a>);
impl io::Read for RawReader<'_> {
fn read(&mut self, b: &mut [u8]) -> io::Result<usize> {
rustix::io::read(self.0, b).map_err(Into::into)
}
}
let stdin = RawReader(rustix::stdio::stdin());
self.curr_file = Some(Box::new(stdin));
}

// For non-unix platforms we don't have GNU compatibility requirements, so
// we don't need to prevent stdin buffering. This is sub-optimal (since
// there will still be additional buffering further up the stack), but
// doesn't seem worth worrying about at this time.
#[cfg(not(unix))]
#[cfg(not(any(unix, target_os = "wasi")))]
{
let stdin = io::stdin();
self.curr_file = Some(Box::new(stdin));
}
break;
Expand Down
Loading