This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit c4733a636798ce525352dbd4ad23a65a76d948da
Author: pengyinjie <[email protected]>
AuthorDate: Mon Oct 13 19:55:06 2025 +0800

    libc/stdio: Enable line buffering in fdopen() only for terminals.
    
    fdopen() enabled line buffering unconditionally.  Enable it only when
    the file descriptor refers to a terminal, as required for the default
    buffering mode of a newly opened stream.
    
    fopen() is built on fdopen(), so with CONFIG_STDIO_LINEBUFFER the streams
    of files that are not terminals, opened with fopen() or fdopen(), are now
    fully buffered instead of line buffered, as C requires for a stream that
    does not refer to an interactive device.
    
    Signed-off-by: pengyinjie <[email protected]>
    Signed-off-by: ganjing <[email protected]>
---
 libs/libc/stdio/lib_fopen.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libs/libc/stdio/lib_fopen.c b/libs/libc/stdio/lib_fopen.c
index cc72a095731..c313ce87619 100644
--- a/libs/libc/stdio/lib_fopen.c
+++ b/libs/libc/stdio/lib_fopen.c
@@ -131,7 +131,10 @@ FAR FILE *fdopen(int fd, FAR const char *mode)
 #  ifdef CONFIG_STDIO_LINEBUFFER
   /* Setup buffer flags */
 
-  filep->fs_flags   |= __FS_FLAG_LBF; /* Line buffering */
+  if ((oflags & O_WRONLY) != 0 && isatty(fd))
+    {
+      filep->fs_flags |= __FS_FLAG_LBF; /* Enable LBF only for terminals */
+    }
 
 #  endif /* CONFIG_STDIO_LINEBUFFER */
 #endif /* !CONFIG_STDIO_DISABLE_BUFFERING && CONFIG_STDIO_BUFFER_SIZE > 0 */

Reply via email to