]> Savannah Git Hosting - gnulib.git/commitdiff
fts, savedir: avoid glibc 2.2 readdir ENOENT bug
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 13 Jan 2025 18:17:21 +0000 (10:17 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 13 Jan 2025 18:18:05 +0000 (10:18 -0800)
This is mostly to document the bug.
If these old platforms were still common I suppose we should
change the readdir module to work around it.  However, I’m not
sure it’s worth the hassle at this point.
* doc/posix-functions/readdir.texi, doc/posix-functions/readdir_r.texi:
Document the bug.
* lib/fts.c (fts_build):
* lib/savedir.c (streamsavedir):
Work around it.

ChangeLog
doc/posix-functions/readdir.texi
doc/posix-functions/readdir_r.texi
lib/fts.c
lib/savedir.c

index bf54cbd8368db3aec7a9833223129108ca2a913c..d4e849e8a8d5be8c899fec038327d598b341d690 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2025-01-13  Paul Eggert  <eggert@cs.ucla.edu>
+
+       fts, savedir: avoid glibc 2.2 readdir ENOENT bug
+       This is mostly to document the bug.
+       If these old platforms were still common I suppose we should
+       change the readdir module to work around it.  However, I’m not
+       sure it’s worth the hassle at this point.
+       * doc/posix-functions/readdir.texi, doc/posix-functions/readdir_r.texi:
+       Document the bug.
+       * lib/fts.c (fts_build):
+       * lib/savedir.c (streamsavedir):
+       Work around it.
+
 2025-01-13  Bruno Haible  <bruno@clisp.org>
 
        stdlib-h: Define WCOREDUMP, as required by POSIX:2024.
index 97d83ce9469de70703d79833c33663efb1afdb91..3e28b35bde8a1a73e6510a56d1a488460af85fa3 100644 (file)
@@ -30,4 +30,9 @@ formerly attempted to cater to these older systems, this caused
 misbehavior on standard systems and so Gnulib does not attempt to
 cater to them any more.  If you know of any problems caused by this,
 please send a bug report.
+@item
+When reading a directory that has been removed,
+this function sets @code{errno} to @code{ENOENT}
+instead of leaving @code{errno} alone to indicate EOF:
+glibc 2.2.5.
 @end itemize
index 76904314d7c4ac89dff0bd347532e7517cad357c..c1e8aaad09af42b60f23e77088ae9bc3310e9a64 100644 (file)
@@ -28,4 +28,9 @@ Portability problems not fixed by Gnulib:
 @item
 This function is missing on some platforms:
 Minix 3.1.8, mingw, MSVC 14.
+@item
+When reading a directory that has been removed,
+this function sets @code{errno} to @code{ENOENT}
+instead of leaving @code{errno} alone to indicate EOF:
+glibc 2.2.5.
 @end itemize
index d31443902b31d1377b5f6730d213ddf6fd49f0d3..b611e997d469dd091ad24f4347d4f33f6c000fa1 100644 (file)
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -1443,6 +1443,13 @@ fts_build (register FTS *sp, int type)
                 __set_errno (0);
                 struct dirent *dp = readdir(cur->fts_dirp);
                 if (dp == NULL) {
+                        /* Some readdir()s do not absorb ENOENT (dir
+                           deleted but open).  This bug was fixed in
+                           glibc 2.3 (2002).  */
+#if ! (2 < __GLIBC__ + (3 <= __GLIBC_MINOR__))
+                        if (errno == ENOENT)
+                          errno = 0;
+#endif
                         if (errno) {
                                 cur->fts_errno = errno;
                                 /* If we've not read any items yet, treat
index 93c2c36f7d59dbf4268db3fa0e53c2a7ad901dd8..40e3b8cebcea64da76b9ca99e76c0158eb3e5f32 100644 (file)
@@ -123,7 +123,15 @@ streamsavedir (DIR *dirp, enum savedir_option option)
       errno = 0;
       dp = readdir (dirp);
       if (! dp)
-        break;
+        {
+          /* Some readdir()s do not absorb ENOENT (dir deleted but open).
+             This bug was fixed in glibc 2.3 (2002).  */
+#if ! (2 < __GLIBC__ + (3 <= __GLIBC_MINOR__))
+          if (errno == ENOENT)
+            errno = 0;
+#endif
+          break;
+        }
 
       /* Skip "", ".", and "..".  "" is returned by at least one buggy
          implementation: Solaris 2.4 readdir on NFS file systems.  */