diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-09-19 12:14:06 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-09-19 12:14:06 -0400 |
commit | cf2eb17c48a23d49bf517df58e34e30529c16576 (patch) | |
tree | e746c589fb25d62bdc7ea9803a8f2e983b563ba5 /src/bftw.c | |
parent | 5307ef2ed38b665892798aa10295dd68401a38df (diff) | |
download | bfs-cf2eb17c48a23d49bf517df58e34e30529c16576.tar.xz |
list: New drain_slist() macro
Diffstat (limited to 'src/bftw.c')
-rw-r--r-- | src/bftw.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -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; |