From a1dfa1efb2da5b79683e8cc00706d12e0fe1bcf7 Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Sat, 15 Jan 2022 14:41:39 +0100 Subject: 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. --- Userland/Libraries/LibC/stdlib.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Userland/Libraries/LibC/stdlib.cpp b/Userland/Libraries/LibC/stdlib.cpp index 713373fad9..580ffd630c 100644 --- a/Userland/Libraries/LibC/stdlib.cpp +++ b/Userland/Libraries/LibC/stdlib.cpp @@ -189,8 +189,7 @@ void exit(int status) extern void _fini(); _fini(); - fflush(stdout); - fflush(stderr); + fflush(nullptr); #ifndef _DYNAMIC_LOADER __pthread_key_destroy_for_current_thread(); -- cgit v1.2.3