Skip to content

Commit f0764b1

Browse files
committed
Provide read_buf for zkvm stdin
1 parent c77e370 commit f0764b1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

library/std/src/sys/pal/zkvm/stdio.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::abi;
22
use super::abi::fileno;
3-
use crate::io;
3+
use crate::io::{self, BorrowedCursor};
44

55
pub struct Stdin;
66
pub struct Stdout;
@@ -16,6 +16,14 @@ impl io::Read for Stdin {
1616
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
1717
Ok(unsafe { abi::sys_read(fileno::STDIN, buf.as_mut_ptr(), buf.len()) })
1818
}
19+
20+
fn read_buf(&mut self, mut buf: BorrowedCursor<'_>) -> io::Result<()> {
21+
unsafe {
22+
let n = abi::sys_read(fileno::STDIN, buf.as_mut().as_mut_ptr().cast(), buf.capacity());
23+
buf.advance_unchecked(n);
24+
}
25+
Ok(())
26+
}
1927
}
2028

2129
impl Stdout {

0 commit comments

Comments
 (0)