- /* Build a file name for fts_stat to stat. */
- if (ISSET(FTS_NOCHDIR)) {
- p->fts_accpath = p->fts_path;
- memmove(cp, p->fts_name, p->fts_namelen + 1);
- } else
- p->fts_accpath = p->fts_name;
- /* Stat it. */
- p->fts_info = fts_stat(sp, p, 0);
-
- /* 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 need to know all file types values that d_type may
+ * be set to. So if that changes, the following needs
+ * to be modified appropriately.
+ */
+ switch(dostat | dp->d_type) {
+ case (F_STATDIR | DT_UNKNOWN):
+ case (F_STATDIR | DT_DIR):
+ case (F_STATDIRSYM | DT_UNKNOWN):
+ case (F_STATDIRSYM | DT_DIR):
+ case (F_STATDIRSYM | DT_LNK):
+ case (F_ALWAYSSTAT | DT_UNKNOWN):
+ case (F_ALWAYSSTAT | DT_FIFO):
+ case (F_ALWAYSSTAT | DT_CHR):
+ case (F_ALWAYSSTAT | DT_DIR):
+ case (F_ALWAYSSTAT | DT_BLK):
+ case (F_ALWAYSSTAT | DT_REG):
+ case (F_ALWAYSSTAT | DT_LNK):
+ case (F_ALWAYSSTAT | DT_SOCK):
+ case (F_ALWAYSSTAT | DT_WHT):
+ case (F_D_TYPE | DT_UNKNOWN):
+ case (F_D_TYPE | DT_DIR):
+ case (F_D_TYPESYM | DT_UNKNOWN):
+ case (F_D_TYPESYM | DT_DIR):
+ case (F_D_TYPESYM | DT_LNK):
+ /* Build a file name for fts_stat to stat. */
+ if (ISSET(FTS_NOCHDIR)) {
+ p->fts_accpath = p->fts_path;
+ memmove(cp, p->fts_name, p->fts_namelen + 1);
+ } else
+ p->fts_accpath = p->fts_name;
+ /* Stat it. */
+ p->fts_info = fts_stat(sp, p, 0);
+ break;
+ case (F_D_TYPE | DT_FIFO):
+ case (F_D_TYPE | DT_CHR):
+ case (F_D_TYPE | DT_BLK):
+ case (F_D_TYPE | DT_SOCK):
+ case (F_D_TYPESYM | DT_FIFO):
+ case (F_D_TYPESYM | DT_CHR):
+ case (F_D_TYPESYM | DT_BLK):
+ case (F_D_TYPESYM | DT_SOCK):
+ p->fts_info = FTS_DEFAULT;
+ goto common_no_stat;
+ case (F_D_TYPE | DT_REG):
+ case (F_D_TYPESYM | DT_REG):
+ p->fts_info = FTS_F;
+ goto common_no_stat;
+ case (F_D_TYPE | DT_LNK):
+ p->fts_info = FTS_SL;
+ goto common_no_stat;
+ case (F_D_TYPE | DT_WHT):
+ case (F_D_TYPESYM | DT_WHT):
+ p->fts_info = FTS_W;
+ goto common_no_stat;
+ default:
+ /* No stat necessary */
+ p->fts_info = FTS_NSOK;
+common_no_stat:
+ p->fts_accpath =
+ ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name;
+ break;
+ }