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 6cf7ef56b24c731e7b9d12b484ff4d4dfbf67267
Author: anpeiyun <[email protected]>
AuthorDate: Tue Sep 16 16:18:48 2025 +0800

    libc/stdio: Stop stream reads when the EOF indicator is set.
    
    POSIX says that fgetc(), fgets(), gets() and fread() return without
    reading when the end-of-file indicator of the stream is set.  NuttX
    ignored the indicator and read from the file again.  Check the indicator
    before reading and return at once if it is set.
    
    https://pubs.opengroup.org/onlinepubs/9699919799/functions/fgetc.html
    https://pubs.opengroup.org/onlinepubs/9699919799/functions/fread.html
    
    Signed-off-by: anpeiyun <[email protected]>
    Signed-off-by: ganjing <[email protected]>
---
 libs/libc/stdio/lib_libfread_unlocked.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libs/libc/stdio/lib_libfread_unlocked.c 
b/libs/libc/stdio/lib_libfread_unlocked.c
index 205b1775a2e..4298fe0eab2 100644
--- a/libs/libc/stdio/lib_libfread_unlocked.c
+++ b/libs/libc/stdio/lib_libfread_unlocked.c
@@ -70,6 +70,10 @@ ssize_t lib_fread_unlocked(FAR void *ptr, size_t count, FAR 
FILE *stream)
       set_errno(EBADF);
       return ERROR;
     }
+  else if ((stream->fs_flags & __FS_FLAG_EOF) != 0)
+    {
+      return 0;
+    }
   else
     {
       fd = (int)(intptr_t)stream->fs_cookie;

Reply via email to