svn commit: r207839 - stable/7/usr.bin/gzip
Xin LI
delphij at FreeBSD.org
Mon May 10 02:09:53 UTC 2010
Author: delphij
Date: Mon May 10 02:09:53 2010
New Revision: 207839
URL: http://svn.freebsd.org/changeset/base/207839
Log:
MFC most of the recent changes to gzip(1) back to RELENG_7.
Modified:
stable/7/usr.bin/gzip/gzip.1
stable/7/usr.bin/gzip/gzip.c
stable/7/usr.bin/gzip/unbzip2.c
Directory Properties:
stable/7/usr.bin/gzip/ (props changed)
Modified: stable/7/usr.bin/gzip/gzip.1
==============================================================================
--- stable/7/usr.bin/gzip/gzip.1 Mon May 10 02:07:57 2010 (r207838)
+++ stable/7/usr.bin/gzip/gzip.1 Mon May 10 02:09:53 2010 (r207839)
@@ -25,7 +25,7 @@
.\" SUCH DAMAGE.
.\"
.\" $FreeBSD$
-.Dd June 24, 2009
+.Dd April 27, 2010
.Dt GZIP 1
.Os
.Sh NAME
@@ -205,18 +205,21 @@ This implementation of
.Nm
was ported based on the
.Nx
-.Nm
-20090412, and first appeared in
+.Nm ,
+and first appeared in
.Fx 7.0 .
.Sh AUTHORS
+.An -nosplit
This implementation of
.Nm
was written by
-.An Matthew R. Green Aq mrg at eterna.com.au .
+.An Matthew R. Green Aq mrg at eterna.com.au
+with unpack support written by
+.An Xin LI Aq delphij at FreeBSD.org .
.Sh BUGS
According to RFC 1952, the recorded file size is stored in a 32-bit
-integer and therefore it can not represent files that is bigger than
-4GB in size. This limitation also applies to
+integer, therefore, it can not represent files larger than 4GB.
+This limitation also applies to
.Fl l
option of
.Nm
Modified: stable/7/usr.bin/gzip/gzip.c
==============================================================================
--- stable/7/usr.bin/gzip/gzip.c Mon May 10 02:07:57 2010 (r207838)
+++ stable/7/usr.bin/gzip/gzip.c Mon May 10 02:09:53 2010 (r207839)
@@ -1,4 +1,4 @@
-/* $NetBSD: gzip.c,v 1.94 2009/04/12 10:31:14 lukem Exp $ */
+/* $NetBSD: gzip.c,v 1.97 2009/10/11 09:17:21 mrg Exp $ */
/*-
* Copyright (c) 1997, 1998, 2003, 2004, 2006 Matthew R. Green
@@ -43,7 +43,6 @@ __RCSID("$FreeBSD$");
*
* TODO:
* - use mmap where possible
- * - handle some signals better (remove outfile?)
* - make bzip2/compress -v/-t/-l support work as well as possible
*/
@@ -149,8 +148,9 @@ static suffixes_t suffixes[] = {
#undef SUFFIX
};
#define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0])
+#define SUFFIX_MAXLEN 30
-static const char gzip_version[] = "FreeBSD gzip 20090621";
+static const char gzip_version[] = "FreeBSD gzip 20100407";
#ifndef SMALL
static const char gzip_copyright[] = \
@@ -193,6 +193,7 @@ static int qflag; /* quiet mode */
static int rflag; /* recursive mode */
static int tflag; /* test */
static int vflag; /* verbose mode */
+static const char *remove_file = NULL; /* file to be removed upon SIGINT */
#else
#define qflag 0
#define tflag 0
@@ -204,7 +205,7 @@ static char *infile; /* name of file co
static void maybe_err(const char *fmt, ...) __dead2
__attribute__((__format__(__printf__, 1, 2)));
-#ifndef NO_BZIP2_SUPPORT
+#if !defined(NO_BZIP2_SUPPORT) || !defined(NO_PACK_SUPPORT)
static void maybe_errx(const char *fmt, ...) __dead2
__attribute__((__format__(__printf__, 1, 2)));
#endif
@@ -230,6 +231,7 @@ static void usage(void);
static void display_version(void);
#ifndef SMALL
static void display_license(void);
+static void sigint_handler(int);
#endif
static const suffixes_t *check_suffix(char *, int);
static ssize_t read_retry(int, void *, size_t);
@@ -299,11 +301,10 @@ main(int argc, char **argv)
#endif
int ch;
- /* XXX set up signals */
-
#ifndef SMALL
if ((gzip = getenv("GZIP")) != NULL)
prepend_gzip(gzip, &argc, &argv);
+ signal(SIGINT, sigint_handler);
#endif
/*
@@ -372,6 +373,8 @@ main(int argc, char **argv)
case 'S':
len = strlen(optarg);
if (len != 0) {
+ if (len > SUFFIX_MAXLEN)
+ errx(1, "incorrect suffix: '%s': too long", optarg);
suffixes[0].zipped = optarg;
suffixes[0].ziplen = len;
} else {
@@ -457,7 +460,7 @@ maybe_err(const char *fmt, ...)
exit(2);
}
-#ifndef NO_BZIP2_SUPPORT
+#if !defined(NO_BZIP2_SUPPORT) || !defined(NO_PACK_SUPPORT)
/* ... without an errno. */
void
maybe_errx(const char *fmt, ...)
@@ -1168,6 +1171,15 @@ unlink_input(const char *file, const str
return;
unlink(file);
}
+
+static void
+sigint_handler(int signo __unused)
+{
+
+ if (remove_file != NULL)
+ unlink(remove_file);
+ _exit(2);
+}
#endif
static const suffixes_t *
@@ -1236,7 +1248,7 @@ file_compress(char *file, char *outfile,
/* Add (usually) .gz to filename */
if ((size_t)snprintf(outfile, outsize, "%s%s",
file, suffixes[0].zipped) >= outsize)
- memcpy(outfile - suffixes[0].ziplen - 1,
+ memcpy(outfile + outsize - suffixes[0].ziplen - 1,
suffixes[0].zipped, suffixes[0].ziplen + 1);
#ifndef SMALL
@@ -1254,6 +1266,9 @@ file_compress(char *file, char *outfile,
fclose(stdin);
return -1;
}
+#ifndef SMALL
+ remove_file = outfile;
+#endif
} else
out = STDOUT_FILENO;
@@ -1285,6 +1300,7 @@ file_compress(char *file, char *outfile,
}
copymodes(out, &isb, outfile);
+ remove_file = NULL;
#endif
if (close(out) == -1)
maybe_warn("couldn't close output");
@@ -1315,6 +1331,7 @@ file_uncompress(char *file, char *outfil
enum filetype method;
int fd, ofd, zfd = -1;
#ifndef SMALL
+ ssize_t rv;
time_t timestamp = 0;
unsigned char name[PATH_MAX + 1];
#endif
@@ -1360,7 +1377,6 @@ file_uncompress(char *file, char *outfil
#ifndef SMALL
if (method == FT_GZIP && Nflag) {
unsigned char ts[4]; /* timestamp */
- ssize_t rv;
rv = pread(fd, ts, sizeof ts, GZIP_TIMESTAMP);
if (rv >= 0 && rv < (ssize_t)(sizeof ts))
@@ -1421,6 +1437,9 @@ file_uncompress(char *file, char *outfil
maybe_warn("can't open %s", outfile);
goto lose;
}
+#ifndef SMALL
+ remove_file = outfile;
+#endif
} else
zfd = STDOUT_FILENO;
@@ -1552,11 +1571,12 @@ file_uncompress(char *file, char *outfil
unlink(outfile);
return -1;
}
- unlink_input(file, &isb);
#ifndef SMALL
copymodes(ofd, &isb, outfile);
+ remove_file = NULL;
#endif
close(ofd);
+ unlink_input(file, &isb);
return size;
unexpected_EOF:
@@ -2050,7 +2070,7 @@ static void
display_license(void)
{
- fprintf(stderr, "%s (based on NetBSD gzip 20060927)\n", gzip_version);
+ fprintf(stderr, "%s (based on NetBSD gzip 20091011)\n", gzip_version);
fprintf(stderr, "%s\n", gzip_copyright);
exit(0);
}
@@ -2096,4 +2116,3 @@ read_retry(int fd, void *buf, size_t sz)
return sz - left;
}
-
Modified: stable/7/usr.bin/gzip/unbzip2.c
==============================================================================
--- stable/7/usr.bin/gzip/unbzip2.c Mon May 10 02:07:57 2010 (r207838)
+++ stable/7/usr.bin/gzip/unbzip2.c Mon May 10 02:09:53 2010 (r207839)
@@ -1,4 +1,4 @@
-/* $NetBSD: unbzip2.c,v 1.12 2009/10/11 05:17:20 mrg Exp $ */
+/* $NetBSD: unbzip2.c,v 1.13 2009/12/05 03:23:37 mrg Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
More information about the svn-src-stable
mailing list