On 2025-01-13 00:05, Lasse Collin wrote:

I pondered it before sending the patch. POSIX.1-2024 readdir() [1]:

     [EOVERFLOW]
         One of the values in the structure to be returned cannot be
         represented correctly.

Yes, but the list of error numbers in the readdir ERRORS section is not exhaustive. For example, readdir can plausibly fail with EIO even though EIO is not in the list. See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/V2_chap02.html#tag_16_03>, which says "Implementations may support additional errors not included in this list, may generate errors included in this list under circumstances other than those described here, or may contain extensions or limitations that prevent some errors from occurring."

EILSEQ is more-appropriate than EOVERFLOW here, so I'd use it.


In GNU coreutils, src/ls.c, print_dir() has a loop that calls
readdir().[2] It handles two errno values specially:

  - ENOENT is treated the same as successfully reaching the end of
    the directory.

  - EOVERFLOW results in an error message but directory reading is
    continued still.

The EOVERFLOW treatment is buggy because errno might have changed since readdir was called, and now that I'm looking into it also that ENOENT treatment is obsolescent on GNU/Linux, and Gnulib (and therefore Coreutils) is not consistent about working around the obsolescent bug. I installed a Gnulib patch to fix that inconsistency, here:

https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=5a2d28dfb0bd327a491bf4eaea41ea861d43d771

and a related patch into Coreutils, which fixes both the EOVERFLOW bug and the ENOENT inconstency, here:

https://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=0032e336e50c86186a01dbfa77364bc9c12235c1


If readdir() returns the more logical sounding EILSEQ, it means that
GNU ls won't attempt to list the remaining directory entries.

Oh, that's OK, we'd just change GNU ls. This would make for a better 'ls' for the user, as the diagnostics would be more informative.

PS. As you mention, it's fine (and indeed a good idea) to delay the EILSEQ error to the end, as too much code mistakenly treats any null return from readdir as EOF.



Reply via email to