summaryrefslogtreecommitdiff
path: root/lib/common/hardlink.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-08-20 11:42:08 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-08-20 14:45:16 +0200
commit581d9e9ae35d8ce6cbc2f53cdc1b05b962a0b590 (patch)
tree2879683a6e9fdfffd780d811032d322a7763dd28 /lib/common/hardlink.c
parent26e3ec10db15409256bf773ad93c944156697e9e (diff)
Return an error number from sqfs_tree_find_hard_links
Instead of printing error messages to stderr, simply return an error number instead, that the caller then prints out using sqfs_perror. The underlying rbtree already uses sqfs error numbers, so little change is needed here. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/common/hardlink.c')
-rw-r--r--lib/common/hardlink.c43
1 files changed, 13 insertions, 30 deletions
diff --git a/lib/common/hardlink.c b/lib/common/hardlink.c
index f28620f..4657bc3 100644
--- a/lib/common/hardlink.c
+++ b/lib/common/hardlink.c
@@ -24,8 +24,9 @@ static int map_nodes(rbtree_t *inumtree, sqfs_hard_link_t **out,
/* XXX: refuse to generate hard links to directories */
if (n->children != NULL) {
for (n = n->children; n != NULL; n = n->next) {
- if (map_nodes(inumtree, out, n))
- return -1;
+ ret = map_nodes(inumtree, out, n);
+ if (ret != 0)
+ return ret;
}
return 0;
}
@@ -36,23 +37,21 @@ static int map_nodes(rbtree_t *inumtree, sqfs_hard_link_t **out,
idx = n->inode->base.inode_number;
tn = rbtree_lookup(inumtree, &idx);
- if (tn == NULL) {
- ret = rbtree_insert(inumtree, &idx, &n);
- if (ret != 0)
- goto fail_insert;
- return 0;
- }
+ if (tn == NULL)
+ return rbtree_insert(inumtree, &idx, &n);
target = *((const sqfs_tree_node_t **)rbtree_node_value(tn));
lnk = calloc(1, sizeof(*lnk));
if (lnk == NULL)
- goto fail_oom;
+ return SQFS_ERROR_ALLOC;
lnk->inode_number = idx;
ret = sqfs_tree_node_get_path(target, &lnk->target);
- if (ret != 0)
- goto fail_path;
+ if (ret != 0) {
+ free(lnk);
+ return ret;
+ }
if (canonicalize_name(lnk->target) == 0) {
lnk->next = (*out);
@@ -62,18 +61,6 @@ static int map_nodes(rbtree_t *inumtree, sqfs_hard_link_t **out,
free(lnk);
}
return 0;
-fail_path:
- sqfs_perror(NULL, "re-constructing hard link path", ret);
- free(lnk);
- return -1;
-fail_oom:
- fputs("detecting hard links in file system tree: out of memory\n",
- stderr);
- free(lnk);
- return -1;
-fail_insert:
- sqfs_perror(NULL, "detecting hard links in file system tree", ret);
- return -1;
}
static int compare_inum(const void *ctx, const void *lhs, const void *rhs)
@@ -94,11 +81,8 @@ int sqfs_tree_find_hard_links(const sqfs_tree_node_t *root,
ret = rbtree_init(&inumtree, sizeof(sqfs_u32),
sizeof(sqfs_tree_node_t *),
compare_inum);
- if (ret != 0) {
- sqfs_perror(NULL,
- "detecting hard links in file system tree", ret);
- return -1;
- }
+ if (ret != 0)
+ return ret;
ret = map_nodes(&inumtree, out, root);
rbtree_cleanup(&inumtree);
@@ -110,8 +94,7 @@ int sqfs_tree_find_hard_links(const sqfs_tree_node_t *root,
free(lnk->target);
free(lnk);
}
- return -1;
}
- return 0;
+ return ret;
}