aboutsummaryrefslogtreecommitdiff
path: root/bin/gensquashfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-04-10 16:46:07 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-04-12 20:41:34 +0200
commit0bd3afbf487c15221f9d4cfbc19a07e3c4b87587 (patch)
tree3a1f46cce0e80964dac3f40803c6d22a6356d65b /bin/gensquashfs
parent72674fc880fa3a5e121e07f9dcdf6f79437a3011 (diff)
Win32: gensquashfs: Merge fstree_from_dir and subdir implementations
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'bin/gensquashfs')
-rw-r--r--bin/gensquashfs/src/fstree_from_dir.c53
1 files changed, 16 insertions, 37 deletions
diff --git a/bin/gensquashfs/src/fstree_from_dir.c b/bin/gensquashfs/src/fstree_from_dir.c
index 2ece45a..804f64c 100644
--- a/bin/gensquashfs/src/fstree_from_dir.c
+++ b/bin/gensquashfs/src/fstree_from_dir.c
@@ -107,29 +107,6 @@ static int scan_dir(fstree_t *fs, tree_node_t *root,
return 0;
}
-int fstree_from_dir(fstree_t *fs, tree_node_t *root,
- const char *path, scan_node_callback cb,
- void *user, unsigned int flags)
-{
- tree_node_t *n;
-
- if (scan_dir(fs, root, path, cb, user, flags))
- return -1;
-
- if (flags & DIR_SCAN_NO_RECURSION)
- return 0;
-
- for (n = root->data.dir.children; n != NULL; n = n->next) {
- if (!S_ISDIR(n->mode))
- continue;
-
- if (fstree_from_subdir(fs, n, path, n->name, cb, user, flags))
- return -1;
- }
-
- return 0;
-}
-
int fstree_from_subdir(fstree_t *fs, tree_node_t *root,
const char *path, const char *subdir,
scan_node_callback cb, void *user,
@@ -142,21 +119,23 @@ int fstree_from_subdir(fstree_t *fs, tree_node_t *root,
plen = strlen(path);
slen = subdir == NULL ? 0 : strlen(subdir);
- if (slen == 0)
- return fstree_from_dir(fs, root, path, cb, user, flags);
+ if (slen > 0) {
+ temp = calloc(1, plen + 1 + slen + 1);
+ if (temp == NULL) {
+ fprintf(stderr, "%s/%s: allocation failure.\n",
+ path, subdir);
+ return -1;
+ }
- temp = calloc(1, plen + 1 + slen + 1);
- if (temp == NULL) {
- fprintf(stderr, "%s/%s: allocation failure.\n", path, subdir);
- return -1;
- }
+ memcpy(temp, path, plen);
+ temp[plen] = '/';
+ memcpy(temp + plen + 1, subdir, slen);
+ temp[plen + 1 + slen] = '\0';
- memcpy(temp, path, plen);
- temp[plen] = '/';
- memcpy(temp + plen + 1, subdir, slen);
- temp[plen + 1 + slen] = '\0';
+ path = temp;
+ }
- if (scan_dir(fs, root, temp, cb, user, flags))
+ if (scan_dir(fs, root, path, cb, user, flags))
goto fail;
if (flags & DIR_SCAN_NO_RECURSION) {
@@ -168,7 +147,7 @@ int fstree_from_subdir(fstree_t *fs, tree_node_t *root,
if (!S_ISDIR(n->mode))
continue;
- if (fstree_from_subdir(fs, n, temp, n->name, cb, user, flags))
+ if (fstree_from_subdir(fs, n, path, n->name, cb, user, flags))
goto fail;
}
@@ -401,6 +380,7 @@ int fstree_from_subdir(fstree_t *fs, tree_node_t *root,
return populate_dir(fd, fs, root, sb.st_dev, cb, user, flags);
}
+#endif
int fstree_from_dir(fstree_t *fs, tree_node_t *root,
const char *path, scan_node_callback cb,
@@ -408,4 +388,3 @@ int fstree_from_dir(fstree_t *fs, tree_node_t *root,
{
return fstree_from_subdir(fs, root, path, NULL, cb, user, flags);
}
-#endif