From 8aff315c7b07cd0e6b3fc9b380af87abcd859418 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 2 Jul 2025 00:55:04 +0300 Subject: [PATCH] LibC: fflush file in setvbuf before updating the buffer --- userspace/libraries/LibC/stdio.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/userspace/libraries/LibC/stdio.cpp b/userspace/libraries/LibC/stdio.cpp index 43709a13..567f745e 100644 --- a/userspace/libraries/LibC/stdio.cpp +++ b/userspace/libraries/LibC/stdio.cpp @@ -908,12 +908,16 @@ void setbuf(FILE* file, char* buffer) int setvbuf(FILE* file, char* buffer, int type, size_t size) { + ScopeLock _(file); + if (file->fd == -1) { errno = EBADF; return -1; } + (void)fflush(file); + if (size == 0) type = _IONBF;