aboutsummaryrefslogtreecommitdiff
path: root/lib/dirtree.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-04-21 17:46:25 -0500
committerRob Landley <rob@landley.net>2016-04-21 17:46:25 -0500
commitbb77dde5ddfba8fe0c819b18b547c2d710956502 (patch)
tree50948a567f42b7be3ce648eb3045b9db2961db10 /lib/dirtree.c
parent00385e8d0e1f83a58710ada4a210d15102542b7d (diff)
downloadtoybox-bb77dde5ddfba8fe0c819b18b547c2d710956502.tar.gz
Have dirtree_recurse() take the new dirfd as an argument.
Diffstat (limited to 'lib/dirtree.c')
-rw-r--r--lib/dirtree.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/dirtree.c b/lib/dirtree.c
index cc1ab90c..8f235ed4 100644
--- a/lib/dirtree.c
+++ b/lib/dirtree.c
@@ -110,12 +110,9 @@ struct dirtree *dirtree_handle_callback(struct dirtree *new,
if (!callback) return new;
flags = callback(new);
- if (S_ISDIR(new->st.st_mode)) {
- if (flags & (DIRTREE_RECURSE|DIRTREE_COMEAGAIN)) {
- new->dirfd = openat(dirtree_parentfd(new), new->name, O_CLOEXEC);
- flags = dirtree_recurse(new, callback, flags);
- }
- }
+ if (S_ISDIR(new->st.st_mode) && (flags & (DIRTREE_RECURSE|DIRTREE_COMEAGAIN)))
+ flags = dirtree_recurse(new, callback,
+ openat(dirtree_parentfd(new), new->name, O_CLOEXEC), flags);
// If this had children, it was callback's job to free them already.
if (!(flags & DIRTREE_SAVE)) {
@@ -130,12 +127,13 @@ struct dirtree *dirtree_handle_callback(struct dirtree *new,
// callback(). Uses and closes supplied ->dirfd.
int dirtree_recurse(struct dirtree *node,
- int (*callback)(struct dirtree *node), int flags)
+ int (*callback)(struct dirtree *node), int dirfd, int flags)
{
struct dirtree *new, **ddt = &(node->child);
struct dirent *entry;
DIR *dir;
+ node->dirfd = dirfd;
if (node->dirfd == -1 || !(dir = fdopendir(node->dirfd))) {
if (!(flags & DIRTREE_SHUTUP)) {
char *path = dirtree_path(node, 0);