summaryrefslogtreecommitdiff
path: root/bin/gensquashfs/options.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-02-18 22:05:48 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-02-18 23:50:46 +0100
commitd9549b3d288a9cb053ab5198f3bc2d277b72600f (patch)
tree706703ac00a27ceae211a2e230f519fbc1bb73e8 /bin/gensquashfs/options.c
parent9e510d4ae6dbad555a3416fbe041f4aa8189cbde (diff)
gensquashfs: always construct input path during option processing
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'bin/gensquashfs/options.c')
-rw-r--r--bin/gensquashfs/options.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/bin/gensquashfs/options.c b/bin/gensquashfs/options.c
index 9153265..ec2263c 100644
--- a/bin/gensquashfs/options.c
+++ b/bin/gensquashfs/options.c
@@ -267,7 +267,12 @@ void process_command_line(options_t *opt, int argc, char **argv)
opt->infile = optarg;
break;
case 'D':
- opt->packdir = optarg;
+ free(opt->packdir);
+ opt->packdir = strdup(optarg);
+ if (opt->packdir == NULL) {
+ perror(optarg);
+ exit(EXIT_FAILURE);
+ }
break;
#ifdef WITH_SELINUX
case 's':
@@ -316,8 +321,24 @@ void process_command_line(options_t *opt, int argc, char **argv)
fputs("Unknown extra arguments specified.\n", stderr);
goto fail_arg;
}
+
+ /* construct packdir if not specified */
+ if (opt->packdir == NULL && opt->infile != NULL) {
+ const char *split = strrchr(opt->infile, '/');
+
+ if (split != NULL) {
+ opt->packdir = strndup(opt->infile,
+ split - opt->infile);
+
+ if (opt->packdir == NULL) {
+ perror("constructing input directory path");
+ exit(EXIT_FAILURE);
+ }
+ }
+ }
return;
fail_arg:
fputs("Try `gensquashfs --help' for more information.\n", stderr);
+ free(opt->packdir);
exit(EXIT_FAILURE);
}