]> Savannah Git Hosting - gnulib.git/commitdiff
fts: fix errno handling if dirfd fails
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 26 Sep 2022 01:33:49 +0000 (18:33 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 26 Sep 2022 01:35:56 +0000 (18:35 -0700)
* lib/fts.c (fts_build): Use proper errno if dirfd failed.
Although I don’t know of any platform where dirfd can fail here,
we might as well get it right.

ChangeLog
lib/fts.c

index 24553445f6e24cb780c474bd3db8f9e1bbf3338d..6027e5ed94e6bda17b8c00cc91943d9198c226d2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2022-09-25  Paul Eggert  <eggert@cs.ucla.edu>
+
+       fts: fix errno handling if dirfd fails
+       * lib/fts.c (fts_build): Use proper errno if dirfd failed.
+       Although I don’t know of any platform where dirfd can fail here,
+       we might as well get it right.
+
 2022-09-25  Bruno Haible  <bruno@clisp.org>
 
        stdbool: Mostly revert last patch.
index 954cbb7b401d633604e04060e0fd475191baca56..5811f6ea207abfcaa5fb56be5aedcfdd02de7fe4 100644 (file)
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -1290,11 +1290,12 @@ fts_build (register FTS *sp, int type)
             dir_fd = dirfd (dp);
             if (dir_fd < 0)
               {
+                int dirfd_errno = errno;
                 closedir_and_clear (cur->fts_dirp);
                 if (type == BREAD)
                   {
                     cur->fts_info = FTS_DNR;
-                    cur->fts_errno = errno;
+                    cur->fts_errno = dirfd_errno;
                   }
                 return NULL;
               }