Skip to content

Commit 118bb74

Browse files
committed
Provide exact reads for StdinRaw
1 parent f5d401a commit 118bb74

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

library/std/src/io/stdio.rs

+21
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,20 @@ impl Read for StdinRaw {
120120
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
121121
handle_ebadf(self.0.read_to_string(buf), 0)
122122
}
123+
124+
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
125+
if buf.is_empty() {
126+
return Ok(());
127+
}
128+
handle_ebadf_err(self.0.read_exact(buf), io::Error::READ_EXACT_EOF)
129+
}
130+
131+
fn read_buf_exact(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> {
132+
if buf.capacity() == 0 {
133+
return Ok(());
134+
}
135+
handle_ebadf_err(self.0.read_buf_exact(buf), io::Error::READ_EXACT_EOF)
136+
}
123137
}
124138

125139
impl Write for StdoutRaw {
@@ -200,6 +214,13 @@ fn handle_ebadf_lazy<T>(r: io::Result<T>, default: impl FnOnce() -> T) -> io::Re
200214
}
201215
}
202216

217+
fn handle_ebadf_err<T>(r: io::Result<T>, default_err: io::Error) -> io::Result<T> {
218+
match r {
219+
Err(ref e) if stdio::is_ebadf(e) => Err(default_err),
220+
r => r,
221+
}
222+
}
223+
203224
/// A handle to the standard input stream of a process.
204225
///
205226
/// Each handle is a shared reference to a global buffer of input data to this

0 commit comments

Comments
 (0)