This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

readdir may not modify errno at EOF


When readdir returns NULL it is supposed to keep errno unmodified when EOF
was reached (and no error occured).  But __getdents may be changing it
even when sucessfull, so we need to save its value around the call.

Andreas.

2001-05-09  Andreas Schwab  <schwab@suse.de>

	* sysdeps/unix/readdir.c: Make sure we don't modify errno when we
	reached EOF.

--- sysdeps/unix/readdir.c.~1.18.~	Mon Aug 14 12:07:29 2000
+++ sysdeps/unix/readdir.c	Wed May  9 14:14:03 2001
@@ -39,6 +39,7 @@
 __READDIR (DIR *dirp)
 {
   DIRENT_TYPE *dp;
+  int saved_errno = errno;
 
   __libc_lock_lock (dirp->lock);
 
@@ -63,6 +64,9 @@
 	  bytes = __GETDENTS (dirp->fd, dirp->data, maxread);
 	  if (bytes <= 0)
 	    {
+	      /* Don't modifiy errno when reaching EOF.  */
+	      if (bytes == 0)
+		__set_errno (saved_errno);
 	      dp = NULL;
 	      break;
 	    }

-- 
Andreas Schwab                                  "And now for something
SuSE Labs                                        completely different."
Andreas.Schwab@suse.de
SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]