]> git.cameronkatri.com Git - mandoc.git/blobdiff - compat_fts.c
Do not confuse .Bl -column lists that just broken another block
[mandoc.git] / compat_fts.c
index 2203f360772f9fd84303b3a7fd3efe865d1d3a2f..194c565524607ae343da048d1f8657fd0221f933 100644 (file)
@@ -6,8 +6,8 @@ int dummy;
 
 #else
 
-/*     $Id: compat_fts.c,v 1.5 2014/12/11 09:05:01 schwarze Exp $      */
-/*     $OpenBSD: fts.c,v 1.49 2014/11/23 00:14:22 guenther Exp $       */
+/*     $Id: compat_fts.c,v 1.8 2015/02/07 07:53:01 schwarze Exp $      */
+/*     $OpenBSD: fts.c,v 1.50 2015/01/16 16:48:51 deraadt Exp $        */
 
 /*-
  * Copyright (c) 1990, 1993, 1994
@@ -38,7 +38,6 @@ int dummy;
  * SUCH DAMAGE.
  */
 
-#include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 
@@ -51,6 +50,8 @@ int dummy;
 #include <unistd.h>
 #include "compat_fts.h"
 
+#define MAXIMUM(a, b)  (((a) > (b)) ? (a) : (b))
+
 static FTSENT  *fts_alloc(FTS *, const char *, size_t);
 static FTSENT  *fts_build(FTS *);
 static void     fts_lfree(FTSENT *);
@@ -62,6 +63,12 @@ static unsigned short         fts_stat(FTS *, FTSENT *);
 static int      fts_safe_changedir(FTS *, FTSENT *, int, const char *);
 
 #define        ISDOT(a)        (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))
+#ifndef        O_DIRECTORY
+#define        O_DIRECTORY     0
+#endif
+#ifndef        O_CLOEXEC
+#define        O_CLOEXEC       0
+#endif
 
 #define        CLR(opt)        (sp->fts_options &= ~(opt))
 #define        ISSET(opt)      (sp->fts_options & (opt))
@@ -93,7 +100,7 @@ fts_open(char * const *argv, int options, void *dummy)
         * Start out with 1K of path space, and enough, in any case,
         * to hold the user's paths.
         */
-       if (fts_palloc(sp, MAX(fts_maxarglen(argv), PATH_MAX)))
+       if (fts_palloc(sp, MAXIMUM(fts_maxarglen(argv), PATH_MAX)))
                goto mem1;
 
        /* Allocate/initialize root's parent. */
@@ -407,7 +414,7 @@ fts_build(FTS *sp)
        DIR *dirp;
        void *oldaddr;
        size_t dlen, len, maxlen;
-       int nitems, cderrno, descend, level, nlinks, nostat, doadjust;
+       int nitems, cderrno, descend, level, doadjust;
        int saved_errno;
        char *cp;
 
@@ -424,14 +431,6 @@ fts_build(FTS *sp)
                return (NULL);
        }
 
-       /*
-        * Nlinks is the number of possible entries of type directory in the
-        * directory if we're cheating on stat calls, 0 if we're not doing
-        * any stat calls at all, -1 if we're doing stats on everything.
-        */
-       nlinks = -1;
-       nostat = 0;
-
        /*
         * If we're going to need to stat anything or we want to descend
         * and stay in the directory, chdir.  If this fails we keep going,
@@ -449,8 +448,7 @@ fts_build(FTS *sp)
         */
        cderrno = 0;
        if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) {
-               if (nlinks)
-                       cur->fts_errno = errno;
+               cur->fts_errno = errno;
                cur->fts_flags |= FTS_DONTCHDIR;
                descend = 0;
                cderrno = errno;
@@ -545,21 +543,9 @@ mem1:                              saved_errno = errno;
                }
 
                if (cderrno) {
-                       if (nlinks) {
-                               p->fts_info = FTS_NS;
-                               p->fts_errno = cderrno;
-                       } else
-                               p->fts_info = FTS_NSOK;
+                       p->fts_info = FTS_NS;
+                       p->fts_errno = cderrno;
                        p->fts_accpath = cur->fts_accpath;
-               } else if (nlinks == 0
-#ifdef DT_DIR
-                   || (nostat &&
-                   dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN)
-#endif
-                   ) {
-                       p->fts_accpath =
-                           ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name;
-                       p->fts_info = FTS_NSOK;
                } else {
                        /* Build a file name for fts_stat to stat. */
                        if (ISSET(FTS_NOCHDIR)) {
@@ -569,11 +555,6 @@ mem1:                              saved_errno = errno;
                                p->fts_accpath = p->fts_name;
                        /* Stat it. */
                        p->fts_info = fts_stat(sp, p);
-
-                       /* Decrement link count if applicable. */
-                       if (nlinks > 0 && (p->fts_info == FTS_D ||
-                           p->fts_info == FTS_DC || p->fts_info == FTS_DOT))
-                               --nlinks;
                }
 
                /* We walk in directory order so "ls -f" doesn't get upset. */