From 0032e336e50c86186a01dbfa77364bc9c12235c1 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 13 Jan 2025 10:43:06 -0800 Subject: [PATCH] ls: readdir errno fixes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * src/ls.c (print_dir): Fix bug: file_failure can set errno to something other than EOVERFLOW but the code assumed it didn’t. Also, omit ENOENT bug workaround with glibc 2.3 and later, for consistency with Gnulib. --- src/ls.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/ls.c b/src/ls.c index 50937071bf..a64ed57ab2 100644 --- a/src/ls.c +++ b/src/ls.c @@ -3089,9 +3089,6 @@ print_dir (char const *name, char const *realname, bool command_line_arg) and when readdir simply finds that there are no more entries. */ errno = 0; next = readdir (dirp); - /* Some readdir()s do not absorb ENOENT (dir deleted but open). */ - if (errno == ENOENT) - errno = 0; if (next) { if (! file_ignored (next->d_name)) @@ -3122,14 +3119,21 @@ print_dir (char const *name, char const *realname, bool command_line_arg) } } } - else if (errno != 0) + else { + int err = errno; + if (err == 0) + 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 (err == ENOENT) + break; +#endif file_failure (command_line_arg, _("reading directory %s"), name); - if (errno != EOVERFLOW) + if (err != EOVERFLOW) break; } - else - break; /* When processing a very large directory, and since we've inhibited interrupts, this loop would take so long that ls would be annoyingly -- 2.47.3