aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs/dir_reader/get_path.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-01-31 11:21:30 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-01-31 13:51:49 +0100
commitcdccc69c62579b0c13b35fad0728079652b8f3c9 (patch)
tree9fa54c710f73c5e08a9c8466e7a712eb63ee07ac /lib/sqfs/dir_reader/get_path.c
parent2182129c8f359c4fa1390eaba7a65b595ccd4182 (diff)
Move library source into src sub-directory
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/dir_reader/get_path.c')
-rw-r--r--lib/sqfs/dir_reader/get_path.c81
1 files changed, 0 insertions, 81 deletions
diff --git a/lib/sqfs/dir_reader/get_path.c b/lib/sqfs/dir_reader/get_path.c
deleted file mode 100644
index 847bfd3..0000000
--- a/lib/sqfs/dir_reader/get_path.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/* 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>
-
-int sqfs_tree_node_get_path(const sqfs_tree_node_t *node, char **out)
-{
- const sqfs_tree_node_t *it;
- size_t clen, len = 0;
- char *str, *ptr;
-
- *out = NULL;
-
- if (node == NULL)
- return SQFS_ERROR_ARG_INVALID;
-
- for (it = node; it->parent != NULL; it = it->parent) {
- if (it->parent == node)
- return SQFS_ERROR_LINK_LOOP;
-
- /* non-root nodes must have a valid name */
- clen = strlen((const char *)it->name);
-
- if (clen == 0)
- return SQFS_ERROR_CORRUPTED;
-
- if (strchr((const char *)it->name, '/') != NULL)
- return SQFS_ERROR_CORRUPTED;
-
- if (it->name[0] == '.') {
- if (clen == 1 || (clen == 2 && it->name[1] == '.'))
- return SQFS_ERROR_CORRUPTED;
- }
-
- /* compute total path length */
- if (SZ_ADD_OV(clen, 1, &clen))
- return SQFS_ERROR_OVERFLOW;
-
- if (SZ_ADD_OV(len, clen, &len))
- return SQFS_ERROR_OVERFLOW;
- }
-
- /* root node must not have a name */
- if (it->name[0] != '\0')
- return SQFS_ERROR_ARG_INVALID;
-
- /* generate the path */
- if (node->parent == NULL) {
- str = strdup("/");
- if (str == NULL)
- return SQFS_ERROR_ALLOC;
- } else {
- if (SZ_ADD_OV(len, 1, &len))
- return SQFS_ERROR_OVERFLOW;
-
- str = malloc(len);
- if (str == NULL)
- return SQFS_ERROR_ALLOC;
-
- ptr = str + len - 1;
- *ptr = '\0';
-
- for (it = node; it->parent != NULL; it = it->parent) {
- len = strlen((const char *)it->name);
- ptr -= len;
-
- memcpy(ptr, (const char *)it->name, len);
- *(--ptr) = '/';
- }
- }
-
- *out = str;
- return 0;
-}