mikros: Do not close stdio after every use

This commit is contained in:
pjht 2024-09-22 14:53:19 -05:00
parent 7bd76e861a
commit 5ccb37a3f7
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E

View File

@ -26,8 +26,9 @@ impl io::Read for Stdin {
return Ok(0); return Ok(0);
}; };
let file = File { fs_pid: fd.0, fd: fd.1, pos: AtomicUsize::new(0) }; let file = File { fs_pid: fd.0, fd: fd.1, pos: AtomicUsize::new(0) };
let num_bytes = file.read(buf)?; let res = file.read(buf);
Ok(num_bytes) crate::mem::drop(file); // do not close the temporary file struct
res
} }
} }
@ -49,7 +50,9 @@ impl io::Write for Stdout {
return Ok(0); return Ok(0);
}; };
let file = File { fs_pid: fd.0, fd: fd.1, pos: AtomicUsize::new(0) }; let file = File { fs_pid: fd.0, fd: fd.1, pos: AtomicUsize::new(0) };
file.write(buf) let res = file.write(buf);
crate::mem::drop(file); // do not close the temporary file struct
res
} }
fn flush(&mut self) -> io::Result<()> { fn flush(&mut self) -> io::Result<()> {
@ -75,7 +78,9 @@ impl io::Write for Stderr {
return Ok(0); return Ok(0);
}; };
let file = File { fs_pid: fd.0, fd: fd.1, pos: AtomicUsize::new(0) }; let file = File { fs_pid: fd.0, fd: fd.1, pos: AtomicUsize::new(0) };
file.write(buf) let res = file.write(buf);
crate::mem::drop(file); // do not close the temporary file struct
res
} }
fn flush(&mut self) -> io::Result<()> { fn flush(&mut self) -> io::Result<()> {