diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2023-11-17 19:35:19 +0200 |
---|---|---|
committer | Jia Tan <jiat0218@gmail.com> | 2023-11-18 01:56:09 +0800 |
commit | 659aca0d695807c0762d4101765189e4e33d1e2c (patch) | |
tree | 20c76a4a50b2f1c69c94d9726ef44db269392e90 /src/xz/args.c | |
parent | Tests: Create test_suffix.sh. (diff) | |
download | xz-659aca0d695807c0762d4101765189e4e33d1e2c.tar.xz |
xz: Move the check for --suffix with --format=raw a few lines earlier.
Now it reads from argv[] instead of args->arg_names.
Diffstat (limited to 'src/xz/args.c')
-rw-r--r-- | src/xz/args.c | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/src/xz/args.c b/src/xz/args.c index 8a5ce1f5..31c071ce 100644 --- a/src/xz/args.c +++ b/src/xz/args.c @@ -811,6 +811,28 @@ args_parse(args_info *args, int argc, char **argv) opt_block_list = NULL; } + // If raw format is used and a custom suffix is not provided, + // then only stdout mode can be used when compressing or + // decompressing. + if (opt_format == FORMAT_RAW && !suffix_is_set() && !opt_stdout + && (opt_mode == MODE_COMPRESS + || opt_mode == MODE_DECOMPRESS)) { + if (args->files_name != NULL) + message_fatal(_("With --format=raw, " + "--suffix=.SUF is required " + "unless writing to stdout")); + + // If all of the filenames provided are "-" (more than one + // "-" could be specified) or no filenames are provided, + // then we are only going to be writing to standard out. + for (int i = optind; i < argc; i++) { + if (strcmp(argv[i], "-") != 0) + message_fatal(_("With --format=raw, " + "--suffix=.SUF is required " + "unless writing to stdout")); + } + } + // Compression settings need to be validated (options themselves and // their memory usage) when compressing to any file format. It has to // be done also when uncompressing raw data, since for raw decoding @@ -834,28 +856,6 @@ args_parse(args_info *args, int argc, char **argv) args->arg_count = (unsigned int)(argc - optind); } - // If raw format is used and a custom suffix is not provided, - // then only stdout mode can be used when compressing or - // decompressing. - if (opt_format == FORMAT_RAW && !suffix_is_set() && !opt_stdout - && (opt_mode == MODE_COMPRESS - || opt_mode == MODE_DECOMPRESS)) { - if (args->files_name != NULL) - message_fatal(_("With --format=raw, " - "--suffix=.SUF is required " - "unless writing to stdout")); - - // If all of the filenames provided are "-" (more than one - // "-" could be specified) or no filenames are provided, - // then we are only going to be writing to standard out. - for (unsigned int i = 0; i < args->arg_count; i++) { - if (strcmp(args->arg_names[i], "-") != 0) - message_fatal(_("With --format=raw, " - "--suffix=.SUF is required " - "unless writing to stdout")); - } - } - return; } |