From cca4c9f4c0878b08fac6dfe014148ddcd5aa7678 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 14 Apr 2021 21:34:00 +0200 Subject: unzip: add -t function old new delta packed_usage 33584 33598 +14 .rodata 103218 103219 +1 unzip_main 2665 2656 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 15/-9) Total: 6 bytes Signed-off-by: Denys Vlasenko --- archival/unzip.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'archival') diff --git a/archival/unzip.c b/archival/unzip.c index 12db4e579..66005a43e 100644 --- a/archival/unzip.c +++ b/archival/unzip.c @@ -64,6 +64,7 @@ //usage: "\n -o Overwrite" //usage: "\n -j Do not restore paths" //usage: "\n -p Print to stdout" +//usage: "\n -t Test" //usage: "\n -q Quiet" //usage: "\n -x FILE Exclude FILEs" //usage: "\n -d DIR Extract into DIR" @@ -556,7 +557,7 @@ int unzip_main(int argc, char **argv) opts = 0; /* '-' makes getopt return 1 for non-options */ - while ((i = getopt(argc, argv, "-d:lnopqxjv")) != -1) { + while ((i = getopt(argc, argv, "-d:lnotpqxjv")) != -1) { switch (i) { case 'd': /* Extract to base directory */ base_dir = optarg; @@ -574,8 +575,13 @@ int unzip_main(int argc, char **argv) overwrite = O_ALWAYS; break; - case 'p': /* Extract files to stdout and fall through to set verbosity */ + case 't': /* Extract files to /dev/null */ + xmove_fd(xopen("/dev/null", O_WRONLY), STDOUT_FILENO); + /*fallthrough*/ + + case 'p': /* Extract files to stdout */ dst_fd = STDOUT_FILENO; + /*fallthrough*/ case 'q': /* Be quiet */ quiet++; @@ -984,7 +990,6 @@ int unzip_main(int argc, char **argv) /* O_NOFOLLOW defends against symlink attacks */ dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW); #endif - do_extract: if (!quiet) { printf(/* zip.fmt.method == 0 ? " extracting: %s\n" @@ -992,6 +997,7 @@ int unzip_main(int argc, char **argv) printable_string(dst_fn) ); } + do_extract: #if ENABLE_FEATURE_UNZIP_CDF if (S_ISLNK(file_mode)) { if (dst_fd != STDOUT_FILENO) /* not -p? */ -- cgit v1.2.3