yushuailong commented on code in PR #19016:
URL: https://github.com/apache/nuttx/pull/19016#discussion_r3341404787


##########
libs/libc/dirent/lib_readdir.c:
##########
@@ -67,11 +68,22 @@ FAR struct dirent *readdir(DIR *dirp)
       return NULL;
     }
 
+  /* Save errno so it can be restored on end-of-directory.  POSIX requires
+   * errno to be unchanged at EOF, but the read() path may not preserve it.
+   */
+
+  errcode = get_errno();
+
   ret = read(dirp->fd, &dirp->entry, sizeof(struct dirent));
-  if (ret <= 0)
+  if (ret == 0)

Review Comment:
   Agreed ideally the lower layer shouldn't dirty errno, but with many 
filesystem backends that's hard to guarantee. so guarding here is reasonable,  
I have seen similar practices elsewhere. 
https://github.com/bminor/glibc/blob/04e750e75b73957cf1c791535a3f4319534a52fc/sysdeps/unix/sysv/linux/readdir.c#L45
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to