- /*
- * Cycle detection is done as soon as we find a directory. Detection
- * is by brute force; if the tree gets deep enough or the number of
- * symbolic links to directories high enough something faster might
- * be worthwhile.
- */
- if (S_ISDIR(p->fts_statb.st_mode)) {
- register FTSENT *t;
- register dev_t dev;
- register ino_t ino;
-
- dev = p->fts_statb.st_dev;
- ino = p->fts_statb.st_ino;
- for (t = p->fts_parent; t->fts_level > FTS_ROOTLEVEL;
- t = t->fts_parent)
- if (ino == t->fts_statb.st_ino &&
- dev == t->fts_statb.st_dev) {
- sp->fts_savelink = p->fts_link;
- p->fts_link = t;
- return(FTS_DC);
+ if (S_ISDIR(sbp->st_mode)) {
+ /*
+ * Set the device/inode. Used to find cycles and check for
+ * crossing mount points. Also remember the link count, used
+ * in fts_build to limit the number of stat calls. It is
+ * understood that these fields are only referenced if fts_info
+ * is set to FTS_D.
+ */
+ dev = p->fts_dev = sbp->st_dev;
+ ino = p->fts_ino = sbp->st_ino;
+ p->fts_nlink = sbp->st_nlink;
+
+ if (ISDOT(p->fts_name))
+ return (FTS_DOT);
+
+ /*
+ * Cycle detection is done by brute force when the directory
+ * is first encountered. If the tree gets deep enough or the
+ * number of symbolic links to directories is high enough,
+ * something faster might be worthwhile.
+ */
+ for (t = p->fts_parent;
+ t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent)
+ if (ino == t->fts_ino && dev == t->fts_dev) {
+ p->fts_cycle = t;
+ return (FTS_DC);