-use std::io::{self, Write};
-
use log::trace;
use rustc_middle::mir;
let count = this.read_scalar(n)?.to_machine_usize(this)?;
trace!("Called write({:?}, {:?}, {:?})", fd, buf, count);
let result = this.write(fd, buf, count)?;
- if fd == 1 {
- io::stdout().flush().unwrap();
- }
// Now, `result` is the value we return back to the program.
this.write_scalar(Scalar::from_machine_isize(result, this), dest)?;
}
}
fn write(&mut self, bytes: &[u8]) -> InterpResult<'tcx, io::Result<usize>> {
- Ok(Write::write(self, bytes))
+ let result = Write::write(self, bytes);
+ // Stdout is buffered, flush to make sure it appears on the
+ // screen. This is the write() syscall of the interpreted
+ // program, we want it to correspond to a write() syscall on
+ // the host -- there is no good in adding extra buffering
+ // here.
+ io::stdout().flush().unwrap();
+
+ Ok(result)
}
fn seek(&mut self, _offset: SeekFrom) -> InterpResult<'tcx, io::Result<u64>> {