From 1e3b99ea2fceafe99b52f7e24e130f0ab22a7b51 Mon Sep 17 00:00:00 2001 From: Ethan Sommer Date: Mon, 25 Nov 2019 03:17:57 -0500 Subject: [PATCH] gzip: add -t --- toys/lsb/gzip.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/toys/lsb/gzip.c b/toys/lsb/gzip.c index 6f6bfe5b..b80e24fe 100644 --- a/toys/lsb/gzip.c +++ b/toys/lsb/gzip.c @@ -5,18 +5,18 @@ * See http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/gzip.html * GZIP RFC: http://www.ietf.org/rfc/rfc1952.txt * - * TODO: qtv --rsyncable + * TODO: qv --rsyncable // gzip.net version allows all options for all commands. -USE_GZIP(NEWTOY(gzip, "n(no-name)cdfk123456789[-123456789]", TOYFLAG_USR|TOYFLAG_BIN)) -USE_GUNZIP(NEWTOY(gunzip, "cdfk123456789[-123456789]", TOYFLAG_USR|TOYFLAG_BIN)) -USE_ZCAT(NEWTOY(zcat, "cdfk123456789[-123456789]", TOYFLAG_USR|TOYFLAG_BIN)) +USE_GZIP(NEWTOY(gzip, "n(no-name)cdfkt123456789[-123456789]", TOYFLAG_USR|TOYFLAG_BIN)) +USE_GUNZIP(NEWTOY(gunzip, "cdfkt123456789[-123456789]", TOYFLAG_USR|TOYFLAG_BIN)) +USE_ZCAT(NEWTOY(zcat, "cdfkt123456789[-123456789]", TOYFLAG_USR|TOYFLAG_BIN)) config GZIP bool "gzip" default n help - usage: gzip [-19cdfk] [FILE...] + usage: gzip [-19cdfkt] [FILE...] Compress files. With no files, compresses stdin to stdout. On success, the input files are removed and replaced by new @@ -26,13 +26,14 @@ config GZIP -d Decompress (act as gunzip) -f Force: allow overwrite of output file -k Keep input files (default is to remove) + -t Test integrity -# Compression level 1-9 (1:fastest, 6:default, 9:best) config GUNZIP bool "gunzip" default y help - usage: gunzip [-cfk] [FILE...] + usage: gunzip [-cfkt] [FILE...] Decompress files. With no files, decompresses stdin to stdout. On success, the input files are removed and replaced by new @@ -41,6 +42,7 @@ config GUNZIP -c Output to stdout (act as zcat) -f Force: allow read from tty -k Keep input files (default is to remove) + -t Test integrity config ZCAT bool "zcat" @@ -116,7 +118,7 @@ static void do_gzip(int ifd, char *in) { struct stat sb; char *out = 0; - int ofd = 0; + int ofd = FLAG(t) ? xopen("/dev/null", O_WRONLY) : 0; // Are we writing to stdout? if (!ifd || FLAG(c)) ofd = 1; @@ -158,6 +160,8 @@ void gzip_main(void) if ((toys.optflags>>TT.level)&1) break; if (!(TT.level = 9-TT.level)) TT.level = 6; + if (FLAG(t)) toys.optflags |= FLAG_d; + loopfiles(toys.optargs, do_gzip); } -- 2.39.2