* lib/fts.c [!_LGPL_PACKAGE]: Don't include fcntl--.h twice.
[pspp] / lib / fts.c
index 6eca31089e4d53193ba0b7c38c3847923c1a8564..75bab3c8963bba05463db4604d8d667c62238e49 100644 (file)
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -155,7 +155,6 @@ static void leave_dir (FTS *fts, FTSENT *ent) {}
 static bool setup_dir (FTS *fts) { return true; }
 static void free_dir (FTS *fts) {}
 #else
-# include "fcntl--.h"
 # include "fts-cycle.c"
 #endif
 
@@ -396,7 +395,10 @@ fts_open (char * const *argv,
                p->fts_level = FTS_ROOTLEVEL;
                p->fts_parent = parent;
                p->fts_accpath = p->fts_name;
-               if (defer_stat) {
+               /* Even when defer_stat is true, be sure to stat the first
+                  command line argument, since fts_read (at least with
+                  FTS_XDEV) requires that.  */
+               if (defer_stat && root != NULL) {
                        p->fts_info = FTS_NSOK;
                        fts_set_stat_required(p, true);
                } else {
@@ -433,7 +435,7 @@ fts_open (char * const *argv,
        sp->fts_cur->fts_link = root;
        sp->fts_cur->fts_info = FTS_INIT;
        if (! setup_dir (sp))
-         goto mem3;
+               goto mem3;
 
        /*
         * If using chdir(2), grab a file descriptor pointing to dot to ensure
@@ -1005,6 +1007,8 @@ fts_build (register FTS *sp, int type)
        /* Read the directory, attaching each entry to the `link' pointer. */
        doadjust = false;
        for (head = tail = NULL, nitems = 0; dirp && (dp = readdir(dirp));) {
+               bool is_dir;
+
                if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
                        continue;
 
@@ -1070,7 +1074,6 @@ mem1:                             saved_errno = errno;
                } else
                        p->fts_accpath = p->fts_name;
 
-               bool is_dir;
                if (sp->fts_compar == NULL || ISSET(FTS_DEFER_STAT)) {
                        /* Record what fts_read will have to do with this
                           entry. In many cases, it will simply fts_stat it,