From 19b4aa9f810d44f2e0cf73889a514b204913eaf0 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 22 Jul 2023 11:19:48 +0200 Subject: [PATCH] libc: Flush buffers before dealing with file positions --- libc/src/stdio.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libc/src/stdio.cpp b/libc/src/stdio.cpp index 4f09faf1..4e3440ff 100644 --- a/libc/src/stdio.cpp +++ b/libc/src/stdio.cpp @@ -350,6 +350,8 @@ extern "C" int fseek(FILE* stream, long offset, int whence) { + fflush(stream); + long result = lseek(stream->_fd, offset, whence); if (result < 0) return -1; @@ -361,11 +363,15 @@ extern "C" long ftell(FILE* stream) { + fflush(stream); + return lseek(stream->_fd, 0, SEEK_CUR); } void rewind(FILE* stream) { + fflush(stream); + lseek(stream->_fd, 0, SEEK_SET); clearerr(stream); @@ -383,6 +389,8 @@ extern "C" int fsetpos(FILE* stream, const fpos_t* pos) { + fflush(stream); + return fseek(stream, *pos, SEEK_SET); }