summaryrefslogtreecommitdiff
path: root/usr.bin/compress
diff options
context:
space:
mode:
authorSolene Rapenne <solene@cvs.openbsd.org>2022-03-14 21:52:09 +0000
committerSolene Rapenne <solene@cvs.openbsd.org>2022-03-14 21:52:09 +0000
commited4ff4ea316834425784c12478c9bb7b87a753ad (patch)
treeb2379780eb0972e88853246a8df28dce4c319dc1 /usr.bin/compress
parent50e71eba341b2d04d0c57615d06e42ef3388c05d (diff)
add -k flag to gzip and gunzip
When using this flag, the input file is kept after compression or decompression, this makes our gzip more compatible with the other gzip changes reworked by jca@, thanks ok jca@ millert@
Diffstat (limited to 'usr.bin/compress')
-rw-r--r--usr.bin/compress/gzip.110
-rw-r--r--usr.bin/compress/main.c22
2 files changed, 19 insertions, 13 deletions
diff --git a/usr.bin/compress/gzip.1 b/usr.bin/compress/gzip.1
index 7f48fe98613..39d5dbecc56 100644
--- a/usr.bin/compress/gzip.1
+++ b/usr.bin/compress/gzip.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: gzip.1,v 1.14 2014/10/07 21:06:30 deraadt Exp $
+.\" $OpenBSD: gzip.1,v 1.15 2022/03/14 21:52:08 solene Exp $
.\"
.\" Copyright (c) 1986, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -33,7 +33,7 @@
.\"
.\" @(#)compress.1 8.2 (Berkeley) 4/18/94
.\"
-.Dd $Mdocdate: October 7 2014 $
+.Dd $Mdocdate: March 14 2022 $
.Dt GZIP 1
.Os
.Sh NAME
@@ -43,13 +43,13 @@
.Nd compress and expand data (deflate mode)
.Sh SYNOPSIS
.Nm gzip
-.Op Fl 123456789cdfhLlNnOqrtVv
+.Op Fl 123456789cdfhkLlNnOqrtVv
.Op Fl b Ar bits
.Op Fl o Ar filename
.Op Fl S Ar suffix
.Op Ar
.Nm gunzip
-.Op Fl cfhLlNnqrtVv
+.Op Fl cfhkLlNnqrtVv
.Op Fl o Ar filename
.Op Ar
.Nm gzcat
@@ -183,6 +183,8 @@ behave as
.Xr cat 1 .
.It Fl h
Print a short help message.
+.It Fl k
+Keep input files after compression or decompression.
.It Fl L
A no-op which exists for compatibility only.
On GNU gzip, it displays the program's license.
diff --git a/usr.bin/compress/main.c b/usr.bin/compress/main.c
index d047777f971..9f034cf7ccb 100644
--- a/usr.bin/compress/main.c
+++ b/usr.bin/compress/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.98 2021/01/18 00:46:58 mortimer Exp $ */
+/* $OpenBSD: main.c,v 1.99 2022/03/14 21:52:08 solene Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -75,8 +75,8 @@ const struct compressor {
"deflate",
".gz",
"\037\213",
- "123456789ab:cdfhLlNnOo:qrS:tVv",
- "cfhLlNno:qrtVv",
+ "123456789ab:cdfhkLlNnOo:qrS:tVv",
+ "cfhkLlNno:qrtVv",
"fhqr",
gz_ropen,
gz_read,
@@ -141,6 +141,7 @@ const struct option longopts[] = {
{ "uncompress", no_argument, 0, 'd' },
{ "force", no_argument, 0, 'f' },
{ "help", no_argument, 0, 'h' },
+ { "keep", no_argument, 0, 'k' },
{ "list", no_argument, 0, 'l' },
{ "license", no_argument, 0, 'L' },
{ "no-name", no_argument, 0, 'n' },
@@ -166,12 +167,12 @@ main(int argc, char *argv[])
const char *optstr, *s;
char *p, *infile;
char outfile[PATH_MAX], _infile[PATH_MAX], suffix[16];
- int bits, ch, error, rc, cflag, oflag;
+ int bits, ch, error, rc, cflag, kflag, oflag;
if (pledge("stdio rpath wpath cpath fattr chown", NULL) == -1)
err(1, "pledge");
- bits = cflag = oflag = 0;
+ bits = cflag = kflag = oflag = 0;
storename = -1;
p = __progname;
if (p[0] == 'g') {
@@ -276,6 +277,9 @@ main(int argc, char *argv[])
strlcpy(suffix, method->suffix, sizeof(suffix));
bits = 6;
break;
+ case 'k':
+ kflag = 1;
+ break;
case 'l':
list++;
testmode = 1;
@@ -458,8 +462,8 @@ main(int argc, char *argv[])
switch (error) {
case SUCCESS:
- if (!cat && !testmode) {
- if (!pipin && unlink(infile) && verbose >= 0)
+ if (!cat && !pipin && !testmode && !kflag) {
+ if (unlink(infile) == -1 && verbose >= 0)
warn("input: %s", infile);
}
break;
@@ -947,13 +951,13 @@ usage(int status)
fprintf(stderr, "usage: %s [-123456789cdf%sh%slNnOqrt%sv] "
"[-b bits] [-o filename] [-S suffix]\n"
" %*s [file ...]\n", __progname,
- !gzip ? "g" : "", gzip ? "L" : "", gzip ? "V" : "",
+ !gzip ? "g" : "", gzip ? "kL" : "", gzip ? "V" : "",
(int)strlen(__progname), "");
break;
case MODE_DECOMP:
fprintf(stderr, "usage: %s [-cfh%slNnqrt%sv] [-o filename] "
"[file ...]\n", __progname,
- gzip ? "L" : "", gzip ? "V" : "");
+ gzip ? "kL" : "", gzip ? "V" : "");
break;
case MODE_CAT:
fprintf(stderr, "usage: %s [-f%shqr] [file ...]\n",