aboutsummaryrefslogtreecommitdiff
path: root/lib/dirtree.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-06-01 20:27:51 -0500
committerRob Landley <rob@landley.net>2012-06-01 20:27:51 -0500
commit38d3cfb8a38c32111e4bc713396f78ddbb0e5f50 (patch)
tree8ff7f831ea9e6d8dacecfa192464673b1ae66e9c /lib/dirtree.c
parent4fa1b32871f661a7e11898b274ec162d52c23ee9 (diff)
downloadtoybox-38d3cfb8a38c32111e4bc713396f78ddbb0e5f50.tar.gz
Changed my mind about the design again, now callback is dirtree_opennode() and recursion choice is how caller interprets flags.
Diffstat (limited to 'lib/dirtree.c')
-rw-r--r--lib/dirtree.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/lib/dirtree.c b/lib/dirtree.c
index 01e0ea8c..291f99a4 100644
--- a/lib/dirtree.c
+++ b/lib/dirtree.c
@@ -78,21 +78,20 @@ int dirtree_notdotdot(struct dirtree *catch)
return DIRTREE_SAVE|DIRTREE_RECURSE;
}
-// depth first recursion
-int dirtree_comeagain(struct dirtree *try, int recurse)
+// get open filehandle for node in extra, giving caller the option of
+// using DIRTREE_COMEAGAIN or not.
+int dirtree_opennode(struct dirtree *try)
{
- int ret = dirtree_notdotdot(try);
- if (ret) {
- if (S_ISDIR(try->st.st_mode)) {
- if (!try->extra) {
- try->extra = xdup(try->data);
- if (recurse) return DIRTREE_COMEAGAIN;
- }
- } else try->extra = openat(try->parent ? try->parent->data : AT_FDCWD,
- try->name, 0);
- }
+ if (!dirtree_notdotdot(try)) return 0;
+ if (S_ISDIR(try->st.st_mode)) {
+ if (!try->extra) {
+ try->extra = xdup(try->data);
+ return DIRTREE_COMEAGAIN;
+ }
+ } else try->extra = openat(try->parent ? try->parent->data : AT_FDCWD,
+ try->name, 0);
- return ret;
+ return DIRTREE_SAVE|DIRTREE_RECURSE;
}
// Handle callback for a node in the tree. Returns saved node(s) or NULL.