summaryrefslogtreecommitdiffstats
path: root/src/bftw.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-03-29 13:25:18 -0400
committerTavian Barnes <tavianator@tavianator.com>2023-03-29 13:25:18 -0400
commitf75f3de63888702f29f48bcf2691291403720b9d (patch)
tree40d77d87299b8d54fb5d8e8b059c4a216cd4d353 /src/bftw.c
parent116ab1ed2b4230aea1ab634618af3162cabbb37f (diff)
downloadbfs-f75f3de63888702f29f48bcf2691291403720b9d.tar.xz
list: New helper macros for converting entries to items
Diffstat (limited to 'src/bftw.c')
-rw-r--r--src/bftw.c18
1 files changed, 5 insertions, 13 deletions
diff --git a/src/bftw.c b/src/bftw.c
index 9ff526d..aa36b87 100644
--- a/src/bftw.c
+++ b/src/bftw.c
@@ -69,14 +69,8 @@ struct bftw_file {
};
/** Move from a list entry to a bftw_file. */
-static struct bftw_file *bftw_file_entry(struct slink *link) {
- return BFS_CONTAINER_OF(link, struct bftw_file, link);
-}
-
-/** Move from an LRU entry to a bftw_file. */
-static struct bftw_file *bftw_lru_file(struct link *link) {
- return BFS_CONTAINER_OF(link, struct bftw_file, lru);
-}
+#define BFTW_FILE(...) \
+ LIST_ITEM(struct bftw_file, __VA_ARGS__)
/**
* A cache of open directories.
@@ -126,7 +120,7 @@ static int bftw_cache_pop(struct bftw_cache *cache) {
return -1;
}
- struct bftw_file *file = bftw_lru_file(cache->list.tail);
+ struct bftw_file *file = BFTW_FILE(cache->list.tail, lru);
bftw_file_close(cache, file);
return 0;
}
@@ -810,7 +804,7 @@ static int bftw_pop(struct bftw_state *state) {
return 0;
}
- state->file = bftw_file_entry(slist_pop(&state->queue));
+ state->file = BFTW_FILE(slist_pop(&state->queue));
if (bftw_build_path(state) != 0) {
return -1;
@@ -974,9 +968,7 @@ static int bftw_state_destroy(struct bftw_state *state) {
/** Comparison function for BFTW_SORT. */
static bool bftw_file_cmp(struct slink *left, struct slink *right, const void *ptr) {
- struct bftw_file *lfile = bftw_file_entry(left);
- struct bftw_file *rfile = bftw_file_entry(right);
- return strcoll(lfile->name, rfile->name) <= 0;
+ return strcoll(BFTW_FILE(left)->name, BFTW_FILE(right)->name) <= 0;
}
/** Finish adding a batch of files. */