mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
od, uucore: Allow reusing RawReader (#12385)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user