od, uucore: Allow reusing RawReader (#12385)

This commit is contained in:
oech3
2026-05-19 21:47:21 +09:00
committed by GitHub
parent 4da1068154
commit 2a8ce671b0
3 changed files with 12 additions and 10 deletions
+1 -1
View File
@@ -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
+1 -9
View File
@@ -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<T: AsFd>(pub T);
impl<T: AsFd> io::Read for RawReader<T> {
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());
let stdin = uucore::io::RawReader(rustix::stdio::stdin());
self.curr_file = Some(Box::new(stdin));
}
+10
View File
@@ -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<T: AsFd>(pub T);
#[cfg(any(unix, target_os = "wasi"))]
impl<T: AsFd> io::Read for RawReader<T> {
fn read(&mut self, b: &mut [u8]) -> io::Result<usize> {
rustix::io::read(&self.0, b).map_err(Into::into)
}
}
// create writer without buffering
#[cfg(any(unix, target_os = "wasi"))]
pub struct RawWriter<T: AsFd>(pub T);