From ca9aeeec1ffdb09aa938edf507bfddfa0a8fdcbb Mon Sep 17 00:00:00 2001 From: Fotis Panagiotopoulos Date: Tue, 18 Oct 2022 13:19:10 +0300 Subject: [PATCH] freopen: Added flush of the read buffers. --- libs/libc/stdio/lib_freopen.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libs/libc/stdio/lib_freopen.c b/libs/libc/stdio/lib_freopen.c index ca4d42bc78b..2958dfdaace 100644 --- a/libs/libc/stdio/lib_freopen.c +++ b/libs/libc/stdio/lib_freopen.c @@ -100,9 +100,16 @@ FAR FILE *freopen(FAR const char *path, FAR const char *mode, return NULL; } - /* Flush the stream and duplicate the new fd to it */ + /* Flush the stream and invalidate the read buffer. */ fflush(stream); + +#ifndef CONFIG_STDIO_DISABLE_BUFFERING + lib_rdflush(stream); +#endif + + /* Duplicate the new fd to the stream. */ + ret = dup2(fd, fileno(stream)); close(fd); if (ret < 0)