diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-05-05 01:25:43 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-05-05 01:26:06 +0200 |
commit | 7ce4b36d517ac5fade36240d293ff784ef6a9305 (patch) | |
tree | f0c246595251d27f62010aca770b25bb5f7ea336 /lib/fstree/src/get_by_path.c | |
parent | 7a39921d7fff089c87ac183d3c0d6e42e5cbaa04 (diff) |
Internalize fstree_mknode, consolidate fstree functionality
The fstree_mknode function is only used internally, remove the
declaration from the header and internalize it. The code using it is
consolidated into fstree.c.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/fstree/src/get_by_path.c')
-rw-r--r-- | lib/fstree/src/get_by_path.c | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/lib/fstree/src/get_by_path.c b/lib/fstree/src/get_by_path.c deleted file mode 100644 index 133f412..0000000 --- a/lib/fstree/src/get_by_path.c +++ /dev/null @@ -1,84 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * get_by_path.c - * - * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> - */ -#include "config.h" - -#include "fstree.h" - -#include <string.h> -#include <errno.h> - -static tree_node_t *child_by_name(tree_node_t *root, const char *name, - size_t len) -{ - tree_node_t *n = root->data.children; - - while (n != NULL) { - if (strncmp(n->name, name, len) == 0 && n->name[len] == '\0') - break; - - n = n->next; - } - - return n; -} - -tree_node_t *fstree_get_node_by_path(fstree_t *fs, tree_node_t *root, - const char *path, bool create_implicitly, - bool stop_at_parent) -{ - const char *end; - tree_node_t *n; - size_t len; - - while (*path != '\0') { - while (*path == '/') - ++path; - - if (!S_ISDIR(root->mode)) { - errno = ENOTDIR; - return NULL; - } - - end = strchr(path, '/'); - if (end == NULL) { - if (stop_at_parent) - break; - - len = strlen(path); - } else { - len = end - path; - } - - n = child_by_name(root, path, len); - - if (n == NULL) { - struct stat sb; - - if (!create_implicitly) { - errno = ENOENT; - return NULL; - } - - memset(&sb, 0, sizeof(sb)); - sb.st_mode = S_IFDIR | (fs->defaults.mode & 07777); - sb.st_uid = fs->defaults.uid; - sb.st_gid = fs->defaults.gid; - sb.st_mtime = fs->defaults.mtime; - - n = fstree_mknode(root, path, len, NULL, &sb); - if (n == NULL) - return NULL; - - n->flags |= FLAG_DIR_CREATED_IMPLICITLY; - } - - root = n; - path = path + len; - } - - return root; -} |