From 65596fe0ac738a17511a474cd375aacc3fab2d37 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Thu, 2 Apr 2026 11:18:25 +0200 Subject: [PATCH] wc: split WordCountable trait to exclude inner_file on wasi --- src/uu/wc/src/countable.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/uu/wc/src/countable.rs b/src/uu/wc/src/countable.rs index 5b2ad7a99..32d565538 100644 --- a/src/uu/wc/src/countable.rs +++ b/src/uu/wc/src/countable.rs @@ -20,13 +20,20 @@ pub trait WordCountable: AsFd + AsRawFd + Read { fn inner_file(&mut self) -> Option<&mut File>; } -#[cfg(not(unix))] +#[cfg(all(not(unix), not(target_os = "wasi")))] pub trait WordCountable: Read { type Buffered: BufRead; fn buffered(self) -> Self::Buffered; fn inner_file(&mut self) -> Option<&mut File>; } +#[cfg(target_os = "wasi")] +pub trait WordCountable: Read { + type Buffered: BufRead; + fn buffered(self) -> Self::Buffered; +} + +#[cfg(not(target_os = "wasi"))] impl WordCountable for StdinLock<'_> { type Buffered = Self; @@ -38,6 +45,16 @@ impl WordCountable for StdinLock<'_> { } } +#[cfg(target_os = "wasi")] +impl WordCountable for StdinLock<'_> { + type Buffered = Self; + + fn buffered(self) -> Self::Buffered { + self + } +} + +#[cfg(not(target_os = "wasi"))] impl WordCountable for File { type Buffered = BufReader; @@ -49,3 +66,12 @@ impl WordCountable for File { Some(self) } } + +#[cfg(target_os = "wasi")] +impl WordCountable for File { + type Buffered = BufReader; + + fn buffered(self) -> Self::Buffered { + BufReader::new(self) + } +}