aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqfs')
-rw-r--r--lib/sqfs/Makemodule.am1
-rw-r--r--lib/sqfs/dir_reader/get_path.c42
2 files changed, 43 insertions, 0 deletions
diff --git a/lib/sqfs/Makemodule.am b/lib/sqfs/Makemodule.am
index d49482e..ad3d42d 100644
--- a/lib/sqfs/Makemodule.am
+++ b/lib/sqfs/Makemodule.am
@@ -20,6 +20,7 @@ libsquashfs_la_SOURCES += lib/sqfs/read_table.c lib/sqfs/comp/compressor.c
libsquashfs_la_SOURCES += lib/sqfs/comp/internal.h
libsquashfs_la_SOURCES += lib/sqfs/dir_reader/dir_reader.c
libsquashfs_la_SOURCES += lib/sqfs/dir_reader/read_tree.c
+libsquashfs_la_SOURCES += lib/sqfs/dir_reader/get_path.c
libsquashfs_la_SOURCES += lib/sqfs/dir_reader/internal.h
libsquashfs_la_SOURCES += lib/sqfs/inode.c lib/sqfs/xattr/xattr_writer.c
libsquashfs_la_SOURCES += lib/sqfs/xattr/xattr_writer_flush.c
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;
+}