Lines Matching defs:sp
81 #define CLR(opt) (sp->fts_options &= ~(opt))
82 #define ISSET(opt) (sp->fts_options & (opt))
83 #define SET(opt) (sp->fts_options |= (opt))
85 #define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd))
126 FTS *sp;
141 sp = &priv->ftsp_fts;
142 sp->fts_compar = compar;
143 sp->fts_options = options;
156 if (fts_palloc(sp, MAX(fts_maxarglen(argv), MAXPATHLEN)))
160 if ((parent = fts_alloc(sp, "", 0)) == NULL)
172 p = fts_alloc(sp, *argv, len);
176 p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW));
200 root = fts_sort(sp, root, nitems);
207 if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL)
209 sp->fts_cur->fts_link = root;
210 sp->fts_cur->fts_info = FTS_INIT;
220 (sp->fts_rfd = _open(".", O_RDONLY | O_CLOEXEC, 0)) < 0)
223 return (sp);
227 mem2: free(sp->fts_path);
228 mem1: free(sp);
233 fts_load(FTS *sp, FTSENT *p)
246 memmove(sp->fts_path, p->fts_name, len + 1);
252 p->fts_accpath = p->fts_path = sp->fts_path;
253 sp->fts_dev = p->fts_dev;
257 __fts_close_44bsd(FTS *sp)
267 if (sp->fts_cur) {
268 for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) {
277 if (sp->fts_child)
278 fts_lfree(sp->fts_child);
279 if (sp->fts_array)
280 free(sp->fts_array);
281 free(sp->fts_path);
285 saved_errno = fchdir(sp->fts_rfd) ? errno : 0;
286 (void)_close(sp->fts_rfd);
291 free(sp);
298 free(sp);
311 __fts_read_44bsd(FTS *sp)
319 if (sp->fts_cur == NULL || ISSET(FTS_STOP))
323 p = sp->fts_cur;
331 p->fts_info = fts_stat(sp, p, 0);
343 p->fts_info = fts_stat(sp, p, 1);
359 (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) {
362 if (sp->fts_child) {
363 fts_lfree(sp->fts_child);
364 sp->fts_child = NULL;
371 if (sp->fts_child != NULL && ISSET(FTS_NAMEONLY)) {
373 fts_lfree(sp->fts_child);
374 sp->fts_child = NULL;
389 if (sp->fts_child != NULL) {
390 if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) {
393 for (p = sp->fts_child; p != NULL;
398 } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) {
403 p = sp->fts_child;
404 sp->fts_child = NULL;
418 if (FCHDIR(sp, sp->fts_rfd)) {
422 fts_load(sp, p);
423 return (sp->fts_cur = p);
434 p->fts_info = fts_stat(sp, p, 1);
446 name: t = sp->fts_path + NAPPEND(p->fts_parent);
449 return (sp->fts_cur = p);
463 return (sp->fts_cur = NULL);
467 sp->fts_path[p->fts_pathlen] = '\0';
475 if (FCHDIR(sp, sp->fts_rfd)) {
480 if (FCHDIR(sp, p->fts_symfd)) {
489 fts_safe_changedir(sp, p->fts_parent, -1, "..")) {
494 return (sp->fts_cur = p);
505 __fts_set_44bsd(FTS *sp, FTSENT *p, int instr)
517 __fts_children_44bsd(FTS *sp, int instr)
528 p = sp->fts_cur;
553 if (sp->fts_child != NULL)
554 fts_lfree(sp->fts_child);
571 return (sp->fts_child = fts_build(sp, instr));
575 sp->fts_child = fts_build(sp, instr);
581 return (sp->fts_child);
589 (__fts_get_clientptr_44bsd)(FTS *sp)
592 return (fts_get_clientptr(sp));
606 __fts_set_clientptr_44bsd(FTS *sp, void *clientptr)
609 sp->fts_clientptr = clientptr;
627 fts_build(FTS *sp, int type)
641 cur = sp->fts_cur;
673 if (fts_ufslinks(sp, cur))
705 if (fts_safe_changedir(sp, cur, _dirfd(dirp), NULL)) {
728 cp = sp->fts_path + len;
735 maxlen = sp->fts_pathlen - len;
746 if ((p = fts_alloc(sp, dp->d_name, (int)dnamlen)) == NULL)
749 oldaddr = sp->fts_path;
750 if (fts_palloc(sp, dnamlen + len + 1)) {
767 if (oldaddr != sp->fts_path) {
770 cp = sp->fts_path + len;
772 maxlen = sp->fts_pathlen - len;
791 p->fts_parent = sp->fts_cur;
823 p->fts_info = fts_stat(sp, p, 0);
849 fts_padjust(sp, head);
856 if (len == sp->fts_pathlen || nitems == 0)
870 FCHDIR(sp, sp->fts_rfd) :
871 fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) {
885 if (sp->fts_compar && nitems > 1)
886 head = fts_sort(sp, head, nitems);
891 fts_stat(FTS *sp, FTSENT *p, int follow)
986 fts_sort(FTS *sp, FTSENT *head, int nitems)
997 if (nitems > sp->fts_nitems) {
998 sp->fts_nitems = nitems + 40;
999 if ((sp->fts_array = reallocf(sp->fts_array,
1000 sp->fts_nitems * sizeof(FTSENT *))) == NULL) {
1001 sp->fts_nitems = 0;
1005 for (ap = sp->fts_array, p = head; p; p = p->fts_link)
1007 qsort(sp->fts_array, nitems, sizeof(FTSENT *), fts_compar);
1008 for (head = *(ap = sp->fts_array); --nitems; ++ap)
1015 fts_alloc(FTS *sp, char *name, int namelen)
1051 p->fts_path = sp->fts_path;
1057 p->fts_fts = sp;
1080 fts_palloc(FTS *sp, size_t more)
1083 sp->fts_pathlen += more + 256;
1089 if (sp->fts_pathlen < 0 || sp->fts_pathlen >= USHRT_MAX) {
1090 if (sp->fts_path)
1091 free(sp->fts_path);
1092 sp->fts_path = NULL;
1096 sp->fts_path = reallocf(sp->fts_path, sp->fts_pathlen);
1097 return (sp->fts_path == NULL);
1105 fts_padjust(FTS *sp, FTSENT *head)
1108 char *addr = sp->fts_path;
1118 for (p = sp->fts_child; p; p = p->fts_link)
1145 fts_safe_changedir(FTS *sp, FTSENT *p, int fd, char *path)
1177 fts_ufslinks(FTS *sp, const FTSENT *ent)
1182 priv = (struct _fts_private *)sp;