1N/A/*********************************************************************** 1N/A* This software is part of the ast package * 1N/A* Copyright (c) 1985-2011 AT&T Intellectual Property * 1N/A* and is licensed under the * 1N/A* Common Public License, Version 1.0 * 1N/A* by AT&T Intellectual Property * 1N/A* A copy of the License is available at * 1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 1N/A* Information and Software Systems Research * 1N/A* Glenn Fowler <gsf@research.att.com> * 1N/A* David Korn <dgk@research.att.com> * 1N/A* Phong Vo <kpv@research.att.com> * 1N/A***********************************************************************/ 1N/A * fts implementation unwound from the kpv ftwalk() of 1988-10-30 1N/A int cd;
/* chdir status */ \
1N/A unsigned char state;
/* fts_read() state */ \
1N/A char*
base;
/* basename in path */ \
1N/A char*
pad[
2];
/* $0.02 to splain this */ 1N/A * NOTE: <ftwalk.h> relies on status and statb being the first two elements 1N/A int nd;
/* popdir() count */ \
1N/A unsigned char must;
/* must stat */ \
1N/A unsigned char type;
/* DT_* type */ \
1N/A unsigned char symlink;
/* originally a symlink */ \
1N/A char name[
sizeof(
int)];
/* fts_name data */ 1N/A * NOTE: a malicious dir rename() could change .. underfoot so we 1N/A * must always verify; undef verify to enable the unsafe code 1N/A * FTS_NOSTAT requires a dir with 1N/A * D_TYPE(&dirent_t)!=DT_UNKNOWN 1N/A * allocate an FTSENT node 1N/A * hack for NFS where <dev,ino> may not uniquely identify objects 1N/A * search trees with top-down splaying (a la Tarjan and Sleator) 1N/A * when used for insertion sort, this implements a stable sort 1N/A * this is the left zig-zig case 1N/A * stick all things > e to the right tree 1N/A * this is the right zig-zig case 1N/A * stick all things <= e to the left tree 1N/A * delete the root element from the tree 1N/A * generate ordered fts_link list from binary tree at root 1N/A * FTSENT.stack instead of recursion to avoid blowing the real 1N/A * stack on big directories 1N/A * set directory when curdir is lost in space 1N/A * note that path and home are in the same buffer 1N/A * pop a set of directories 1N/A * initialize st from path and fts_info from st 1N/A * get top list of elements to process 1N/A * ordering delayed until first fts_read() 1N/A * to give caller a chance to set fts->handle 1N/A while (*s++ ==
'.' && *s++ ==
'/')
1N/A * don't let any standards committee get 1N/A * away with calling your idea a hack 1N/A * order fts->todo if fts->comparf != 0 1N/A * resize the path buffer 1N/A * note that free() is not used because we may need to chdir(fts->home) 1N/A * if there isn't enough space to continue 1N/A * add space for "/." used in testing FTS_DNX 1N/A * open a new fts stream on pathnames 1N/A * set up the path work buffer 1N/A * initialize the tippity-top 1N/A * make the list of top elements 1N/A * return the next FTS entry 1N/A * process the top object on the stack 1N/A * initialize the top level 1N/A * chdir to parent if asked for 1N/A * add object's name to the path 1N/A * check for cycle and open dir 1N/A * buffer is known to be large enough here! 1N/A * FTS_D or FTS_DNX, about to read children 1N/A else if (s[
1] ==
'.' && s[
2] == 0)
1N/A * don't recurse on . and .. 1N/A * done with the directory 1N/A * try moving back to parent dir 1N/A * pop objects completely processed 1N/A * delete from <dev,ino> tree 1N/A * perform post-order processing 1N/A * move to parent dir 1N/A * try again or delete from top of stack 1N/A * reset current directory 1N/A * follow symlink if asked to 1N/A * about to prune this f and already at home 1N/A * set stream or entry flags 1N/A * return the list of child entries 1N/A * return default (FTS_LOGICAL|FTS_META|FTS_PHYSICAL|FTS_SEEDOTDIR) flags 1N/A * conditioned by astconf() 1N/A * return 1 if ent is mounted on a local filesystem 1N/A * close an open fts stream 1N/A * register function to be called for each fts_read() entry 1N/A * context==0 => unregister notifyf