aboutsummaryrefslogtreecommitdiff
path: root/src/xz/args.c
diff options
context:
space:
mode:
authorJia Tan <jiat0218@gmail.com>2023-11-14 20:27:04 +0800
committerJia Tan <jiat0218@gmail.com>2023-11-14 20:27:04 +0800
commitd4f4a4d040ef47a5e82dffd0f067e92716606ddf (patch)
tree2d1f06e08922b230e55f87d8ab541fa9e928be4b /src/xz/args.c
parentliblzma: Add missing comments to lz_encoder.h. (diff)
downloadxz-d4f4a4d040ef47a5e82dffd0f067e92716606ddf.tar.xz
xz: Detect when all data will be written to standard out earlier.
If the -c, --stdout argument is not used, then we can still detect when the data will be written to standard out if all of the provided filenames are "-" (denoting standard in) or if no filenames are provided.
Diffstat (limited to 'src/xz/args.c')
-rw-r--r--src/xz/args.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/xz/args.c b/src/xz/args.c
index 8b481c93..e3cddda3 100644
--- a/src/xz/args.c
+++ b/src/xz/args.c
@@ -842,6 +842,27 @@ args_parse(args_info *args, int argc, char **argv)
args->arg_count = (unsigned int)(argc - optind);
}
+ // 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. However if --files or
+ // --files0 is used, then we will not be writing to standard out.
+ if (!opt_stdout && args->files_name == NULL) {
+ uint32_t i;
+
+ for (i = 0; i < args->arg_count; i++) {
+ const char *name = args->arg_names[i];
+
+ // getopt_long() will not give us an empty string
+ // as an argument name here so we don't need to
+ // check if name[0] is a NULL terminator.
+ if (name[0] != '-' && name[1] != '\0')
+ break;
+ }
+
+ // Set opt_stdout if the loop did not exit early.
+ opt_stdout = i == args->arg_count;
+ }
+
return;
}