Mercurial > hg > toybox
changeset 601:a6a541b7fc34
Add dirtree_parentfd()
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 16 Jun 2012 15:16:08 -0500 |
parents | 58d2fd7484bd |
children | 12eddd9a1fe4 |
files | lib/dirtree.c lib/lib.h toys/chmod.c |
diffstat | 3 files changed, 9 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/dirtree.c Sat Jun 16 14:19:56 2012 -0500 +++ b/lib/dirtree.c Sat Jun 16 15:16:08 2012 -0500 @@ -79,6 +79,11 @@ return DIRTREE_SAVE|DIRTREE_RECURSE; } +int dirtree_parentfd(struct dirtree *node) +{ + return node->parent ? node->parent->data : AT_FDCWD; +} + // get open filehandle for node in extra, giving caller the option of // using DIRTREE_COMEAGAIN or not. int dirtree_opennode(struct dirtree *try) @@ -89,8 +94,7 @@ try->extra = xdup(try->data); return DIRTREE_COMEAGAIN; } - } else try->extra = openat(try->parent ? try->parent->data : AT_FDCWD, - try->name, 0); + } else try->extra = openat(dirtree_parentfd(try), try->name, 0); return DIRTREE_SAVE|DIRTREE_RECURSE; } @@ -113,9 +117,7 @@ // Directory always has filehandle for examining contents. Whether or // not we'll recurse into it gets decided later. - if (dir) - new->data = openat(new->parent ? new->parent->data : AT_FDCWD, - new->name, 0); + if (dir) new->data = openat(dirtree_parentfd(new), new->name, 0); flags = callback(new);
--- a/lib/lib.h Sat Jun 16 14:19:56 2012 -0500 +++ b/lib/lib.h Sat Jun 16 15:16:08 2012 -0500 @@ -74,6 +74,7 @@ struct dirtree *dirtree_add_node(int dirfd, char *name, int symfollow); char *dirtree_path(struct dirtree *node, int *plen); int dirtree_notdotdot(struct dirtree *catch); +int dirtree_parentfd(struct dirtree *node); int dirtree_opennode(struct dirtree *try); struct dirtree *handle_callback(struct dirtree *new, int (*callback)(struct dirtree *node));
--- a/toys/chmod.c Sat Jun 16 14:19:56 2012 -0500 +++ b/toys/chmod.c Sat Jun 16 15:16:08 2012 -0500 @@ -58,7 +58,7 @@ printf("chmod '%s' to %04o\n", s, mode); free(s); } - wfchmodat(try->parent ? try->parent->data : AT_FDCWD, try->name, mode); + wfchmodat(dirtree_parentfd(try), try->name, mode); return (toys.optflags & FLAG_R) ? DIRTREE_RECURSE : 0; }