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.
This commit is contained in:
Paul Eggert
2025-01-13 10:18:05 -08:00
parent 54636e00ee
commit 5a2d28dfb0
5 changed files with 39 additions and 1 deletions
+13
View File
@@ -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, Im not
sure its 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.
+5
View 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
+5
View 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
+7
View File
@@ -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
+9 -1
View 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. */