summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-05-31 19:25:16 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-05-31 19:25:16 +0200
commit3559e5e0e840839ae85aa02c0748f89676c0a5e8 (patch)
tree004066f10f22b245d22ac73f71fd17ac5c8e3f06 /lib
parentc4a945dd254af75d334fdd881076c665184faa31 (diff)
gensquashfs: allow combining packdir and packfile
If packdir and packfile are both specified, use packdir as alternate root. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/fstree/fstree_from_file.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/lib/fstree/fstree_from_file.c b/lib/fstree/fstree_from_file.c
index c2fac7a..5a87222 100644
--- a/lib/fstree/fstree_from_file.c
+++ b/lib/fstree/fstree_from_file.c
@@ -362,7 +362,7 @@ out_desc:
return -1;
}
-int fstree_from_file(fstree_t *fs, const char *filename)
+int fstree_from_file(fstree_t *fs, const char *filename, const char *rootdir)
{
FILE *fp = fopen(filename, "rb");
size_t n, line_num = 0;
@@ -375,23 +375,30 @@ int fstree_from_file(fstree_t *fs, const char *filename)
return -1;
}
- ptr = strrchr(filename, '/');
+ if (rootdir == NULL) {
+ ptr = strrchr(filename, '/');
- if (ptr != NULL) {
- line = strndup(filename, ptr - filename);
- if (line == NULL) {
- perror("composing root path");
- return -1;
- }
+ if (ptr != NULL) {
+ line = strndup(filename, ptr - filename);
+ if (line == NULL) {
+ perror("composing root path");
+ return -1;
+ }
+
+ if (chdir(line)) {
+ perror(line);
+ free(line);
+ return -1;
+ }
- if (chdir(line)) {
- perror(line);
free(line);
+ line = NULL;
+ }
+ } else {
+ if (chdir(rootdir)) {
+ perror(rootdir);
return -1;
}
-
- free(line);
- line = NULL;
}
for (;;) {