fix silly indirect-through-zero bug
[unix-history] / usr / src / usr.sbin / mtree / verify.c
index 27ae3dd..1bb6e46 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)verify.c   5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)verify.c   5.9 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -34,43 +34,38 @@ vwalk()
        register FTS *t;
        register FTSENT *p;
        register NODE *ep, *level;
        register FTS *t;
        register FTSENT *p;
        register NODE *ep, *level;
+       char *argv[2];
+       int ftsdepth = 0, specdepth = 0;
 
 
-       if (!(t = ftsopen(".", ftsoptions, (int (*)())NULL))) {
+       argv[0] = ".";
+       argv[1] = (char *)NULL;
+       if (!(t = fts_open(argv, ftsoptions, (int (*)())NULL))) {
                (void)fprintf(stderr,
                (void)fprintf(stderr,
-                   "mtree: ftsopen: %s.\n", strerror(errno));
+                   "mtree: fts_open: %s.\n", strerror(errno));
                exit(1);
        }
        level = root;
                exit(1);
        }
        level = root;
-       while (p = ftsread(t)) {
+       while (p = fts_read(t)) {
                switch(p->fts_info) {
                case FTS_D:
                        if (!strcmp(p->fts_name, "."))
                                continue;
                switch(p->fts_info) {
                case FTS_D:
                        if (!strcmp(p->fts_name, "."))
                                continue;
+                       ftsdepth++; 
                        break;
                        break;
-               case FTS_DC:
-                       (void)fprintf(stderr,
-                           "mtree: directory cycle: %s.\n", RP(p));
-                       continue;
-               case FTS_DNR:
-                       (void)fprintf(stderr,
-                           "mtree: %s: unable to read.\n", RP(p));
-                       continue;
-               case FTS_DNX:
-                       (void)fprintf(stderr,
-                           "mtree: %s: unable to search.\n", RP(p));
-                       continue;
                case FTS_DP:
                case FTS_DP:
-                       for (level = level->parent; level->prev;
-                           level = level->prev);
+                       ftsdepth--; 
+                       if (specdepth > ftsdepth) {
+                               for (level = level->parent; level->prev;
+                                     level = level->prev);  
+                               specdepth--;
+                       }
                        continue;
                        continue;
+               case FTS_DNR:
                case FTS_ERR:
                case FTS_ERR:
+               case FTS_NS:
                        (void)fprintf(stderr, "mtree: %s: %s.\n",
                            RP(p), strerror(errno));
                        continue;
                        (void)fprintf(stderr, "mtree: %s: %s.\n",
                            RP(p), strerror(errno));
                        continue;
-               case FTS_NS:
-                       (void)fprintf(stderr,
-                           "mtree: can't stat: %s.\n", RP(p));
-                       continue;
                default:
                        if (dflag)
                                continue;
                default:
                        if (dflag)
                                continue;
@@ -82,15 +77,18 @@ vwalk()
                            !strcmp(ep->name, p->fts_name)) {
                                ep->flags |= F_VISIT;
                                if (ep->flags & F_IGN) {
                            !strcmp(ep->name, p->fts_name)) {
                                ep->flags |= F_VISIT;
                                if (ep->flags & F_IGN) {
-                                       (void)ftsset(t, p, FTS_SKIP);
+                                       (void)fts_set(t, p, FTS_SKIP);
                                        continue;
                                }
                                compare(ep->name, ep, p);
                                if (ep->child && ep->type == F_DIR &&
                                        continue;
                                }
                                compare(ep->name, ep, p);
                                if (ep->child && ep->type == F_DIR &&
-                                   p->fts_info == FTS_D)
+                                   p->fts_info == FTS_D) {
                                        level = ep->child;
                                        level = ep->child;
+                                       specdepth++;
+                               }
                                break;
                        }
                                break;
                        }
+
                if (ep)
                        continue;
                if (!eflag) {
                if (ep)
                        continue;
                if (!eflag) {
@@ -104,8 +102,9 @@ vwalk()
                        }
                        (void)putchar('\n');
                }
                        }
                        (void)putchar('\n');
                }
-               (void)ftsset(t, p, FTS_SKIP);
+               (void)fts_set(t, p, FTS_SKIP);
        }
        }
+       (void)fts_close(t);
 }
 
 miss(p, tail)
 }
 
 miss(p, tail)