From 5ccb37a3f70193e6dabf0182bba28d74becf0c8e Mon Sep 17 00:00:00 2001 From: pjht Date: Sun, 22 Sep 2024 14:53:19 -0500 Subject: [PATCH] mikros: Do not close stdio after every use --- library/std/src/sys/pal/mikros/stdio.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/library/std/src/sys/pal/mikros/stdio.rs b/library/std/src/sys/pal/mikros/stdio.rs index d24f8338cb1..b46dea6c49f 100644 --- a/library/std/src/sys/pal/mikros/stdio.rs +++ b/library/std/src/sys/pal/mikros/stdio.rs @@ -26,8 +26,9 @@ fn read(&mut self, buf: &mut [u8]) -> io::Result { return Ok(0); }; let file = File { fs_pid: fd.0, fd: fd.1, pos: AtomicUsize::new(0) }; - let num_bytes = file.read(buf)?; - Ok(num_bytes) + let res = file.read(buf); + crate::mem::drop(file); // do not close the temporary file struct + res } } @@ -49,7 +50,9 @@ fn write(&mut self, buf: &[u8]) -> io::Result { return Ok(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<()> { @@ -75,7 +78,9 @@ fn write(&mut self, buf: &[u8]) -> io::Result { return Ok(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<()> {