瀏覽代碼

LibC: Flush all file streams on exit

The POSIX standard specifies the following:

> If the main() function returns to its original caller, or if the
> exit() function is called, all open files are closed (hence all output
> streams are flushed) before program termination.

This means that flushing `stdin` and `stdout` only is not enough, as the
program might have pending writes in other file buffers too.

Now that we support `fflush(nullptr)`, we call that in `exit()` to flush
all streams. This fixes one of bash's generated headers not being
written to disk.
Daniel Bertalan 3 年之前
父節點
當前提交
a1dfa1efb2
共有 1 個文件被更改,包括 1 次插入2 次删除
  1. 1 2
      Userland/Libraries/LibC/stdlib.cpp

+ 1 - 2
Userland/Libraries/LibC/stdlib.cpp

@@ -189,8 +189,7 @@ void exit(int status)
 
 
     extern void _fini();
     extern void _fini();
     _fini();
     _fini();
-    fflush(stdout);
-    fflush(stderr);
+    fflush(nullptr);
 
 
 #ifndef _DYNAMIC_LOADER
 #ifndef _DYNAMIC_LOADER
     __pthread_key_destroy_for_current_thread();
     __pthread_key_destroy_for_current_thread();