summaryrefslogtreecommitdiff
path: root/lib/common/get_path.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-10-07 13:54:24 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-10-07 13:54:24 +0200
commit1fad07ce86fc2a506c59501d7fb7c7d7481525f6 (patch)
tree6ba41c514e2ddc692cb95a0fb2070dd222897c7c /lib/common/get_path.c
parent5597dca9c6053cd19104e18d88edb199b32e3743 (diff)
Rename libsqfshelper to libcommon
That is IMO less confusing and express what it is (i.e. what it has become) more clearly, i.e. common code shared by the utilities. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/common/get_path.c')
-rw-r--r--lib/common/get_path.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/common/get_path.c b/lib/common/get_path.c
new file mode 100644
index 0000000..bdc6c3f
--- /dev/null
+++ b/lib/common/get_path.c
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * get_path.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "common.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;
+}