summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Karlsson <johan@FreeBSD.org>2002-10-03 19:30:22 +0000
committerJohan Karlsson <johan@FreeBSD.org>2002-10-03 19:30:22 +0000
commit208464c323c6ae84c03248aadefb0848a30af280 (patch)
tree25906745c66eca251888a360f0f08c960796234d
parentd3749f0c2bba7d3a6e9b5ffb1e0d91e19d2470bc (diff)
Notes
-rw-r--r--lib/libz/minigzip.c39
-rw-r--r--usr.bin/minigzip/minigzip.111
2 files changed, 43 insertions, 7 deletions
diff --git a/lib/libz/minigzip.c b/lib/libz/minigzip.c
index 3617dfca7c42..076aa2cc520e 100644
--- a/lib/libz/minigzip.c
+++ b/lib/libz/minigzip.c
@@ -271,7 +271,8 @@ void file_uncompress(file)
/* ===========================================================================
- * Usage: minigzip [-d] [-f] [-h] [-1 to -9] [files...]
+ * Usage: minigzip [-c ] [-d] [-f] [-h] [-1 to -9] [files...]
+ * -c : write to standard output
* -d : decompress
* -f : compress with Z_FILTERED
* -h : compress with Z_HUFFMAN_ONLY
@@ -282,6 +283,7 @@ int main(argc, argv)
int argc;
char *argv[];
{
+ int copyout = 0;
int uncompr = 0;
gzFile file;
char *bname, outmode[20];
@@ -296,12 +298,14 @@ int main(argc, argv)
bname = argv[0];
argc--, argv++;
- if (!strcmp(bname, "gunzip") || !strcmp(bname, "zcat"))
+ if (!strcmp(bname, "gunzip"))
uncompr = 1;
+ else if (!strcmp(bname, "zcat"))
+ copyout = uncompr = 1;
while (argc > 0) {
if (strcmp(*argv, "-c") == 0)
- ; /* Just for compatibility with gzip */
+ copyout = 1;
else if (strcmp(*argv, "-d") == 0)
uncompr = 1;
else if (strcmp(*argv, "-f") == 0)
@@ -328,11 +332,36 @@ int main(argc, argv)
gz_compress(stdin, file);
}
} else {
+ if (copyout) {
+ SET_BINARY_MODE(stdout);
+ }
do {
if (uncompr) {
- file_uncompress(*argv);
+ if (copyout) {
+ file = gzopen(*argv, "rb");
+ if (file == NULL)
+ fprintf(stderr, "%s: can't gzopen %s\n", prog, *argv);
+ else
+ gz_uncompress(file, stdout);
+ } else {
+ file_uncompress(*argv);
+ }
} else {
- file_compress(*argv, outmode);
+ if (copyout) {
+ FILE * in = fopen(*argv, "rb");
+
+ if (in == NULL) {
+ perror(*argv);
+ } else {
+ file = gzdopen(fileno(stdout), outmode);
+ if (file == NULL) error("can't gzdopen stdout");
+
+ gz_compress(in, file);
+ }
+
+ } else {
+ file_compress(*argv, outmode);
+ }
}
} while (argv++, --argc);
}
diff --git a/usr.bin/minigzip/minigzip.1 b/usr.bin/minigzip/minigzip.1
index 0bfe89964ea5..7759296d6acd 100644
--- a/usr.bin/minigzip/minigzip.1
+++ b/usr.bin/minigzip/minigzip.1
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd December 13, 1997
+.Dd October 3, 2002
.Dt MINIGZIP 1
.Os
.Sh NAME
@@ -32,7 +32,7 @@
.Nd minimal implementation of the 'gzip' compression tool
.Sh SYNOPSIS
.Nm
-.Op Fl d
+.Op Fl cd
.Op Ar
.Sh DESCRIPTION
The
@@ -64,6 +64,13 @@ arguments are supplied,
.Nm
reads from standard input and writes the results of the operation
to standard output.
+.Pp
+If the
+.Fl c
+option is specified,
+.Nm
+writes the results to standard output and keep the original files
+unchanged.
.Sh SEE ALSO
.Xr gzip 1
.Sh AUTHORS