summaryrefslogtreecommitdiffstats
path: root/src/bftw.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-09-19 12:14:06 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-09-19 12:14:06 -0400
commitcf2eb17c48a23d49bf517df58e34e30529c16576 (patch)
treee746c589fb25d62bdc7ea9803a8f2e983b563ba5 /src/bftw.c
parent5307ef2ed38b665892798aa10295dd68401a38df (diff)
downloadbfs-cf2eb17c48a23d49bf517df58e34e30529c16576.tar.xz
list: New drain_slist() macro
Diffstat (limited to 'src/bftw.c')
-rw-r--r--src/bftw.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/bftw.c b/src/bftw.c
index 64991b0..0186e3f 100644
--- a/src/bftw.c
+++ b/src/bftw.c
@@ -1162,12 +1162,13 @@ static int bftw_file_open(struct bftw_state *state, struct bftw_file *file, cons
struct bftw_list parents;
SLIST_INIT(&parents);
- struct bftw_file *cur;
- for (cur = file; cur != base; cur = cur->parent) {
+ // Reverse the chain of parents
+ for (struct bftw_file *cur = file; cur != base; cur = cur->parent) {
SLIST_PREPEND(&parents, cur);
}
- while ((cur = SLIST_POP(&parents))) {
+ // Open each component relative to its parent
+ drain_slist (struct bftw_file, cur, &parents) {
if (!cur->parent || cur->parent->fd >= 0) {
bftw_file_openat(state, cur, cur->parent, cur->name);
}
@@ -1870,8 +1871,8 @@ static int bftw_gc(struct bftw_state *state, enum bftw_gc_flags flags) {
}
state->direrror = 0;
- while ((file = SLIST_POP(&state->to_close, ready))) {
- bftw_unwrapdir(state, file);
+ drain_slist (struct bftw_file, dead, &state->to_close, ready) {
+ bftw_unwrapdir(state, dead);
}
enum bftw_gc_flags visit = BFTW_VISIT_FILE;