Browse Source

Implement Drop for FILE, so we flush when the process exits

Tom Almeida 6 years ago
parent
commit
7277286efd
1 changed files with 9 additions and 0 deletions
  1. 9 0
      src/stdio/src/lib.rs

+ 9 - 0
src/stdio/src/lib.rs

@@ -203,6 +203,15 @@ impl Read for FILE {
     }
 }
 
+impl Drop for FILE {
+    fn drop(&mut self) {
+        // Flush
+        if let Some(_) = self.write {
+            self.write(&[]);
+        }
+    }
+}
+
 /// Clears EOF and ERR indicators on a stream
 #[no_mangle]
 pub extern "C" fn clearerr(stream: &mut FILE) {