From c3127b5f9f3099ea526fe6da571ddf77bd72871d Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 20 Jan 2023 02:14:44 -0600 Subject: [PATCH] Switch dirtree to set macro bits instead of hardwired numbers. --- lib/dirtree.c | 10 +++++----- toys/posix/find.c | 2 +- toys/posix/ls.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/dirtree.c b/lib/dirtree.c index 4023101e..63ba16ab 100644 --- a/lib/dirtree.c +++ b/lib/dirtree.c @@ -52,11 +52,11 @@ struct dirtree *dirtree_add_node(struct dirtree *parent, char *name, int flags) } // Allocate/populate return structure - memset(dt = xmalloc((len = sizeof(struct dirtree)+len+1)+linklen), 0, - statless ? sizeof(struct dirtree) : offsetof(struct dirtree, st)); + dt = xmalloc((len = sizeof(struct dirtree)+len+1)+linklen); + memset(dt, 0, sizeof(struct dirtree)); dt->parent = parent; - dt->again = statless ? 2 : 0; - if (!statless) memcpy(&dt->st, &st, sizeof(struct stat)); + if (statless) dt->again = DIRTREE_STATLESS; + else memcpy(&dt->st, &st, sizeof(struct stat)); if (name) strcpy(dt->name, name); else *dt->name = 0, dt->st.st_mode = S_IFDIR; if (linklen) dt->symlink = memcpy(len+(char *)dt, libbuf, linklen); @@ -176,7 +176,7 @@ int dirtree_recurse(struct dirtree *node, } if (flags & DIRTREE_COMEAGAIN) { - node->again |= 1; + node->again |= DIRTREE_COMEAGAIN; flags = callback(node); } diff --git a/toys/posix/find.c b/toys/posix/find.c index 9a851aa9..942d3ef4 100644 --- a/toys/posix/find.c +++ b/toys/posix/find.c @@ -220,7 +220,7 @@ static int do_find(struct dirtree *new) // skip . and .. below topdir, handle -xdev and -depth if (new) { // Handle stat failures first. - if (new->again&2) { + if (new->again&DIRTREE_STATLESS) { if (!new->parent || errno != ENOENT) { perror_msg("'%s'", s = dirtree_path(new, 0)); free(s); diff --git a/toys/posix/ls.c b/toys/posix/ls.c index 3d0e1d26..6e100963 100644 --- a/toys/posix/ls.c +++ b/toys/posix/ls.c @@ -544,7 +544,7 @@ void ls_main(void) // note: double_list->prev temporarily goes in dirtree->parent if (dt) { - if (dt->again&2) { + if (dt->again&DIRTREE_STATLESS) { perror_msg_raw(*s); free(dt); } else dlist_add_nomalloc((void *)&TT.files->child, (void *)dt); -- 2.39.2