diff options
author | Rob Landley <rob@landley.net> | 2016-04-21 17:46:25 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2016-04-21 17:46:25 -0500 |
commit | bb77dde5ddfba8fe0c819b18b547c2d710956502 (patch) | |
tree | 50948a567f42b7be3ce648eb3045b9db2961db10 /lib/dirtree.c | |
parent | 00385e8d0e1f83a58710ada4a210d15102542b7d (diff) | |
download | toybox-bb77dde5ddfba8fe0c819b18b547c2d710956502.tar.gz |
Have dirtree_recurse() take the new dirfd as an argument.
Diffstat (limited to 'lib/dirtree.c')
-rw-r--r-- | lib/dirtree.c | 12 |
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); |