diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2022-07-04 20:01:59 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2022-07-08 19:17:35 +0200 |
commit | 3946cf086183f8dd4d5d115f52ba1b87560b7ce4 (patch) | |
tree | 2659b940b757d1bd177d00562bf8e41a333ef12e /lib/sqfs/dir_reader | |
parent | 8c0aa2504199036eaaa09673ea93dcdcd79606ef (diff) |
Move sqfs_tree_node_get_path to libsquashfs
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/dir_reader')
-rw-r--r-- | lib/sqfs/dir_reader/get_path.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/sqfs/dir_reader/get_path.c b/lib/sqfs/dir_reader/get_path.c new file mode 100644 index 0000000..bdd8317 --- /dev/null +++ b/lib/sqfs/dir_reader/get_path.c @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * get_path.c + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#define SQFS_BUILDING_DLL +#include "internal.h" + +#include <string.h> +#include <stdlib.h> + +char *sqfs_tree_node_get_path(const sqfs_tree_node_t *node) +{ + const sqfs_tree_node_t *it; + char *str, *ptr; + size_t len = 0; + + if (node->parent == NULL) + return strdup("/"); + + for (it = node; it != NULL && it->parent != NULL; it = it->parent) { + len += strlen((const char *)it->name) + 1; + } + + str = malloc(len + 1); + if (str == NULL) + return NULL; + + ptr = str + len; + *ptr = '\0'; + + for (it = node; it != NULL && it->parent != NULL; it = it->parent) { + len = strlen((const char *)it->name); + ptr -= len; + + memcpy(ptr, (const char *)it->name, len); + *(--ptr) = '/'; + } + + return str; +} |