From e1e655b02f6c54177f9070eeb221ab95c6d4e20f Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Wed, 19 Apr 2023 10:13:49 +0200 Subject: libfstree: hoist file link pointer into parent structure Instead of having a file_info_t next pointer, requiring an up-cast to tree_node_t all the time, simply add a "next_by_type" pointer to the tree node itself, which can also be used for other purposes by other node types and removes the need for up-casting. Signed-off-by: David Oberhollenzer --- lib/fstree/src/post_process.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/fstree/src/post_process.c b/lib/fstree/src/post_process.c index 5bf7e7d..f8bc0f7 100644 --- a/lib/fstree/src/post_process.c +++ b/lib/fstree/src/post_process.c @@ -55,15 +55,15 @@ fail_ov: return -1; } -static file_info_t *file_list_dfs(tree_node_t *n) +static tree_node_t *file_list_dfs(tree_node_t *n) { if (S_ISREG(n->mode)) { - n->data.file.next = NULL; - return &n->data.file; + n->next_by_type = NULL; + return n; } if (S_ISDIR(n->mode)) { - file_info_t *list = NULL, *last = NULL; + tree_node_t *list = NULL, *last = NULL; for (n = n->data.children; n != NULL; n = n->next) { if (list == NULL) { @@ -72,11 +72,11 @@ static file_info_t *file_list_dfs(tree_node_t *n) continue; last = list; } else { - last->next = file_list_dfs(n); + last->next_by_type = file_list_dfs(n); } - while (last->next != NULL) - last = last->next; + while (last->next_by_type != NULL) + last = last->next_by_type; } return list; -- cgit v1.2.3