Skip to content

Commit 2602e95

Browse files
committed
Handle reads on STDIN
1 parent ade99c3 commit 2602e95

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/shims/posix/foreign_items.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
6767
let buf = this.read_scalar(buf)?.not_undef()?;
6868
let count = this.read_scalar(count)?.to_machine_usize(this)?;
6969
let result = if fd == 0 {
70-
throw_unsup_format!("reading from stdin is not implemented")
70+
use std::io::{self, Read};
71+
72+
let mut buffer = String::new();
73+
let res = io::stdin().read_to_string(&mut buffer);
74+
75+
match res {
76+
Ok(bytes) => {
77+
this.memory.write_bytes(buf, buffer.bytes())?;
78+
i64::try_from(bytes).unwrap()
79+
},
80+
Err(_) => -1,
81+
}
7182
} else if fd == 1 || fd == 2 {
7283
throw_unsup_format!("cannot read from stdout/stderr")
7384
} else {

0 commit comments

Comments
 (0)