Lines Matching defs:sp
71 #define CLR(opt) (sp->fts_options &= ~(opt))
72 #define ISSET(opt) (sp->fts_options & (opt))
73 #define SET(opt) (sp->fts_options |= (opt))
75 #define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd))
116 FTS *sp;
136 sp = &priv->ftsp_fts;
137 sp->fts_compar = compar;
138 sp->fts_options = options;
151 if (fts_palloc(sp, MAX(fts_maxarglen(argv), MAXPATHLEN)))
155 if ((parent = fts_alloc(sp, "", 0)) == NULL)
163 p = fts_alloc(sp, *argv, len);
167 p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW), -1);
191 root = fts_sort(sp, root, nitems);
198 if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL)
200 sp->fts_cur->fts_link = root;
201 sp->fts_cur->fts_info = FTS_INIT;
211 (sp->fts_rfd = _open(".", O_RDONLY | O_CLOEXEC, 0)) < 0)
214 return (sp);
218 mem2: free(sp->fts_path);
219 mem1: free(sp);
224 fts_load(FTS *sp, FTSENT *p)
237 memmove(sp->fts_path, p->fts_name, len + 1);
243 p->fts_accpath = p->fts_path = sp->fts_path;
244 sp->fts_dev = p->fts_dev;
248 fts_close(FTS *sp)
258 if (sp->fts_cur) {
259 for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) {
268 if (sp->fts_child)
269 fts_lfree(sp->fts_child);
270 if (sp->fts_array)
271 free(sp->fts_array);
272 free(sp->fts_path);
276 saved_errno = fchdir(sp->fts_rfd) ? errno : 0;
277 (void)_close(sp->fts_rfd);
282 free(sp);
289 free(sp);
302 fts_read(FTS *sp)
310 if (sp->fts_cur == NULL || ISSET(FTS_STOP))
314 p = sp->fts_cur;
322 p->fts_info = fts_stat(sp, p, 0, -1);
334 p->fts_info = fts_stat(sp, p, 1, -1);
350 (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) {
353 if (sp->fts_child) {
354 fts_lfree(sp->fts_child);
355 sp->fts_child = NULL;
362 if (sp->fts_child != NULL && ISSET(FTS_NAMEONLY)) {
364 fts_lfree(sp->fts_child);
365 sp->fts_child = NULL;
380 if (sp->fts_child != NULL) {
381 if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) {
384 for (p = sp->fts_child; p != NULL;
389 } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) {
394 p = sp->fts_child;
395 sp->fts_child = NULL;
407 if (FCHDIR(sp, sp->fts_rfd)) {
412 fts_load(sp, p);
413 return (sp->fts_cur = p);
426 p->fts_info = fts_stat(sp, p, 1, -1);
440 name: t = sp->fts_path + NAPPEND(p->fts_parent);
443 return (sp->fts_cur = p);
457 return (sp->fts_cur = NULL);
461 sp->fts_path[p->fts_pathlen] = '\0';
469 if (FCHDIR(sp, sp->fts_rfd)) {
474 if (FCHDIR(sp, p->fts_symfd)) {
483 fts_safe_changedir(sp, p->fts_parent, -1, "..")) {
489 return (sp->fts_cur = p);
500 fts_set(FTS *sp, FTSENT *p, int instr)
512 fts_children(FTS *sp, int instr)
523 p = sp->fts_cur;
548 if (sp->fts_child != NULL)
549 fts_lfree(sp->fts_child);
566 return (sp->fts_child = fts_build(sp, instr));
570 sp->fts_child = fts_build(sp, instr);
571 serrno = (sp->fts_child == NULL) ? errno : 0;
579 return (sp->fts_child);
587 (fts_get_clientptr)(FTS *sp)
590 return (fts_get_clientptr(sp));
604 fts_set_clientptr(FTS *sp, void *clientptr)
607 sp->fts_clientptr = clientptr;
625 fts_build(FTS *sp, int type)
639 cur = sp->fts_cur;
671 if (fts_ufslinks(sp, cur))
703 if (fts_safe_changedir(sp, cur, _dirfd(dirp), NULL)) {
726 cp = sp->fts_path + len;
733 maxlen = sp->fts_pathlen - len;
744 if ((p = fts_alloc(sp, dp->d_name, dnamlen)) == NULL)
747 oldaddr = sp->fts_path;
748 if (fts_palloc(sp, dnamlen + len + 1)) {
765 if (oldaddr != sp->fts_path) {
768 cp = sp->fts_path + len;
770 maxlen = sp->fts_pathlen - len;
774 p->fts_parent = sp->fts_cur;
803 p->fts_info = fts_stat(sp, p, 0, _dirfd(dirp));
806 p->fts_info = fts_stat(sp, p, 0, -1);
833 fts_padjust(sp, head);
840 sp->fts_path[cur->fts_pathlen] = '\0';
851 FCHDIR(sp, sp->fts_rfd) :
852 fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) {
866 if (sp->fts_compar && nitems > 1)
867 head = fts_sort(sp, head, nitems);
872 fts_stat(FTS *sp, FTSENT *p, int follow, int dfd)
974 fts_sort(FTS *sp, FTSENT *head, size_t nitems)
985 if (nitems > sp->fts_nitems) {
986 sp->fts_nitems = nitems + 40;
987 if ((sp->fts_array = reallocf(sp->fts_array,
988 sp->fts_nitems * sizeof(FTSENT *))) == NULL) {
989 sp->fts_nitems = 0;
993 for (ap = sp->fts_array, p = head; p; p = p->fts_link)
995 qsort(sp->fts_array, nitems, sizeof(FTSENT *), fts_compar);
996 for (head = *(ap = sp->fts_array); --nitems; ++ap)
1003 fts_alloc(FTS *sp, char *name, size_t namelen)
1039 p->fts_path = sp->fts_path;
1045 p->fts_fts = sp;
1068 fts_palloc(FTS *sp, size_t more)
1071 sp->fts_pathlen += more + 256;
1072 sp->fts_path = reallocf(sp->fts_path, sp->fts_pathlen);
1073 return (sp->fts_path == NULL);
1081 fts_padjust(FTS *sp, FTSENT *head)
1084 char *addr = sp->fts_path;
1094 for (p = sp->fts_child; p; p = p->fts_link)
1121 fts_safe_changedir(FTS *sp, FTSENT *p, int fd, char *path)
1154 fts_ufslinks(FTS *sp, const FTSENT *ent)
1159 priv = (struct _fts_private *)sp;