From 77a6c12f15b5228877add2532215f797022d6f0d Mon Sep 17 00:00:00 2001 From: mrg Date: Sat, 6 Nov 2010 21:42:32 +0000 Subject: [PATCH] pull across a few changes from the freebsd folks: http://svn.freebsd.org/changeset/base/213044 - fixes gunzip issues http://svn.freebsd.org/changeset/base/213927 - fixes various typos and comments and also an older change to add support for bzip2's "-k" option: don't delete the input file thanks! --- usr.bin/gzip/gzip.c | 21 ++++++++++++++++----- usr.bin/gzip/unpack.c | 16 ++++++++-------- usr.bin/gzip/zuncompress.c | 4 ++-- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/usr.bin/gzip/gzip.c b/usr.bin/gzip/gzip.c index 03b7d9da51cd..e14f1bc69339 100644 --- a/usr.bin/gzip/gzip.c +++ b/usr.bin/gzip/gzip.c @@ -1,4 +1,4 @@ -/* $NetBSD: gzip.c,v 1.97 2009/10/11 09:17:21 mrg Exp $ */ +/* $NetBSD: gzip.c,v 1.98 2010/11/06 21:42:32 mrg Exp $ */ /* * Copyright (c) 1997, 1998, 2003, 2004, 2006 Matthew R. Green @@ -30,7 +30,7 @@ #ifndef lint __COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006\ Matthew R. Green. All rights reserved."); -__RCSID("$NetBSD: gzip.c,v 1.97 2009/10/11 09:17:21 mrg Exp $"); +__RCSID("$NetBSD: gzip.c,v 1.98 2010/11/06 21:42:32 mrg Exp $"); #endif /* not lint */ /* @@ -148,7 +148,7 @@ static suffixes_t suffixes[] = { #define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0]) #define SUFFIX_MAXLEN 30 -static const char gzip_version[] = "NetBSD gzip 20091011"; +static const char gzip_version[] = "NetBSD gzip 20101018"; static int cflag; /* stdout mode */ static int dflag; /* decompress mode */ @@ -157,6 +157,7 @@ static int numflag = 6; /* gzip -1..-9 value */ #ifndef SMALL static int fflag; /* force mode */ +static int kflag; /* don't delete input files */ static int nflag; /* don't save name/timestamp */ static int Nflag; /* don't restore name/timestamp */ static int qflag; /* quiet mode */ @@ -238,6 +239,7 @@ static 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' }, { "no-name", no_argument, 0, 'n' }, { "name", no_argument, 0, 'N' }, @@ -291,7 +293,7 @@ main(int argc, char **argv) #ifdef SMALL #define OPT_LIST "123456789cdhltV" #else -#define OPT_LIST "123456789cdfhlNnqrS:tVv" +#define OPT_LIST "123456789cdfhklNnqrS:tVv" #endif while ((ch = getopt_long(argc, argv, OPT_LIST, longopts, NULL)) != -1) { @@ -318,6 +320,9 @@ main(int argc, char **argv) case 'f': fflag = 1; break; + case 'k': + kflag = 1; + break; case 'N': nflag = 0; Nflag = 1; @@ -886,6 +891,9 @@ gz_uncompress(int in, int out, char *pre, size_t prelen, off_t *gsizep, switch (error) { /* Z_BUF_ERROR goes with Z_FINISH... */ case Z_BUF_ERROR: + if (z.avail_out > 0 && !done_reading) + continue; + case Z_STREAM_END: case Z_OK: break; @@ -1127,8 +1135,10 @@ unlink_input(const char *file, const struct stat *sb) { struct stat nsb; + if (kflag) + return; if (stat(file, &nsb) != 0) - /* Must be gone alrady */ + /* Must be gone already */ return; if (nsb.st_dev != sb->st_dev || nsb.st_ino != sb->st_ino) /* Definitely a different file */ @@ -1991,6 +2001,7 @@ usage(void) " --uncompress\n" " -f --force force overwriting & compress links\n" " -h --help display this help\n" + " -k --keep don't delete input files during operation\n" " -l --list list compressed file contents\n" " -N --name save or restore original file name and time stamp\n" " -n --no-name don't save original file name or time stamp\n" diff --git a/usr.bin/gzip/unpack.c b/usr.bin/gzip/unpack.c index 8bc16be44d68..93dbadbc3cd0 100644 --- a/usr.bin/gzip/unpack.c +++ b/usr.bin/gzip/unpack.c @@ -1,5 +1,5 @@ /* $FreeBSD: head/usr.bin/gzip/unpack.c 194579 2009-06-21 09:39:43Z delphij $ */ -/* $NetBSD: unpack.c,v 1.1 2009/10/11 07:07:54 mrg Exp $ */ +/* $NetBSD: unpack.c,v 1.2 2010/11/06 21:42:32 mrg Exp $ */ /*- * Copyright (c) 2009 Xin LI @@ -41,7 +41,7 @@ * tree levels, each level would consume 1 byte (See [1]). * * After the symbol count table, there is the symbol table, storing - * symbols represented by coresponding leaf node. EOB is not being + * symbols represented by corresponding leaf node. EOB is not being * explicitly transmitted (not necessary anyway) in the symbol table. * * Compressed data goes after the symbol table. @@ -62,7 +62,7 @@ /* * unpack descriptor * - * Represent the huffman tree in a similiar way that pack(1) would + * Represent the huffman tree in a similar way that pack(1) would * store in a packed file. We store all symbols in a linear table, * and store pointers to each level's first symbol. In addition to * that, maintain two counts for each level: inner nodes count and @@ -93,7 +93,7 @@ typedef struct { * Caller is responsible to make sure that all of these pointers are * initialized (in our case, they all point to valid memory block). * We don't zero out pointers here because nobody else would ever - * reference the memory block without scrubing them. + * reference the memory block without scrubbing them. */ static void unpack_descriptor_fini(unpack_descriptor_t *unpackd) @@ -118,7 +118,7 @@ unpackd_fill_inodesin(const unpack_descriptor_t *unpackd, int level) /* * The internal nodes would be 1/2 of total internal nodes and * leaf nodes in the next level. For the last level there - * would be no internal node by defination. + * would be no internal node by definition. */ if (level < unpackd->treelevels) { unpackd_fill_inodesin(unpackd, level + 1); @@ -141,7 +141,7 @@ accepted_bytes(off_t *bytes_in, off_t newbytes) /* * Read file header and construct the tree. Also, prepare the buffered I/O - * for decode rountine. + * for decode routine. * * Return value is uncompressed size. */ @@ -196,7 +196,7 @@ unpack_parse_header(int in, int out, char *pre, size_t prelen, off_t *bytes_in, /* We count from 0 so adjust to match array upper bound */ unpackd->treelevels--; - /* Read the levels symbol count table and caculate total */ + /* Read the levels symbol count table and calculate total */ unpackd->symbol_size = 1; /* EOB */ for (i = 0; i <= unpackd->treelevels; i++) { if ((thisbyte = fgetc(unpackd->fpIn)) == EOF) @@ -238,7 +238,7 @@ unpack_parse_header(int in, int out, char *pre, size_t prelen, off_t *bytes_in, /* * The symbolsin table has been constructed now. - * Caculate the internal nodes count table based on it. + * Calculate the internal nodes count table based on it. */ unpackd_fill_inodesin(unpackd, 0); } diff --git a/usr.bin/gzip/zuncompress.c b/usr.bin/gzip/zuncompress.c index 5e8969338ac8..0a9ac2e978db 100644 --- a/usr.bin/gzip/zuncompress.c +++ b/usr.bin/gzip/zuncompress.c @@ -1,4 +1,4 @@ -/* $NetBSD: zuncompress.c,v 1.7 2009/04/12 10:31:14 lukem Exp $ */ +/* $NetBSD: zuncompress.c,v 1.8 2010/11/06 21:42:32 mrg Exp $ */ /*- * Copyright (c) 1985, 1986, 1992, 1993 @@ -114,7 +114,7 @@ struct s_zstate { code_int zs_ent; code_int zs_hsize_reg; int zs_hshift; - } w; /* Write paramenters */ + } w; /* Write parameters */ struct { char_type *zs_stackp; int zs_finchar;