|
6 | 6 |
|
7 | 7 | use std::fs::File; |
8 | 8 | use std::io; |
9 | | -#[cfg(unix)] |
10 | | -use std::os::fd::{AsRawFd, FromRawFd}; |
11 | 9 |
|
12 | 10 | use uucore::display::Quotable; |
13 | 11 | use uucore::show_error; |
@@ -56,20 +54,25 @@ impl MultifileReader<'_> { |
56 | 54 | // For performance reasons we do still do buffered reads from stdin, but |
57 | 55 | // the buffering is done elsewhere and in a way that is aware of the `-N` |
58 | 56 | // limit. |
59 | | - let stdin = io::stdin(); |
60 | | - #[cfg(unix)] |
| 57 | + #[cfg(any(unix, target_os = "wasi"))] |
61 | 58 | { |
62 | | - let stdin_raw_fd = stdin.as_raw_fd(); |
63 | | - let stdin_file = unsafe { File::from_raw_fd(stdin_raw_fd) }; |
64 | | - self.curr_file = Some(Box::new(stdin_file)); |
| 59 | + struct RawReader<'a>(rustix::fd::BorrowedFd<'a>); |
| 60 | + impl io::Read for RawReader<'_> { |
| 61 | + fn read(&mut self, b: &mut [u8]) -> io::Result<usize> { |
| 62 | + rustix::io::read(self.0, b).map_err(Into::into) |
| 63 | + } |
| 64 | + } |
| 65 | + let stdin = RawReader(rustix::stdio::stdin()); |
| 66 | + self.curr_file = Some(Box::new(stdin)); |
65 | 67 | } |
66 | 68 |
|
67 | 69 | // For non-unix platforms we don't have GNU compatibility requirements, so |
68 | 70 | // we don't need to prevent stdin buffering. This is sub-optimal (since |
69 | 71 | // there will still be additional buffering further up the stack), but |
70 | 72 | // doesn't seem worth worrying about at this time. |
71 | | - #[cfg(not(unix))] |
| 73 | + #[cfg(not(any(unix, target_os = "wasi")))] |
72 | 74 | { |
| 75 | + let stdin = io::stdin(); |
73 | 76 | self.curr_file = Some(Box::new(stdin)); |
74 | 77 | } |
75 | 78 | break; |
|
0 commit comments