Handle read
s on STDIN
This commit is contained in:
parent
ade99c3bed
commit
2602e951c0
@ -67,7 +67,18 @@ fn emulate_foreign_item_by_name(
|
||||
let buf = this.read_scalar(buf)?.not_undef()?;
|
||||
let count = this.read_scalar(count)?.to_machine_usize(this)?;
|
||||
let result = if fd == 0 {
|
||||
throw_unsup_format!("reading from stdin is not implemented")
|
||||
use std::io::{self, Read};
|
||||
|
||||
let mut buffer = String::new();
|
||||
let res = io::stdin().read_to_string(&mut buffer);
|
||||
|
||||
match res {
|
||||
Ok(bytes) => {
|
||||
this.memory.write_bytes(buf, buffer.bytes())?;
|
||||
i64::try_from(bytes).unwrap()
|
||||
},
|
||||
Err(_) => -1,
|
||||
}
|
||||
} else if fd == 1 || fd == 2 {
|
||||
throw_unsup_format!("cannot read from stdout/stderr")
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user