From 2a8ce671b09b8db047666e66d21d8adfa9bb3bfc Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Tue, 19 May 2026 21:47:21 +0900 Subject: [PATCH] od, uucore: Allow reusing RawReader (#12385) --- src/uu/od/Cargo.toml | 2 +- src/uu/od/src/multifile_reader.rs | 10 +--------- src/uucore/src/lib/mods/io.rs | 10 ++++++++++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/uu/od/Cargo.toml b/src/uu/od/Cargo.toml index 87579a341..1804630d4 100644 --- a/src/uu/od/Cargo.toml +++ b/src/uu/od/Cargo.toml @@ -22,7 +22,7 @@ byteorder = { workspace = true } clap = { workspace = true } half = { workspace = true } rustix = { workspace = true, features = ["stdio"] } -uucore = { workspace = true, features = ["parser-size"] } +uucore = { workspace = true, features = ["fs", "parser-size"] } fluent = { workspace = true } libc.workspace = true diff --git a/src/uu/od/src/multifile_reader.rs b/src/uu/od/src/multifile_reader.rs index 414df4e4e..27c3b8376 100644 --- a/src/uu/od/src/multifile_reader.rs +++ b/src/uu/od/src/multifile_reader.rs @@ -56,15 +56,7 @@ impl MultifileReader<'_> { // limit. #[cfg(any(unix, target_os = "wasi"))] { - use std::os::fd::AsFd; - // todo: definition is generic enough to move to uucore::io::RawReader if useful - struct RawReader(pub T); - impl io::Read for RawReader { - fn read(&mut self, b: &mut [u8]) -> io::Result { - rustix::io::read(&self.0, b).map_err(Into::into) - } - } - let stdin = RawReader(rustix::stdio::stdin()); + let stdin = uucore::io::RawReader(rustix::stdio::stdin()); self.curr_file = Some(Box::new(stdin)); } diff --git a/src/uucore/src/lib/mods/io.rs b/src/uucore/src/lib/mods/io.rs index 06da4b95f..eccbd10e3 100644 --- a/src/uucore/src/lib/mods/io.rs +++ b/src/uucore/src/lib/mods/io.rs @@ -30,6 +30,16 @@ type NativeType = OwnedHandle; #[cfg(not(windows))] type NativeType = OwnedFd; +// create reader without buffering +#[cfg(any(unix, target_os = "wasi"))] +pub struct RawReader(pub T); +#[cfg(any(unix, target_os = "wasi"))] +impl io::Read for RawReader { + fn read(&mut self, b: &mut [u8]) -> io::Result { + rustix::io::read(&self.0, b).map_err(Into::into) + } +} + // create writer without buffering #[cfg(any(unix, target_os = "wasi"))] pub struct RawWriter(pub T);