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 36338ec1d1a050c45a5b98a60621962b60d991a9
Author: anpeiyun <[email protected]>
AuthorDate: Mon Aug 25 14:45:14 2025 +0800

    libc/stdio: Clear the EOF indicator in fseek().
    
    POSIX says that a successful fseek() clears the end-of-file indicator of
    the stream.  NuttX left it set, and since reads now stop while the
    indicator is set, a read after seeking back into the file would fail.
    
    https://pubs.opengroup.org/onlinepubs/9699919799/functions/fseek.html
    
    Signed-off-by: anpeiyun <[email protected]>
    Signed-off-by: ganjing <[email protected]>
---
 libs/libc/stdio/lib_fseeko.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/libs/libc/stdio/lib_fseeko.c b/libs/libc/stdio/lib_fseeko.c
index 72002ffc41e..822ba0d6a26 100644
--- a/libs/libc/stdio/lib_fseeko.c
+++ b/libs/libc/stdio/lib_fseeko.c
@@ -58,6 +58,7 @@
 
 int fseeko(FAR FILE *stream, off_t offset, int whence)
 {
+  off_t newpos;
 #ifdef CONFIG_DEBUG_FEATURES
   /* Verify that we were provided with a stream */
 
@@ -91,12 +92,18 @@ int fseeko(FAR FILE *stream, off_t offset, int whence)
 
   if (stream->fs_iofunc.seek != NULL)
     {
-      return stream->fs_iofunc.seek(stream->fs_cookie, &offset,
-                                    whence) == (off_t)-1 ? ERROR : OK;
+      newpos = stream->fs_iofunc.seek(stream->fs_cookie, &offset, whence);
     }
   else
     {
-      return lseek((int)(intptr_t)stream->fs_cookie, offset,
-                                    whence) == (off_t)-1 ? ERROR : OK;
+      newpos = lseek((int)(intptr_t)stream->fs_cookie, offset, whence);
     }
+
+  if (newpos != (off_t)-1)
+    {
+      stream->fs_flags &= ~__FS_FLAG_EOF;
+      return OK;
+    }
+
+  return ERROR;
 }

Reply via email to