From fe533c2e625392ae145bb3997a70e966e862e8e3 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 22 May 2026 20:43:23 +0300 Subject: [PATCH] LibC: Fix freopen to preserve file state :) --- userspace/libraries/LibC/stdio.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/userspace/libraries/LibC/stdio.cpp b/userspace/libraries/LibC/stdio.cpp index a9279040..3e9b506f 100644 --- a/userspace/libraries/LibC/stdio.cpp +++ b/userspace/libraries/LibC/stdio.cpp @@ -404,7 +404,8 @@ FILE* freopen(const char* pathname, const char* mode_str, FILE* file) if (pathname) { - fclose(file); + fflush(file); + close(file->fd); file->fd = open(pathname, mode, 0666); file->mode = mode & O_ACCMODE; if (file->fd == -1)