Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/gzip patch from tron@ to convert to using public bz ...
details: https://anonhg.NetBSD.org/src/rev/f285ce07a194
branches: trunk
changeset: 565125:f285ce07a194
user: mrg <mrg%NetBSD.org@localhost>
date: Tue Mar 30 09:15:07 2004 +0000
description:
patch from tron@ to convert to using public bz interfaces. simonb says
no reason not to and this fixes PR#24964.
diffstat:
usr.bin/gzip/gzip.c | 8 ++-
usr.bin/gzip/unbzip2.c | 93 +++++++++++++++++++------------------------------
2 files changed, 41 insertions(+), 60 deletions(-)
diffs (165 lines):
diff -r 267f42e8860a -r f285ce07a194 usr.bin/gzip/gzip.c
--- a/usr.bin/gzip/gzip.c Tue Mar 30 06:08:58 2004 +0000
+++ b/usr.bin/gzip/gzip.c Tue Mar 30 09:15:07 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gzip.c,v 1.29 2004/03/28 13:54:44 mrg Exp $ */
+/* $NetBSD: gzip.c,v 1.30 2004/03/30 09:15:07 mrg Exp $ */
/*
* Copyright (c) 1997, 1998, 2003 Matthew R. Green
@@ -32,7 +32,7 @@
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003 Matthew R. Green\n\
All rights reserved.\n");
-__RCSID("$NetBSD: gzip.c,v 1.29 2004/03/28 13:54:44 mrg Exp $");
+__RCSID("$NetBSD: gzip.c,v 1.30 2004/03/30 09:15:07 mrg Exp $");
#endif /* not lint */
/*
@@ -78,7 +78,6 @@
};
#ifndef NO_BZIP2_SUPPORT
-#define BZ_NO_STDIO
#include <bzlib.h>
#define BZ2_SUFFIX ".bz2"
@@ -746,6 +745,7 @@
maybe_warnx("%s already exists -- skipping", outfile);
goto lose;
}
+ /* XXX wanna do this for -l in -DSMALL */
if (stat(file, &isb) == 0) {
if (isb.st_nlink > 1 && lflag == 0) {
maybe_warnx("%s has %d other links -- skipping",
@@ -761,6 +761,7 @@
if (method == FT_BZIP2) {
int in, out;
+ /* XXX */
if (lflag)
maybe_errx(1, "no -l with bzip2 files");
@@ -785,6 +786,7 @@
FILE *in, *out;
int fd;
+ /* XXX */
if (lflag)
maybe_errx(1, "no -l with Lempel-Ziv files");
diff -r 267f42e8860a -r f285ce07a194 usr.bin/gzip/unbzip2.c
--- a/usr.bin/gzip/unbzip2.c Tue Mar 30 06:08:58 2004 +0000
+++ b/usr.bin/gzip/unbzip2.c Tue Mar 30 09:15:07 2004 +0000
@@ -1,75 +1,54 @@
-/* $NetBSD: unbzip2.c,v 1.1 2004/01/01 02:44:09 mrg Exp $ */
+/* $NetBSD: unbzip2.c,v 1.2 2004/03/30 09:15:07 mrg Exp $ */
/* This file is #included by gzip.c */
-#define INBUFSIZE (64 * 1024)
-#define OUTBUFSIZE (64 * 1024)
-
static off_t
unbzip2(int in, int out)
{
- int n, ret, end_of_file;
+ FILE *f_in;
+ BZFILE *b_in;
+ int bzerror, n;
off_t bytes_out = 0;
- bz_stream bzs;
- char *inbuf, *outbuf;
+ char buffer[64 * 1024];
- if ((inbuf = malloc(INBUFSIZE)) == NULL)
- maybe_err(1, "malloc");
- if ((outbuf = malloc(OUTBUFSIZE)) == NULL)
- maybe_err(1, "malloc");
+ if ((in = dup(in)) < 0)
+ maybe_err(1, "dup");
- bzs.bzalloc = NULL;
- bzs.bzfree = NULL;
- bzs.opaque = NULL;
+ if ((f_in = fdopen(in, "r")) == NULL)
+ maybe_err(1, "fdopen");
- end_of_file = 0;
- ret = BZ2_bzDecompressInit(&bzs, 0, 0);
- if (ret != BZ_OK)
- maybe_errx(1, "bzip2 init");
+ if ((b_in = BZ2_bzReadOpen(&bzerror, f_in, 0, 0, NULL, 0)) == NULL)
+ maybe_err(1, "BZ2_bzReadOpen");
- bzs.avail_in = 0;
+ do {
+ n = BZ2_bzRead(&bzerror, b_in, buffer, sizeof (buffer));
- while (ret != BZ_STREAM_END) {
- if (bzs.avail_in == 0 && !end_of_file) {
- n = read(in, inbuf, INBUFSIZE);
- if (n < 0)
- maybe_err(1, "read");
- if (n == 0)
- end_of_file = 1;
- bzs.next_in = inbuf;
- bzs.avail_in = n;
- } else
- n = 0;
-
- bzs.next_out = outbuf;
- bzs.avail_out = OUTBUFSIZE;
- ret = BZ2_bzDecompress(&bzs);
+ switch (bzerror) {
+ case BZ_IO_ERROR:
+ maybe_errx(1, "bzip2 I/O error");
+ case BZ_UNEXPECTED_EOF:
+ maybe_errx(1, "bzip2 unexpected end of file");
+ case BZ_DATA_ERROR:
+ maybe_errx(1, "bzip2 data integrity error");
+ case BZ_DATA_ERROR_MAGIC:
+ maybe_errx(1, "bzip2 magic number error");
+ case BZ_MEM_ERROR:
+ maybe_errx(1, "bzip2 out of memory");
+ case BZ_OK:
+ case BZ_STREAM_END:
+ break;
+ default:
+ maybe_errx(1, "bzip2 unknown error");
+ }
- switch (ret) {
- case BZ_STREAM_END:
- case BZ_OK:
- if (ret == BZ_OK && end_of_file)
- maybe_err(1, "read");
- if (!tflag) {
- n = write(out, outbuf, OUTBUFSIZE - bzs.avail_out);
- if (n < 0)
- maybe_err(1, "write");
- }
- bytes_out += n;
- if (ret == BZ_STREAM_END)
- break;
+ if ((n = write(out, buffer, n)) < 0)
+ maybe_err(1, "write");
+ bytes_out += n;
+ } while (bzerror != BZ_STREAM_END);
- case BZ_DATA_ERROR:
- maybe_errx(1, "bzip2 data integrity error");
- case BZ_DATA_ERROR_MAGIC:
- maybe_errx(1, "bzip2 magic number error");
- case BZ_MEM_ERROR:
- maybe_errx(1, "bzip2 out of memory");
- }
- }
+ (void)BZ2_bzReadClose(&bzerror, b_in);
+ (void)fclose(f_in);
- if (BZ2_bzDecompressEnd(&bzs) != BZ_OK)
- return (0);
return (bytes_out);
}
Home |
Main Index |
Thread Index |
Old Index