summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2003-12-09 07:34:56 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2003-12-09 07:34:56 +0000
commit62e8aabd3a8153b9b2bf9be54bd64d1e44552d68 (patch)
tree3898967cbb2b2ebc6359ddd2ee0e3dd35b943052
parent0f4a0bc0835143abaf53d8dce692ef65d43f9394 (diff)
Fixes based on a patch from Moritz Jodeit; mickey@ OK
o break out of inflate() when we hit an error o fix printf format #ifdef SMALL o add version string of nullopen.c to -V output o remove unnecessary initializations to 0 for variables cat and decomp o beautify -l output to make it line up with the heading
-rw-r--r--usr.bin/compress/gzopen.c11
-rw-r--r--usr.bin/compress/main.c31
2 files changed, 23 insertions, 19 deletions
diff --git a/usr.bin/compress/gzopen.c b/usr.bin/compress/gzopen.c
index 0527d172b1b..42f18bb2a23 100644
--- a/usr.bin/compress/gzopen.c
+++ b/usr.bin/compress/gzopen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gzopen.c,v 1.16 2003/11/21 21:54:46 millert Exp $ */
+/* $OpenBSD: gzopen.c,v 1.17 2003/12/09 07:34:55 millert Exp $ */
/*
* Copyright (c) 1997 Michael Shalayeff
@@ -59,7 +59,7 @@
*/
const char gz_rcsid[] =
- "$OpenBSD: gzopen.c,v 1.16 2003/11/21 21:54:46 millert Exp $";
+ "$OpenBSD: gzopen.c,v 1.17 2003/12/09 07:34:55 millert Exp $";
#include <sys/param.h>
#include <sys/stat.h>
@@ -407,11 +407,12 @@ gz_read(void *cookie, char *buf, int len)
{
gz_stream *s = (gz_stream*)cookie;
u_char *start = buf; /* starting point for crc computation */
+ int error = Z_OK;
s->z_stream.next_out = buf;
s->z_stream.avail_out = len;
- while (s->z_stream.avail_out != 0 && !s->z_eof) {
+ while (error == Z_OK && !s->z_eof && s->z_stream.avail_out != 0) {
if (s->z_stream.avail_in == 0) {
@@ -422,7 +423,8 @@ gz_read(void *cookie, char *buf, int len)
s->z_stream.next_in = s->z_buf;
}
- if (inflate(&(s->z_stream), Z_NO_FLUSH) == Z_STREAM_END) {
+ error = inflate(&(s->z_stream), Z_NO_FLUSH);
+ if (error == Z_STREAM_END) {
/* Check CRC and original size */
s->z_crc = crc32(s->z_crc, start,
(uInt)(s->z_stream.next_out - start));
@@ -444,6 +446,7 @@ gz_read(void *cookie, char *buf, int len)
}
inflateReset(&(s->z_stream));
s->z_crc = crc32(0L, Z_NULL, 0);
+ error = Z_OK;
}
}
s->z_crc = crc32(s->z_crc, start,
diff --git a/usr.bin/compress/main.c b/usr.bin/compress/main.c
index e6e09a3702d..d4028e2a43c 100644
--- a/usr.bin/compress/main.c
+++ b/usr.bin/compress/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.47 2003/09/05 21:03:36 henning Exp $ */
+/* $OpenBSD: main.c,v 1.48 2003/12/09 07:34:55 millert Exp $ */
static const char copyright[] =
"@(#) Copyright (c) 1992, 1993\n\
@@ -37,7 +37,7 @@ static const char license[] =
#if 0
static char sccsid[] = "@(#)compress.c 8.2 (Berkeley) 1/7/94";
#else
-static const char main_rcsid[] = "$OpenBSD: main.c,v 1.47 2003/09/05 21:03:36 henning Exp $";
+static const char main_rcsid[] = "$OpenBSD: main.c,v 1.48 2003/12/09 07:34:55 millert Exp $";
#endif
#endif /* not lint */
@@ -148,7 +148,7 @@ main(int argc, char *argv[])
char *nargv[512]; /* some estimate based on ARG_MAX */
int bits, exists, oreg, ch, error, i, rc, oflag;
- bits = cat = oflag = decomp = 0;
+ bits = oflag = 0;
nosave = -1;
p = __progname;
if (p[0] == 'g') {
@@ -277,11 +277,10 @@ main(int argc, char *argv[])
decomp++;
break;
case 'V':
- printf("%s\n%s\n%s\n", main_rcsid,
+ printf("%s\n%s\n", main_rcsid, gz_rcsid);
#ifndef SMALL
- z_rcsid,
+ printf("%s\n%s\n", z_rcsid, null_rcsid);
#endif
- gz_rcsid);
exit (0);
case 'v':
verbose++;
@@ -786,25 +785,27 @@ list_stats(const char *name, const struct compressor *method,
static u_int nruns;
char *timestr;
- if (name != NULL && strcmp(name, "/dev/stdout") == 0)
- name += 5;
-
if (nruns == 0) {
if (verbose >= 0) {
if (verbose > 0)
- fputs("method crc date time ", stdout);
- puts("compressed uncompr. ratio uncompressed_name");
+ fputs("method crc date time ", stdout);
+ puts("compressed uncompressed ratio uncompressed_name");
}
}
nruns++;
if (name != NULL) {
+ if (strcmp(name, "/dev/stdout") == 0)
+ name += 5;
if (verbose > 0) {
timestr = ctime(&info->mtime) + 4;
timestr[12] = '\0';
- printf("%.5s %08x %s ", method->name, info->crc, timestr);
+ if (timestr[4] == ' ')
+ timestr[4] = '0';
+ printf("%-7.7s %08x %s ", method->name, info->crc,
+ timestr);
}
- printf("%9lld %9lld %4.1f%% %s\n",
+ printf("%10lld %10lld %4.1f%% %s\n",
(long long)(info->total_in + info->hlen),
(long long)info->total_out,
(info->total_out - info->total_in) *
@@ -816,8 +817,8 @@ list_stats(const char *name, const struct compressor *method,
if (nruns < 3) /* only do totals for > 1 files */
return;
if (verbose > 0)
- fputs(" ", stdout);
- printf("%9lld %9lld %4.1f%% (totals)\n",
+ fputs(" ", stdout);
+ printf("%10lld %10lld %4.1f%% (totals)\n",
(long long)(compressed_total + header_total),
(long long)uncompressed_total,
(uncompressed_total - compressed_total) *