浏览代码

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

Tom Almeida 6 年之前
父节点
当前提交
7277286efd
共有 1 个文件被更改,包括 9 次插入0 次删除
  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) {