Lines Matching refs:fts

177 node(FTS* fts, FTSENT* parent, register char* name, register size_t namelen)  in node()  argument
182 if (fts->free && namelen < MINNAME) in node()
184 f = fts->free; in node()
185 fts->free = f->fts_link; in node()
192 fts->fts_errno = errno; in node()
193 fts->state = FTS_error; in node()
196 f->fts = fts; in node()
460 popdirs(FTS* fts) in popdirs() argument
471 if (!(f = fts->curdir) || f->fts_level < 0) in popdirs()
477 while (fts->nd > 0) in popdirs()
479 for (s = buf; s < e && fts->nd > 0; fts->nd--) in popdirs()
481 if (fts->pwd) in popdirs()
484 verify |= fts->pwd->symlink; in popdirs()
486 fts->pwd = fts->pwd->pwd; in popdirs()
504 info(FTS* fts, register FTSENT* f, const char* path, struct stat* sp, int flags) in info() argument
524 if ((flags & FTS_NOSTAT) && !fts->fs3d) in info()
582 toplist(FTS* fts, register char* const* pathnames) in toplist() argument
593 if (fts->flags & FTS_NOSEEDOTDIR) in toplist()
594 fts->flags &= ~FTS_SEEDOTDIR; in toplist()
595 physical = (fts->flags & FTS_PHYSICAL); in toplist()
596 metaphysical = (fts->flags & (FTS_META|FTS_PHYSICAL)) == (FTS_META|FTS_PHYSICAL); in toplist()
604 if (!(f = node(fts, fts->parent, path, strlen(path)))) in toplist()
608 f->fts_namelen = (fts->flags & FTS_SEEDOTDIR) ? strlen(path) : (pathcanon(path, 0) - path); in toplist()
612 fts->flags |= FTS_SEEDOTDIR; in toplist()
616 if (fts->flags & FTS_NOSEEDOTDIR) in toplist()
618 fts->flags &= ~FTS_SEEDOTDIR; in toplist()
632 fts->flags |= FTS_SEEDOTDIR; in toplist()
646 info(fts, f, path, f->fts_statp, fts->flags); in toplist()
657 info(fts, f, NiL, f->fts_statp, 0); in toplist()
676 order(FTS* fts) in order() argument
684 for (f = fts->todo; f; f = f->fts_link) in order()
685 root = search(f, root, fts->comparf, 1); in order()
687 fts->todo = top; in order()
697 resize(register FTS* fts, size_t inc) in resize() argument
707 n_old = fts->homesize; in resize()
708 fts->homesize = ((fts->homesize + inc + 4) / PATH_MAX + 1) * PATH_MAX; in resize()
709 if (!(newp = newof(0, char, fts->homesize, 0))) in resize()
711 fts->fts_errno = errno; in resize()
712 fts->state = FTS_error; in resize()
715 old = fts->home; in resize()
716 fts->home = newp; in resize()
718 if (fts->endbuf) in resize()
719 fts->endbuf = newp + fts->homesize - 4; in resize()
720 if (fts->path) in resize()
721 fts->path = newp + (fts->path - old); in resize()
722 if (fts->base) in resize()
723 fts->base = newp + (fts->base - old); in resize()
735 register FTS* fts; in fts_open() local
737 if (!(fts = newof(0, FTS, 1, sizeof(FTSENT)))) in fts_open()
739 fts->flags = flags; in fts_open()
740 fts->cd = (flags & FTS_NOCHDIR) ? 1 : -1; in fts_open()
741 fts->comparf = comparf; in fts_open()
742 fts->fs3d = fs3d(FS3D_TEST); in fts_open()
748 fts->homesize = 2 * PATH_MAX; in fts_open()
751 if (!(fts->home = newof(fts->home, char, fts->homesize, 0))) in fts_open()
753 free(fts); in fts_open()
756 if (fts->cd > 0 || getcwd(fts->home, fts->homesize)) in fts_open()
759 fts->homesize += PATH_MAX; in fts_open()
761 fts->cd = 1; in fts_open()
763 fts->endbuf = fts->home + fts->homesize - 4; in fts_open()
769 fts->parent = (FTSENT*)(fts + 1); in fts_open()
770 fts->parent->fts_info = FTS_D; in fts_open()
771 …memcpy(fts->parent->fts_accpath = fts->parent->fts_path = fts->parent->fts_name = fts->parent->nam… in fts_open()
772 fts->parent->fts_level = -1; in fts_open()
774 fts->parent->_fts_level = (short)fts->parent->fts_level; in fts_open()
776 fts->parent->fts_statp = &fts->parent->statb; in fts_open()
777 fts->parent->must = 2; in fts_open()
778 fts->parent->type = DT_UNKNOWN; in fts_open()
779 fts->path = fts->home + strlen(fts->home) + 1; in fts_open()
791 fts->todo = toplist(fts, v); in fts_open()
794 fts->todo = toplist(fts, pathnames); in fts_open()
795 if (!fts->todo || fts->todo->fts_info == FTS_NS && !fts->todo->fts_link) in fts_open()
797 fts_close(fts); in fts_open()
800 return fts; in fts_open()
808 fts_read(register FTS* fts) in fts_read() argument
822 switch (fts->state) in fts_read()
827 f = fts->todo; in fts_read()
835 drop(fts, f); in fts_read()
840 fts->todo = f->fts_link; in fts_read()
841 drop(fts, f); in fts_read()
842 f = fts->todo; in fts_read()
854 if (!fts->state && fts->comparf) in fts_read()
855 order(fts); in fts_read()
856 if (!(f = fts->todo)) in fts_read()
866 fts->root = fts->top = fts->bot = 0; in fts_read()
874 fts->parent->fts_number = f->fts_number; in fts_read()
875 fts->parent->fts_pointer = f->fts_pointer; in fts_read()
876 fts->parent->fts_statp = f->fts_statp; in fts_read()
877 fts->parent->statb = *f->fts_statp; in fts_read()
878 f->fts_parent = fts->parent; in fts_read()
879 fts->diroot = 0; in fts_read()
880 if (fts->cd == 0) in fts_read()
881 pathcd(fts->home, NiL); in fts_read()
882 else if (fts->cd < 0) in fts_read()
883 fts->cd = 0; in fts_read()
884 fts->pwd = f->fts_parent; in fts_read()
885 fts->curdir = fts->cd ? 0 : f->fts_parent; in fts_read()
886 *(fts->base = fts->path) = 0; in fts_read()
893 if (fts->cd < 0) in fts_read()
895 fts->cd = setdir(fts->home, fts->path); in fts_read()
896 fts->pwd = f->fts_parent; in fts_read()
897 fts->curdir = fts->cd ? 0 : f->fts_parent; in fts_read()
904 if ((fts->baselen = f->fts_namelen) >= (fts->endbuf - fts->base) && resize(fts, fts->baselen)) in fts_read()
906 memcpy(fts->base, f->name, fts->baselen + 1); in fts_read()
907 fts->name = fts->cd ? fts->path : fts->base; in fts_read()
918 …if ((fts->diroot = search(f, fts->diroot, statcmp, 0)) != f || f->fts_level > 0 && (t = f) && stat… in fts_read()
921 f->fts_cycle = fts->diroot; in fts_read()
923 …else if (!(fts->flags & FTS_TOP) && (!(fts->flags & FTS_XDEV) || f->statb.st_dev == f->fts_parent-… in fts_read()
929 if (fts->base[fts->baselen - 1] != '/') in fts_read()
930 memcpy(fts->base + fts->baselen, "/.", 3); in fts_read()
931 if (!(fts->dir = opendir(fts->name))) in fts_read()
933 fts->base[fts->baselen] = 0; in fts_read()
934 if (!fts->dir && !(fts->dir = opendir(fts->name))) in fts_read()
939 if (f->nd || !(fts->flags & FTS_NOPREORDER)) in fts_read()
941 fts->current = f; in fts_read()
942 fts->link = f->fts_link; in fts_read()
944 f->fts_path = PATH(fts, fts->path, f->fts_level); in fts_read()
945 f->fts_pathlen = (fts->base - f->fts_path) + fts->baselen; in fts_read()
946 f->fts_accpath = ACCESS(fts, f); in fts_read()
947 fts->state = FTS_preorder_return; in fts_read()
958 if (!fts->dir || f->nd || f->status == FTS_SKIP) in fts_read()
960 if (fts->dir) in fts_read()
962 closedir(fts->dir); in fts_read()
963 fts->dir = 0; in fts_read()
965 fts->state = FTS_popstack; in fts_read()
973 if (fts->cd == 0) in fts_read()
975 if ((fts->cd = chdir(fts->name)) < 0) in fts_read()
976 pathcd(fts->home, NiL); in fts_read()
977 else if (fts->pwd != f) in fts_read()
979 f->pwd = fts->pwd; in fts_read()
980 fts->pwd = f; in fts_read()
982 fts->curdir = fts->cd < 0 ? 0 : f; in fts_read()
984 fts->nostat = fts->children > 1 || f->fts_info == FTS_DNX; in fts_read()
985 fts->cpname = fts->cd && !fts->nostat || !fts->children && !fts->comparf; in fts_read()
986 fts->dotdot = 0; in fts_read()
987 fts->endbase = fts->base + fts->baselen; in fts_read()
988 if (fts->endbase[-1] != '/') in fts_read()
989 *fts->endbase++ = '/'; in fts_read()
990 fts->current = f; in fts_read()
995 while (d = readdir(fts->dir)) in fts_read()
1002 fts->current->nlink--; in fts_read()
1003 if (!(fts->flags & FTS_SEEDOT)) in fts_read()
1009 fts->current->nlink--; in fts_read()
1010 if (fts->current->must == 1) in fts_read()
1011 fts->current->must = 0; in fts_read()
1012 if (!(fts->flags & FTS_SEEDOT)) in fts_read()
1027 if (!(f = node(fts, fts->current, s, i))) in fts_read()
1035 if (i >= fts->endbuf - fts->endbase) in fts_read()
1037 if (resize(fts, i)) in fts_read()
1039 fts->endbase = fts->base + fts->baselen; in fts_read()
1040 if (fts->endbase[-1] != '/') in fts_read()
1041 fts->endbase++; in fts_read()
1043 if (fts->cpname) in fts_read()
1045 memcpy(fts->endbase, s, i + 1); in fts_read()
1046 if (fts->cd) in fts_read()
1047 s = fts->path; in fts_read()
1056 f->fts_statp = fts->current->fts_statp; in fts_read()
1060 fts->dotdot = f; in fts_read()
1061 if (fts->current->fts_parent->fts_level < 0) in fts_read()
1063 f->fts_statp = &fts->current->fts_parent->statb; in fts_read()
1064 info(fts, f, s, f->fts_statp, 0); in fts_read()
1067 f->fts_statp = fts->current->fts_parent->fts_statp; in fts_read()
1071 …else if ((fts->nostat || SKIP(fts, f)) && (f->fts_info = FTS_NSOK) || info(fts, f, s, &f->statb, f… in fts_read()
1073 if (fts->comparf) in fts_read()
1074 fts->root = search(f, fts->root, fts->comparf, 1); in fts_read()
1075 else if (fts->children || f->fts_info == FTS_D || f->fts_info == FTS_SL) in fts_read()
1077 if (fts->top) in fts_read()
1078 fts->bot = fts->bot->fts_link = f; in fts_read()
1080 fts->top = fts->bot = f; in fts_read()
1088 f->fts_path = PATH(fts, fts->path, 1); in fts_read()
1089 f->fts_pathlen = fts->endbase - f->fts_path + f->fts_namelen; in fts_read()
1090 f->fts_accpath = ACCESS(fts, f); in fts_read()
1091 fts->previous = fts->current; in fts_read()
1092 fts->current = f; in fts_read()
1093 fts->state = FTS_terminal; in fts_read()
1102 closedir(fts->dir); in fts_read()
1103 fts->dir = 0; in fts_read()
1104 if (fts->root) in fts_read()
1105 getlist(&fts->top, &fts->bot, fts->root); in fts_read()
1106 if (fts->children) in fts_read()
1112 fts->base[fts->baselen] = 0; in fts_read()
1113 if (fts->cd <= 0) in fts_read()
1115 f = fts->current->fts_parent; in fts_read()
1116 if (fts->cd < 0 in fts_read()
1117 || f != fts->curdir in fts_read()
1118 || !fts->dotdot in fts_read()
1119 || !SAME(f->fts_statp, fts->dotdot->fts_statp) in fts_read()
1120 || fts->pwd && fts->pwd->symlink in fts_read()
1121 || (fts->cd = chdir("..")) < 0 in fts_read()
1124 || !SAME(&sb, fts->dotdot->fts_statp) in fts_read()
1127 fts->cd = setpdir(fts->home, fts->path, fts->base); in fts_read()
1128 if (fts->pwd) in fts_read()
1129 fts->pwd = fts->pwd->pwd; in fts_read()
1130 fts->curdir = fts->cd ? 0 : f; in fts_read()
1132 f = fts->current; in fts_read()
1133 fts->link = f->fts_link; in fts_read()
1134 f->fts_link = fts->top; in fts_read()
1135 f->fts_path = PATH(fts, fts->path, f->fts_level); in fts_read()
1136 f->fts_pathlen = (fts->base - f->fts_path) + f->fts_namelen; in fts_read()
1137 f->fts_accpath = ACCESS(fts, f); in fts_read()
1138 fts->state = FTS_children_return; in fts_read()
1145 fts->base[fts->baselen] = 0; in fts_read()
1146 if (fts->top) in fts_read()
1148 fts->bot->fts_link = fts->todo; in fts_read()
1149 fts->todo = fts->top; in fts_read()
1150 fts->top = 0; in fts_read()
1160 fts->nd = 0; in fts_read()
1161 f = fts->current; in fts_read()
1166 while (fts->todo && f == fts->todo) in fts_read()
1175 if (f != fts->diroot) in fts_read()
1176 fts->diroot = search(f, fts->diroot, statcmp, 0); in fts_read()
1177 fts->diroot = deleteroot(fts->diroot); in fts_read()
1178 if (f == fts->curdir) in fts_read()
1180 fts->nd++; in fts_read()
1181 fts->curdir = t; in fts_read()
1188 if (!(fts->flags & FTS_NOPOSTORDER) && in fts_read()
1196 if (fts->nd > 0) in fts_read()
1197 fts->cd = popdirs(fts); in fts_read()
1198 if (fts->cd < 0) in fts_read()
1199 fts->cd = setpdir(fts->home, fts->path, fts->base); in fts_read()
1200 fts->curdir = fts->cd ? 0 : t; in fts_read()
1202 f->fts_path = PATH(fts, fts->path, f->fts_level); in fts_read()
1203 f->fts_pathlen = (fts->base - f->fts_path) + f->fts_namelen; in fts_read()
1204 f->fts_accpath = ACCESS(fts, f); in fts_read()
1211 fts->link = f->fts_link; in fts_read()
1213 fts->state = FTS_popstack_return; in fts_read()
1222 if (fts->base > fts->path + t->fts_namelen) in fts_read()
1223 fts->base--; in fts_read()
1224 *fts->base = 0; in fts_read()
1225 fts->base -= t->fts_namelen; in fts_read()
1238 fts->todo = fts->todo->fts_link; in fts_read()
1239 drop(fts, f); in fts_read()
1248 if (fts->nd > 0 && popdirs(fts) < 0) in fts_read()
1250 pathcd(fts->home, NiL); in fts_read()
1251 fts->curdir = 0; in fts_read()
1252 fts->cd = -1; in fts_read()
1254 if (fts->todo) in fts_read()
1256 if (*fts->base) in fts_read()
1257 fts->base += f->fts_namelen; in fts_read()
1258 if (*(fts->base - 1) != '/') in fts_read()
1259 *fts->base++ = '/'; in fts_read()
1260 *fts->base = 0; in fts_read()
1261 f = fts->todo; in fts_read()
1262 fts->state = FTS_todo; in fts_read()
1269 f = fts->current; in fts_read()
1270 f->fts_link = fts->link; in fts_read()
1278 if (!n && fts->cd == 0) in fts_read()
1280 if ((fts->cd = chdir(fts->base)) < 0) in fts_read()
1281 pathcd(fts->home, NiL); in fts_read()
1282 else if (fts->pwd != f) in fts_read()
1284 f->pwd = fts->pwd; in fts_read()
1285 fts->pwd = f; in fts_read()
1287 fts->curdir = fts->cd ? 0 : f; in fts_read()
1294 if (fts->base[fts->baselen - 1] != '/') in fts_read()
1295 fts->base[fts->baselen] = '/'; in fts_read()
1296 for (fts->bot = 0, f = fts->top; f; ) in fts_read()
1299 if (fts->bot) in fts_read()
1300 fts->bot->fts_link = f->fts_link; in fts_read()
1302 fts->top = f->fts_link; in fts_read()
1303 drop(fts, f); in fts_read()
1304 f = fts->bot ? fts->bot->fts_link : fts->top; in fts_read()
1308 if (fts->children > 1 && i) in fts_read()
1311 info(fts, f, NiL, f->fts_statp, 0); in fts_read()
1312 else if (f->fts_info == FTS_NSOK && !SKIP(fts, f)) in fts_read()
1315 if (fts->cd) in fts_read()
1317 memcpy(fts->endbase, s, f->fts_namelen + 1); in fts_read()
1318 s = fts->path; in fts_read()
1320 info(fts, f, s, f->fts_statp, fts->flags); in fts_read()
1323 fts->bot = f; in fts_read()
1326 fts->children = 0; in fts_read()
1327 fts->state = FTS_children_resume; in fts_read()
1332 f = fts->todo; in fts_read()
1333 f->fts_link = fts->link; in fts_read()
1335 fts->state = FTS_popstack_resume; in fts_read()
1340 f = fts->current; in fts_read()
1341 f->fts_link = fts->link; in fts_read()
1352 info(fts, f, f->fts_accpath, f->fts_statp, 0); in fts_read()
1355 fts->state = FTS_preorder; in fts_read()
1365 if (fts->cd == 0 && f->fts_level == 0 && f->nd) in fts_read()
1366 fts->cd = -1; in fts_read()
1367 fts->state = FTS_preorder_resume; in fts_read()
1372 f = fts->current; in fts_read()
1378 info(fts, f, f->fts_accpath, f->fts_statp, 0); in fts_read()
1381 if (!(f->fts_link = fts->top)) in fts_read()
1382 fts->bot = f; in fts_read()
1383 fts->top = f; in fts_read()
1384 fts->current = fts->previous; in fts_read()
1385 fts->state = FTS_readdir; in fts_read()
1391 drop(fts, fts->current); in fts_read()
1392 fts->current = f; in fts_read()
1393 fts->state = FTS_readdir; in fts_read()
1402 fts->fts_errno = EINVAL; in fts_read()
1403 fts->state = FTS_error; in fts_read()
1412 if ((n = (*p->notifyf)(fts, f, p->context)) > 0) in fts_read()
1416 fts->fts_errno = EINVAL; in fts_read()
1417 fts->state = FTS_error; in fts_read()
1428 fts_set(register FTS* fts, register FTSENT* f, int status) in fts_set() argument
1430 if (fts || !f || f->fts->current != f) in fts_set()
1458 fts_children(register FTS* fts, int flags) in fts_children() argument
1462 switch (fts->state) in fts_children()
1467 if (fts->comparf) in fts_children()
1468 order(fts); in fts_children()
1469 fts->state = FTS_top_return; in fts_children()
1470 return fts->todo; in fts_children()
1474 fts->children = ((flags | fts->flags) & FTS_NOSTAT) ? 2 : 1; in fts_children()
1475 if (f = fts_read(fts)) in fts_children()
1522 fts_close(register FTS* fts) in fts_close() argument
1527 if (fts->dir) in fts_close()
1528 closedir(fts->dir); in fts_close()
1529 if (fts->cd == 0) in fts_close()
1530 pathcd(fts->home, NiL); in fts_close()
1531 free(fts->home); in fts_close()
1532 if (fts->state == FTS_children_return) in fts_close()
1533 fts->current->fts_link = fts->link; in fts_close()
1534 if (fts->top) in fts_close()
1536 fts->bot->fts_link = fts->todo; in fts_close()
1537 fts->todo = fts->top; in fts_close()
1539 for (f = fts->todo; f; f = x) in fts_close()
1544 for (f = fts->free; f; f = x) in fts_close()
1549 free(fts); in fts_close()