diff options
Diffstat (limited to 'bin/tar2sqfs/src')
-rw-r--r-- | bin/tar2sqfs/src/options.c | 43 | ||||
-rw-r--r-- | bin/tar2sqfs/src/tar2sqfs.c | 4 | ||||
-rw-r--r-- | bin/tar2sqfs/src/tar2sqfs.h | 4 |
3 files changed, 16 insertions, 35 deletions
diff --git a/bin/tar2sqfs/src/options.c b/bin/tar2sqfs/src/options.c index edc27ce..3443ce3 100644 --- a/bin/tar2sqfs/src/options.c +++ b/bin/tar2sqfs/src/options.c @@ -93,9 +93,7 @@ bool no_tail_pack = false; bool no_symlink_retarget = false; sqfs_writer_cfg_t cfg; char *root_becomes = NULL; -char **excludedirs = NULL; -size_t num_excludedirs = 0; -static size_t max_excludedirs = 0; +strlist_t excludedirs = { 0, 0, 0 }; static void input_compressor_print_available(void) { @@ -119,10 +117,8 @@ static void input_compressor_print_available(void) void process_args(int argc, char **argv) { - size_t idx, new_count; bool have_compressor; int i, ret; - char **new; sqfs_writer_cfg_init(&cfg); @@ -222,29 +218,11 @@ void process_args(int argc, char **argv) cfg.quiet = true; break; case 'E': - if (num_excludedirs == max_excludedirs) { - new_count = max_excludedirs ? max_excludedirs * 2 : 16; - new = realloc(excludedirs, - new_count * sizeof(excludedirs[0])); - if (new == NULL) - goto fail_errno; - - max_excludedirs = new_count; - excludedirs = new; - } - - excludedirs[num_excludedirs] = strdup(optarg); - if (excludedirs[num_excludedirs] == NULL) - goto fail_errno; - - if (canonicalize_name(excludedirs[num_excludedirs])) { - perror(optarg); + if (strlist_append(&excludedirs, optarg)) { + fputs("out-of-memory\n", stderr); goto fail; } - - ++num_excludedirs; break; - case 'h': printf(usagestr, SQFS_DEFAULT_BLOCK_SIZE, SQFS_DEVBLK_SIZE); @@ -259,6 +237,14 @@ void process_args(int argc, char **argv) } } + for (size_t idx = 0; idx < excludedirs.count; ++idx) { + if (canonicalize_name(excludedirs.strings[idx])) { + fprintf(stderr, "Invalid name `%s`\n", + excludedirs.strings[idx]); + goto fail; + } + } + if (cfg.num_jobs < 1) cfg.num_jobs = 1; @@ -282,9 +268,6 @@ void process_args(int argc, char **argv) goto fail_arg; } return; -fail_errno: - perror("parsing options"); - goto fail; fail_arg: fputs("Try `tar2sqfsr --help' for more information.\n", stderr); goto fail; @@ -295,9 +278,7 @@ out_success: ret = EXIT_SUCCESS; goto out_exit; out_exit: - for (idx = 0; idx < num_excludedirs; ++idx) - free(excludedirs[idx]); + strlist_cleanup(&excludedirs); free(root_becomes); - free(excludedirs); exit(ret); } diff --git a/bin/tar2sqfs/src/tar2sqfs.c b/bin/tar2sqfs/src/tar2sqfs.c index acb42e2..99f012c 100644 --- a/bin/tar2sqfs/src/tar2sqfs.c +++ b/bin/tar2sqfs/src/tar2sqfs.c @@ -23,8 +23,8 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - topts.excludedirs = excludedirs; - topts.num_excludedirs = num_excludedirs; + topts.excludedirs = excludedirs.strings; + topts.num_excludedirs = excludedirs.count; tar = tar_open_stream(input_file, &topts); sqfs_drop(input_file); diff --git a/bin/tar2sqfs/src/tar2sqfs.h b/bin/tar2sqfs/src/tar2sqfs.h index d2049f2..a5b1089 100644 --- a/bin/tar2sqfs/src/tar2sqfs.h +++ b/bin/tar2sqfs/src/tar2sqfs.h @@ -12,6 +12,7 @@ #include "compat.h" #include "util/util.h" +#include "util/strlist.h" #include "tar/tar.h" #include "tar/format.h" #include "xfrm/compress.h" @@ -29,8 +30,7 @@ extern bool no_tail_pack; extern bool no_symlink_retarget; extern sqfs_writer_cfg_t cfg; extern char *root_becomes; -extern char **excludedirs; -extern size_t num_excludedirs; +extern strlist_t excludedirs; void process_args(int argc, char **argv); |