aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-19 16:08:58 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-20 03:18:47 +0200
commit8eef635136add59fe3998143c583345922845447 (patch)
treed620717b96b0a9a6e279bd2ca78f154d06ddc503
parent04518e8940014d4528fbdc5474705cfcf98b44f2 (diff)
Port fstree get_path function to dir reader tree
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--include/highlevel.h2
-rw-r--r--lib/sqfshelper/Makemodule.am1
-rw-r--r--lib/sqfshelper/get_path.c43
3 files changed, 46 insertions, 0 deletions
diff --git a/include/highlevel.h b/include/highlevel.h
index 1c1ea11..a3d9117 100644
--- a/include/highlevel.h
+++ b/include/highlevel.h
@@ -123,4 +123,6 @@ sqfs_inode_generic_t *tree_node_to_inode(fstree_t *fs, sqfs_id_table_t *idtbl,
int inode_stat(const sqfs_tree_node_t *node, struct stat *sb);
+char *sqfs_tree_node_get_path(const sqfs_tree_node_t *node);
+
#endif /* HIGHLEVEL_H */
diff --git a/lib/sqfshelper/Makemodule.am b/lib/sqfshelper/Makemodule.am
index 32d9852..67f81a4 100644
--- a/lib/sqfshelper/Makemodule.am
+++ b/lib/sqfshelper/Makemodule.am
@@ -12,5 +12,6 @@ libsqfshelper_a_SOURCES += lib/sqfshelper/compress.c lib/sqfshelper/comp_opt.c
libsqfshelper_a_SOURCES += include/data_reader.h lib/sqfshelper/data_reader.c
libsqfshelper_a_SOURCES += include/data_writer.h lib/sqfshelper/data_writer.c
libsqfshelper_a_SOURCES += lib/sqfshelper/write_xattr.c include/highlevel.h
+libsqfshelper_a_SOURCES += lib/sqfshelper/get_path.c
noinst_LIBRARIES += libsqfshelper.a
diff --git a/lib/sqfshelper/get_path.c b/lib/sqfshelper/get_path.c
new file mode 100644
index 0000000..a432b4a
--- /dev/null
+++ b/lib/sqfshelper/get_path.c
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * get_path.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "highlevel.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;
+}