aboutsummaryrefslogtreecommitdiff
path: root/toys/lsb/gzip.c
diff options
context:
space:
mode:
Diffstat (limited to 'toys/lsb/gzip.c')
-rw-r--r--toys/lsb/gzip.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/toys/lsb/gzip.c b/toys/lsb/gzip.c
index 049285af..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, "ncdfk123456789[-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;
@@ -134,7 +136,7 @@ static void do_gzip(int ifd, char *in)
else if ((out = strend(in, ".gz"))>in) out = xstrndup(in, out-in);
else return error_msg("no .gz: %s", in);
- ofd = xcreate(out, O_CREAT|O_WRONLY|WARN_ONLY|(O_EXCL*!FLAG(f)),sb.st_mode);
+ ofd = xcreate(out, O_CREAT|O_WRONLY|WARN_ONLY|O_EXCL*!FLAG(f), sb.st_mode);
if (ofd == -1) return;
}
@@ -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);
}