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 <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2021-04-14 21:34:00 +02:00
parent afc766fc12
commit cca4c9f4c0

View File

@ -64,6 +64,7 @@
//usage: "\n -o Overwrite" //usage: "\n -o Overwrite"
//usage: "\n -j Do not restore paths" //usage: "\n -j Do not restore paths"
//usage: "\n -p Print to stdout" //usage: "\n -p Print to stdout"
//usage: "\n -t Test"
//usage: "\n -q Quiet" //usage: "\n -q Quiet"
//usage: "\n -x FILE Exclude FILEs" //usage: "\n -x FILE Exclude FILEs"
//usage: "\n -d DIR Extract into DIR" //usage: "\n -d DIR Extract into DIR"
@ -556,7 +557,7 @@ int unzip_main(int argc, char **argv)
opts = 0; opts = 0;
/* '-' makes getopt return 1 for non-options */ /* '-' 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) { switch (i) {
case 'd': /* Extract to base directory */ case 'd': /* Extract to base directory */
base_dir = optarg; base_dir = optarg;
@ -574,8 +575,13 @@ int unzip_main(int argc, char **argv)
overwrite = O_ALWAYS; overwrite = O_ALWAYS;
break; 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; dst_fd = STDOUT_FILENO;
/*fallthrough*/
case 'q': /* Be quiet */ case 'q': /* Be quiet */
quiet++; quiet++;
@ -984,7 +990,6 @@ int unzip_main(int argc, char **argv)
/* O_NOFOLLOW defends against symlink attacks */ /* O_NOFOLLOW defends against symlink attacks */
dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW); dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW);
#endif #endif
do_extract:
if (!quiet) { if (!quiet) {
printf(/* zip.fmt.method == 0 printf(/* zip.fmt.method == 0
? " extracting: %s\n" ? " extracting: %s\n"
@ -992,6 +997,7 @@ int unzip_main(int argc, char **argv)
printable_string(dst_fn) printable_string(dst_fn)
); );
} }
do_extract:
#if ENABLE_FEATURE_UNZIP_CDF #if ENABLE_FEATURE_UNZIP_CDF
if (S_ISLNK(file_mode)) { if (S_ISLNK(file_mode)) {
if (dst_fd != STDOUT_FILENO) /* not -p? */ if (dst_fd != STDOUT_FILENO) /* not -p? */