[Midnightbsd-cvs] src [11513] update gzip

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Jul 7 15:18:56 EDT 2018


Revision: 11513
          http://svnweb.midnightbsd.org/src/?rev=11513
Author:   laffer1
Date:     2018-07-07 15:18:55 -0400 (Sat, 07 Jul 2018)
Log Message:
-----------
update gzip

Modified Paths:
--------------
    trunk/usr.bin/gzip/Makefile
    trunk/usr.bin/gzip/gzexe
    trunk/usr.bin/gzip/gzexe.1
    trunk/usr.bin/gzip/gzip.1
    trunk/usr.bin/gzip/gzip.c
    trunk/usr.bin/gzip/unbzip2.c
    trunk/usr.bin/gzip/unpack.c
    trunk/usr.bin/gzip/zdiff
    trunk/usr.bin/gzip/zdiff.1
    trunk/usr.bin/gzip/zforce
    trunk/usr.bin/gzip/zforce.1
    trunk/usr.bin/gzip/zmore
    trunk/usr.bin/gzip/zmore.1
    trunk/usr.bin/gzip/znew
    trunk/usr.bin/gzip/znew.1
    trunk/usr.bin/gzip/zuncompress.c

Added Paths:
-----------
    trunk/usr.bin/gzip/tests/
    trunk/usr.bin/gzip/tests/Makefile
    trunk/usr.bin/gzip/unxz.c

Property Changed:
----------------
    trunk/usr.bin/gzip/gzexe
    trunk/usr.bin/gzip/gzexe.1
    trunk/usr.bin/gzip/gzip.1
    trunk/usr.bin/gzip/zdiff
    trunk/usr.bin/gzip/zdiff.1
    trunk/usr.bin/gzip/zforce
    trunk/usr.bin/gzip/zforce.1
    trunk/usr.bin/gzip/zmore
    trunk/usr.bin/gzip/zmore.1
    trunk/usr.bin/gzip/znew
    trunk/usr.bin/gzip/znew.1

Modified: trunk/usr.bin/gzip/Makefile
===================================================================
--- trunk/usr.bin/gzip/Makefile	2018-07-07 19:16:31 UTC (rev 11512)
+++ trunk/usr.bin/gzip/Makefile	2018-07-07 19:18:55 UTC (rev 11513)
@@ -1,5 +1,6 @@
-#	$NetBSD: Makefile,v 1.13 2009/04/14 22:15:20 lukem Exp $
 # $MidnightBSD$
+#	$NetBSD: Makefile,v 1.18 2013/11/13 11:12:24 pettai Exp $
+# $FreeBSD: stable/10/usr.bin/gzip/Makefile 292588 2015-12-22 08:03:23Z delphij $
 
 .include <bsd.own.mk>
 
@@ -6,8 +7,8 @@
 PROG=		gzip
 MAN=		gzip.1 gzexe.1 zdiff.1 zforce.1 zmore.1 znew.1
 
-DPADD=		${LIBZ}
-LDADD=		-lz
+DPADD=		${LIBZ} ${LIBLZMA} ${LIBPTHREAD}
+LDADD=		-lz -llzma -lpthread
 
 .if ${MK_BZIP2_SUPPORT} != "no"
 DPADD+=		${LIBBZ2}
@@ -21,7 +22,8 @@
 MLINKS+=	gzip.1 gunzip.1 \
 		gzip.1 gzcat.1 \
 		gzip.1 zcat.1 \
-		zdiff.1 zcmp.1
+		zdiff.1 zcmp.1 \
+		zmore.1 zless.1
 
 LINKS+=		${BINDIR}/gzip ${BINDIR}/gunzip \
 		${BINDIR}/gzip ${BINDIR}/gzcat \
@@ -28,4 +30,8 @@
 		${BINDIR}/gzip ${BINDIR}/zcat \
 		${BINDIR}/zdiff ${BINDIR}/zcmp
 
+.if ${MK_TESTS} != "no"
+SUBDIR+=	tests
+.endif
+
 .include <bsd.prog.mk>

Modified: trunk/usr.bin/gzip/gzexe
===================================================================
--- trunk/usr.bin/gzip/gzexe	2018-07-07 19:16:31 UTC (rev 11512)
+++ trunk/usr.bin/gzip/gzexe	2018-07-07 19:18:55 UTC (rev 11513)
@@ -2,7 +2,7 @@
 #
 # $NetBSD: gzexe,v 1.3 2004/05/01 08:22:41 wiz Exp $
 # $OpenBSD: gzexe,v 1.3 2003/08/05 18:22:17 deraadt Exp $
-#
+# $MidnightBSD$
 #-
 #  Copyright (c) 2003 Otto Moerbeek <otto at drijf.net>
 #
@@ -18,7 +18,7 @@
 #  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 #  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #
-# $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/gzip/gzexe 166255 2007-01-26 10:19:08Z delphij $
 
 # The number of lines plus one in the on-the-fly decompression script
 lines=19


Property changes on: trunk/usr.bin/gzip/gzexe
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/gzip/gzexe.1
===================================================================
--- trunk/usr.bin/gzip/gzexe.1	2018-07-07 19:16:31 UTC (rev 11512)
+++ trunk/usr.bin/gzip/gzexe.1	2018-07-07 19:18:55 UTC (rev 11513)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\"	$NetBSD: gzexe.1,v 1.3 2003/12/28 12:49:41 wiz Exp $
 .\"	$OpenBSD: gzexe.1,v 1.1 2003/07/31 07:32:47 otto Exp $
 .\"
@@ -15,7 +16,7 @@
 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.bin/gzip/gzexe.1 166255 2007-01-26 10:19:08Z delphij $
 .Dd January 26, 2007
 .Dt GZEXE 1
 .Os


Property changes on: trunk/usr.bin/gzip/gzexe.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/gzip/gzip.1
===================================================================
--- trunk/usr.bin/gzip/gzip.1	2018-07-07 19:16:31 UTC (rev 11512)
+++ trunk/usr.bin/gzip/gzip.1	2018-07-07 19:18:55 UTC (rev 11513)
@@ -1,4 +1,5 @@
-.\"	$NetBSD: gzip.1,v 1.20 2009/04/01 08:15:37 mrg Exp $
+.\" $MidnightBSD$
+.\"	$NetBSD: gzip.1,v 1.26 2015/10/27 07:36:18 mrg Exp $
 .\"
 .\" Copyright (c) 1997, 2003, 2004 Matthew R. Green
 .\" All rights reserved.
@@ -24,8 +25,8 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $MidnightBSD$
-.Dd May 23, 2011
+.\" $FreeBSD: stable/10/usr.bin/gzip/gzip.1 290569 2015-11-09 01:53:54Z delphij $
+.Dd October 26, 2015
 .Dt GZIP 1
 .Os
 .Sh NAME
@@ -105,9 +106,10 @@
 This version of
 .Nm
 is also capable of decompressing files compressed using
-.Xr compress 1
+.Xr compress 1 ,
+.Xr bzip2 1 ,
 or
-.Xr bzip2 1 .
+.Xr xz 1 .
 .Sh OPTIONS
 The following options are available:
 .Bl -tag -width XXrXXXrecursiveX
@@ -135,7 +137,7 @@
 .It Fl h , -help
 This option prints a usage summary and exits.
 .It Fl k , -keep
-Keep (don't delete) input files during compression
+Keep (do not delete) input files during compression
 or decompression.
 .It Fl L , -license
 This option prints
@@ -182,9 +184,16 @@
 handled before any options on the command line.
 Options on the command line will override anything in
 .Ev GZIP .
+.Sh EXIT STATUS
+The
+.Nm
+utility exits 0 on success,
+1 on errors,
+and 2 if a warning occurs.
 .Sh SEE ALSO
 .Xr bzip2 1 ,
 .Xr compress 1 ,
+.Xr xz 1 ,
 .Xr fts 3 ,
 .Xr zlib 3
 .Sh HISTORY
@@ -218,7 +227,7 @@
 .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, therefore, it can not represent files larger than 4GB.
+integer, therefore, it cannot represent files larger than 4GB.
 This limitation also applies to
 .Fl l
 option of


Property changes on: trunk/usr.bin/gzip/gzip.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/gzip/gzip.c
===================================================================
--- trunk/usr.bin/gzip/gzip.c	2018-07-07 19:16:31 UTC (rev 11512)
+++ trunk/usr.bin/gzip/gzip.c	2018-07-07 19:18:55 UTC (rev 11513)
@@ -1,4 +1,5 @@
-/*	$NetBSD: gzip.c,v 1.99 2011/03/23 12:59:44 tsutsui Exp $	*/
+/* $MidnightBSD$ */
+/*	$NetBSD: gzip.c,v 1.109 2015/10/27 07:36:18 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2003, 2004, 2006 Matthew R. Green
@@ -31,7 +32,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006\
  Matthew R. Green.  All rights reserved.");
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/gzip/gzip.c 327192 2017-12-26 08:33:02Z delphij $");
 #endif /* not lint */
 
 /*
@@ -77,6 +78,9 @@
 #ifndef NO_PACK_SUPPORT
 	FT_PACK,
 #endif
+#ifndef NO_XZ_SUPPORT
+	FT_XZ,
+#endif
 	FT_LAST,
 	FT_UNKNOWN
 };
@@ -97,6 +101,12 @@
 #define PACK_MAGIC	"\037\036"
 #endif
 
+#ifndef NO_XZ_SUPPORT
+#include <lzma.h>
+#define XZ_SUFFIX	".xz"
+#define XZ_MAGIC	"\3757zXZ"
+#endif
+
 #define GZ_SUFFIX	".gz"
 
 #define BUFLEN		(64 * 1024)
@@ -139,6 +149,9 @@
 #ifndef NO_COMPRESS_SUPPORT
 	SUFFIX(Z_SUFFIX,	""),
 #endif
+#ifndef NO_XZ_SUPPORT
+	SUFFIX(XZ_SUFFIX,	""),
+#endif
 	SUFFIX(GZ_SUFFIX,	""),	/* Overwritten by -S "" */
 #endif /* SMALL */
 #undef SUFFIX
@@ -146,7 +159,7 @@
 #define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0])
 #define SUFFIX_MAXLEN	30
 
-static	const char	gzip_version[] = "FreeBSD gzip 20110523";
+static	const char	gzip_version[] = "FreeBSD gzip 20150413";
 
 #ifndef SMALL
 static	const char	gzip_copyright[] = \
@@ -199,16 +212,13 @@
 
 static	char	*infile;		/* name of file coming in */
 
-static	void	maybe_err(const char *fmt, ...) __dead2
-    __attribute__((__format__(__printf__, 1, 2)));
-#if !defined(NO_BZIP2_SUPPORT) || !defined(NO_PACK_SUPPORT)
-static	void	maybe_errx(const char *fmt, ...) __dead2
-    __attribute__((__format__(__printf__, 1, 2)));
+static	void	maybe_err(const char *fmt, ...) __printflike(1, 2) __dead2;
+#if !defined(NO_BZIP2_SUPPORT) || !defined(NO_PACK_SUPPORT) ||	\
+    !defined(NO_XZ_SUPPORT)
+static	void	maybe_errx(const char *fmt, ...) __printflike(1, 2) __dead2;
 #endif
-static	void	maybe_warn(const char *fmt, ...)
-    __attribute__((__format__(__printf__, 1, 2)));
-static	void	maybe_warnx(const char *fmt, ...)
-    __attribute__((__format__(__printf__, 1, 2)));
+static	void	maybe_warn(const char *fmt, ...) __printflike(1, 2);
+static	void	maybe_warnx(const char *fmt, ...) __printflike(1, 2);
 static	enum filetype file_gettype(u_char *);
 #ifdef SMALL
 #define gz_compress(if, of, sz, fn, tm) gz_compress(if, of, sz)
@@ -223,8 +233,8 @@
 static	void	handle_stdout(void);
 static	void	print_ratio(off_t, off_t, FILE *);
 static	void	print_list(int fd, off_t, const char *, time_t);
-static	void	usage(void);
-static	void	display_version(void);
+static	void	usage(void) __dead2;
+static	void	display_version(void) __dead2;
 #ifndef SMALL
 static	void	display_license(void);
 static	void	sigint_handler(int);
@@ -257,7 +267,9 @@
 static	off_t	unpack(int, int, char *, size_t, off_t *);
 #endif
 
-int main(int, char **p);
+#ifndef NO_XZ_SUPPORT
+static	off_t	unxz(int, int, char *, size_t, off_t *);
+#endif
 
 #ifdef SMALL
 #define getopt_long(a,b,c,d,e) getopt(a,b,c)
@@ -456,7 +468,8 @@
 	exit(2);
 }
 
-#if !defined(NO_BZIP2_SUPPORT) || !defined(NO_PACK_SUPPORT)
+#if !defined(NO_BZIP2_SUPPORT) || !defined(NO_PACK_SUPPORT) ||	\
+    !defined(NO_XZ_SUPPORT)
 /* ... without an errno. */
 void
 maybe_errx(const char *fmt, ...)
@@ -798,6 +811,7 @@
 				if (in_tot > 0) {
 					maybe_warnx("%s: trailing garbage "
 						    "ignored", filename);
+					exit_value = 2;
 					goto stop;
 				}
 				maybe_warnx("input not gziped (MAGIC0)");
@@ -1122,6 +1136,11 @@
 		return FT_PACK;
 	else
 #endif
+#ifndef NO_XZ_SUPPORT
+	if (memcmp(buf, XZ_MAGIC, 4) == 0)	/* XXX: We only have 4 bytes */
+		return FT_XZ;
+	else
+#endif
 		return FT_UNKNOWN;
 }
 
@@ -1337,7 +1356,7 @@
 #ifndef SMALL
 	ssize_t rv;
 	time_t timestamp = 0;
-	unsigned char name[PATH_MAX + 1];
+	char name[PATH_MAX + 1];
 #endif
 
 	/* gather the old name info */
@@ -1369,7 +1388,6 @@
 	}
 
 	method = file_gettype(header1);
-
 #ifndef SMALL
 	if (fflag == 0 && method == FT_UNKNOWN) {
 		maybe_warnx("%s: not in gzip format", file);
@@ -1393,14 +1411,26 @@
 		timestamp = ts[3] << 24 | ts[2] << 16 | ts[1] << 8 | ts[0];
 
 		if (header1[3] & ORIG_NAME) {
-			rbytes = pread(fd, name, sizeof name, GZIP_ORIGNAME);
+			rbytes = pread(fd, name, sizeof(name) - 1, GZIP_ORIGNAME);
 			if (rbytes < 0) {
 				maybe_warn("can't read %s", file);
 				goto lose;
 			}
-			if (name[0] != 0) {
+			if (name[0] != '\0') {
+				char *dp, *nf;
+
+				/* Make sure that name is NUL-terminated */
+				name[rbytes] = '\0';
+
+				/* strip saved directory name */
+				nf = strrchr(name, '/');
+				if (nf == NULL)
+					nf = name;
+				else
+					nf++;
+
 				/* preserve original directory name */
-				char *dp = strrchr(file, '/');
+				dp = strrchr(file, '/');
 				if (dp == NULL)
 					dp = file;
 				else
@@ -1407,7 +1437,7 @@
 					dp++;
 				snprintf(outfile, outsize, "%.*s%.*s",
 						(int) (dp - file), 
-						file, (int) rbytes, name);
+						file, (int) rbytes, nf);
 			}
 		}
 	}
@@ -1447,9 +1477,9 @@
 	} else
 		zfd = STDOUT_FILENO;
 
+	switch (method) {
 #ifndef NO_BZIP2_SUPPORT
-	if (method == FT_BZIP2) {
-
+	case FT_BZIP2:
 		/* XXX */
 		if (lflag) {
 			maybe_warnx("no -l with bzip2 files");
@@ -1457,11 +1487,11 @@
 		}
 
 		size = unbzip2(fd, zfd, NULL, 0, NULL);
-	} else
+		break;
 #endif
 
 #ifndef NO_COMPRESS_SUPPORT
-	if (method == FT_Z) {
+	case FT_Z: {
 		FILE *in, *out;
 
 		/* XXX */
@@ -1494,11 +1524,12 @@
 			unlink(outfile);
 			goto lose;
 		}
-	} else
+		break;
+	}
 #endif
 
 #ifndef NO_PACK_SUPPORT
-	if (method == FT_PACK) {
+	case FT_PACK:
 		if (lflag) {
 			maybe_warnx("no -l with packed files");
 			goto lose;
@@ -1505,19 +1536,30 @@
 		}
 
 		size = unpack(fd, zfd, NULL, 0, NULL);
-	} else
+		break;
 #endif
 
+#ifndef NO_XZ_SUPPORT
+	case FT_XZ:
+		if (lflag) {
+			maybe_warnx("no -l with xz files");
+			goto lose;
+		}
+
+		size = unxz(fd, zfd, NULL, 0, NULL);
+		break;
+#endif
+
 #ifndef SMALL
-	if (method == FT_UNKNOWN) {
+	case FT_UNKNOWN:
 		if (lflag) {
 			maybe_warnx("no -l for unknown filetypes");
 			goto lose;
 		}
 		size = cat_fd(NULL, 0, NULL, fd);
-	} else
+		break;
 #endif
-	{
+	default:
 		if (lflag) {
 			print_list(fd, isb.st_size, outfile, isb.st_mtime);
 			close(fd);
@@ -1525,6 +1567,7 @@
 		}
 
 		size = gz_uncompress(fd, zfd, NULL, 0, NULL, file);
+		break;
 	}
 
 	if (close(fd) != 0)
@@ -1588,7 +1631,7 @@
 	if (fd != -1)
 		close(fd);
 	if (zfd != -1 && zfd != STDOUT_FILENO)
-		close(fd);
+		close(zfd);
 	return -1;
 }
 
@@ -1697,7 +1740,8 @@
 			return;
 		}
 
-		usize = zuncompress(in, stdout, (char *)header1, sizeof header1, &gsize);
+		usize = zuncompress(in, stdout, (char *)header1,
+		    sizeof header1, &gsize);
 		fclose(in);
 		break;
 #endif
@@ -1707,6 +1751,12 @@
 			       (char *)header1, sizeof header1, &gsize);
 		break;
 #endif
+#ifndef NO_XZ_SUPPORT
+	case FT_XZ:
+		usize = unxz(STDIN_FILENO, STDOUT_FILENO,
+			     (char *)header1, sizeof header1, &gsize);
+		break;
+#endif
 	}
 
 #ifndef SMALL
@@ -1733,7 +1783,7 @@
 		return;
 	}
 #endif
-	/* If stdin is a file use it's mtime, otherwise use current time */
+	/* If stdin is a file use its mtime, otherwise use current time */
 	ret = fstat(STDIN_FILENO, &sb);
 
 #ifndef SMALL
@@ -2074,7 +2124,7 @@
 display_license(void)
 {
 
-	fprintf(stderr, "%s (based on NetBSD gzip 20091011)\n", gzip_version);
+	fprintf(stderr, "%s (based on NetBSD gzip 20150113)\n", gzip_version);
 	fprintf(stderr, "%s\n", gzip_copyright);
 	exit(0);
 }
@@ -2098,6 +2148,9 @@
 #ifndef NO_PACK_SUPPORT
 #include "unpack.c"
 #endif
+#ifndef NO_XZ_SUPPORT
+#include "unxz.c"
+#endif
 
 static ssize_t
 read_retry(int fd, void *buf, size_t sz)

Added: trunk/usr.bin/gzip/tests/Makefile
===================================================================
--- trunk/usr.bin/gzip/tests/Makefile	                        (rev 0)
+++ trunk/usr.bin/gzip/tests/Makefile	2018-07-07 19:18:55 UTC (rev 11513)
@@ -0,0 +1,10 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/gzip/tests/Makefile 313488 2017-02-09 22:49:48Z ngie $
+
+.include <bsd.own.mk>
+
+NETBSD_ATF_TESTS_SH=	gzip_test
+
+.include <netbsd-tests.test.mk>
+
+.include <bsd.test.mk>


Property changes on: trunk/usr.bin/gzip/tests/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/usr.bin/gzip/unbzip2.c
===================================================================
--- trunk/usr.bin/gzip/unbzip2.c	2018-07-07 19:16:31 UTC (rev 11512)
+++ trunk/usr.bin/gzip/unbzip2.c	2018-07-07 19:18:55 UTC (rev 11513)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: unbzip2.c,v 1.13 2009/12/05 03:23:37 mrg Exp $	*/
 
 /*-
@@ -28,7 +29,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.bin/gzip/unbzip2.c 206387 2010-04-07 22:54:53Z delphij $
  */
 
 /* This file is #included by gzip.c */

Modified: trunk/usr.bin/gzip/unpack.c
===================================================================
--- trunk/usr.bin/gzip/unpack.c	2018-07-07 19:16:31 UTC (rev 11512)
+++ trunk/usr.bin/gzip/unpack.c	2018-07-07 19:18:55 UTC (rev 11513)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2009 Xin LI <delphij at FreeBSD.org>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.bin/gzip/unpack.c 309789 2016-12-10 06:27:45Z delphij $
  */
 
 /* This file is #included by gzip.c */
@@ -68,22 +69,22 @@
  * leaf nodes count.
  */
 typedef struct {
-	int		symbol_size;	/* Size of the symbol table */
-	int		treelevels;	/* Levels for the huffman tree */
+	int	symbol_size;		/* Size of the symbol table */
+	int	treelevels;		/* Levels for the huffman tree */
 
-	int		*symbolsin;	/* Table of leaf symbols count in
-					   each level */
-	int		*inodesin;	/* Table of internal nodes count in
-					   each level */
+	int    *symbolsin;		/* Table of leaf symbols count in each
+					 * level */
+	int    *inodesin;		/* Table of internal nodes count in
+					 * each level */
 
-	char		*symbol;	/* The symbol table */
-	char		*symbol_eob;	/* Pointer to the EOB symbol */
-	char		**tree;		/* Decoding huffman tree (pointers to
-					   first symbol of each tree level */
+	char   *symbol;			/* The symbol table */
+	char   *symbol_eob;		/* Pointer to the EOB symbol */
+	char  **tree;			/* Decoding huffman tree (pointers to
+					 * first symbol of each tree level */
 
-	off_t		uncompressed_size; /* Uncompressed size */
-	FILE		*fpIn;		/* Input stream */
-	FILE		*fpOut;		/* Output stream */
+	off_t	uncompressed_size;	/* Uncompressed size */
+	FILE   *fpIn;			/* Input stream */
+	FILE   *fpOut;			/* Output stream */
 } unpack_descriptor_t;
 
 /*
@@ -122,7 +123,7 @@
 	if (level < unpackd->treelevels) {
 		unpackd_fill_inodesin(unpackd, level + 1);
 		unpackd->inodesin[level] = (unpackd->inodesin[level + 1] +
-					  unpackd->symbolsin[level + 1]) / 2;
+		    unpackd->symbolsin[level + 1]) / 2;
 	} else
 		unpackd->inodesin[level] = 0;
 }
@@ -163,7 +164,7 @@
 
 	accepted_bytes(bytes_in, PACK_HEADER_LENGTH);
 
-	/* Obtain uncompressed length (bytes 2,3,4,5)*/
+	/* Obtain uncompressed length (bytes 2,3,4,5) */
 	unpackd->uncompressed_size = 0;
 	for (i = 2; i <= 5; i++) {
 		unpackd->uncompressed_size <<= 8;
@@ -187,7 +188,7 @@
 	unpackd->symbolsin =
 	    calloc(unpackd->treelevels, sizeof(*(unpackd->symbolsin)));
 	unpackd->tree =
-	    calloc(unpackd->treelevels, (sizeof (*(unpackd->tree))));
+	    calloc(unpackd->treelevels, (sizeof(*(unpackd->tree))));
 	if (unpackd->inodesin == NULL || unpackd->symbolsin == NULL ||
 	    unpackd->tree == NULL)
 		maybe_err("calloc");
@@ -196,7 +197,7 @@
 	unpackd->treelevels--;
 
 	/* Read the levels symbol count table and calculate total */
-	unpackd->symbol_size = 1;		/* EOB */
+	unpackd->symbol_size = 1;	/* EOB */
 	for (i = 0; i <= unpackd->treelevels; i++) {
 		if ((thisbyte = fgetc(unpackd->fpIn)) == EOF)
 			maybe_err("File appears to be truncated");
@@ -310,7 +311,7 @@
 static off_t
 unpack(int in, int out, char *pre, size_t prelen, off_t *bytes_in)
 {
-	unpack_descriptor_t	unpackd;
+	unpack_descriptor_t unpackd;
 
 	in = dup(in);
 	if (in == -1)
@@ -326,4 +327,3 @@
 	/* If we reached here, the unpack was successful */
 	return (unpackd.uncompressed_size);
 }
-

Added: trunk/usr.bin/gzip/unxz.c
===================================================================
--- trunk/usr.bin/gzip/unxz.c	                        (rev 0)
+++ trunk/usr.bin/gzip/unxz.c	2018-07-07 19:18:55 UTC (rev 11513)
@@ -0,0 +1,154 @@
+/* $MidnightBSD$ */
+/*	$NetBSD: unxz.c,v 1.6 2016/01/29 15:19:01 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/usr.bin/gzip/unxz.c 319281 2017-05-31 05:33:32Z delphij $");
+
+#include <stdarg.h>
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <lzma.h>
+
+static off_t
+unxz(int i, int o, char *pre, size_t prelen, off_t *bytes_in)
+{
+	lzma_stream strm = LZMA_STREAM_INIT;
+	static const int flags = LZMA_TELL_UNSUPPORTED_CHECK|LZMA_CONCATENATED;
+	lzma_ret ret;
+	lzma_action action = LZMA_RUN;
+	off_t bytes_out, bp;
+	uint8_t ibuf[BUFSIZ];
+	uint8_t obuf[BUFSIZ];
+
+	if (bytes_in == NULL)
+		bytes_in = &bp;
+
+	strm.next_in = ibuf;
+	memcpy(ibuf, pre, prelen);
+	strm.avail_in = read(i, ibuf + prelen, sizeof(ibuf) - prelen);
+	if (strm.avail_in == (size_t)-1)
+		maybe_err("read failed");
+	strm.avail_in += prelen;
+	*bytes_in = strm.avail_in;
+
+	if ((ret = lzma_stream_decoder(&strm, UINT64_MAX, flags)) != LZMA_OK)
+		maybe_errx("Can't initialize decoder (%d)", ret);
+
+	strm.next_out = NULL;
+	strm.avail_out = 0;
+	if ((ret = lzma_code(&strm, LZMA_RUN)) != LZMA_OK)
+		maybe_errx("Can't read headers (%d)", ret);
+
+	bytes_out = 0;
+	strm.next_out = obuf;
+	strm.avail_out = sizeof(obuf);
+
+	for (;;) {
+		if (strm.avail_in == 0) {
+			strm.next_in = ibuf;
+			strm.avail_in = read(i, ibuf, sizeof(ibuf));
+			switch (strm.avail_in) {
+			case (size_t)-1:
+				maybe_err("read failed");
+				/*NOTREACHED*/
+			case 0:
+				action = LZMA_FINISH;
+				break;
+			default:
+				*bytes_in += strm.avail_in;
+				break;
+			}
+		}
+
+		ret = lzma_code(&strm, action);
+
+		// Write and check write error before checking decoder error.
+		// This way as much data as possible gets written to output
+		// even if decoder detected an error.
+		if (strm.avail_out == 0 || ret != LZMA_OK) {
+			const size_t write_size = sizeof(obuf) - strm.avail_out;
+
+			if (write(o, obuf, write_size) != (ssize_t)write_size)
+				maybe_err("write failed");
+
+			strm.next_out = obuf;
+			strm.avail_out = sizeof(obuf);
+			bytes_out += write_size;
+		}
+
+		if (ret != LZMA_OK) {
+			if (ret == LZMA_STREAM_END) {
+				// Check that there's no trailing garbage.
+				if (strm.avail_in != 0 || read(i, ibuf, 1))
+					ret = LZMA_DATA_ERROR;
+				else {
+					lzma_end(&strm);
+					return bytes_out;
+				}
+			}
+
+			const char *msg;
+			switch (ret) {
+			case LZMA_MEM_ERROR:
+				msg = strerror(ENOMEM);
+				break;
+
+			case LZMA_FORMAT_ERROR:
+				msg = "File format not recognized";
+				break;
+
+			case LZMA_OPTIONS_ERROR:
+				// FIXME: Better message?
+				msg = "Unsupported compression options";
+				break;
+
+			case LZMA_DATA_ERROR:
+				msg = "File is corrupt";
+				break;
+
+			case LZMA_BUF_ERROR:
+				msg = "Unexpected end of input";
+				break;
+
+			case LZMA_MEMLIMIT_ERROR:
+				msg = "Reached memory limit";
+				break;
+
+			default:
+				maybe_errx("Unknown error (%d)", ret);
+				break;
+			}
+			maybe_errx("%s", msg);
+
+		}
+	}
+}


Property changes on: trunk/usr.bin/gzip/unxz.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/usr.bin/gzip/zdiff
===================================================================
--- trunk/usr.bin/gzip/zdiff	2018-07-07 19:16:31 UTC (rev 11512)
+++ trunk/usr.bin/gzip/zdiff	2018-07-07 19:18:55 UTC (rev 11513)
@@ -3,7 +3,7 @@
 # $NetBSD: zdiff,v 1.5 2010/04/14 20:30:28 joerg Exp $
 #
 # $OpenBSD: zdiff,v 1.2 2003/07/29 07:42:44 otto Exp $
-#
+# $MidnightBSD$
 #-
 # Copyright (c) 2003 Todd C. Miller <Todd.Miller at courtesan.com>
 # Copyright (c) 2010 Joerg Sonnenberger <joerg at NetBSD.org>
@@ -24,7 +24,7 @@
 # Agency (DARPA) and Air Force Research Laboratory, Air Force
 # Materiel Command, USAF, under agreement number F39502-99-1-0512.
 #
-# $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/gzip/zdiff 222210 2011-05-23 09:02:44Z delphij $
 
 # Set $prog based on $0
 case $0 in


Property changes on: trunk/usr.bin/gzip/zdiff
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/gzip/zdiff.1
===================================================================
--- trunk/usr.bin/gzip/zdiff.1	2018-07-07 19:16:31 UTC (rev 11512)
+++ trunk/usr.bin/gzip/zdiff.1	2018-07-07 19:18:55 UTC (rev 11513)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\"	$NetBSD: zdiff.1,v 1.5 2010/04/14 19:52:05 wiz Exp $
 .\"	$OpenBSD: zdiff.1,v 1.2 2003/07/13 17:39:14 millert Exp $
 .\"
@@ -20,7 +21,7 @@
 .\" Agency (DARPA) and Air Force Research Laboratory, Air Force
 .\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
 .\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.bin/gzip/zdiff.1 222210 2011-05-23 09:02:44Z delphij $
 .Dd May 23, 2011
 .Dt ZDIFF 1
 .Os


Property changes on: trunk/usr.bin/gzip/zdiff.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/gzip/zforce
===================================================================
--- trunk/usr.bin/gzip/zforce	2018-07-07 19:16:31 UTC (rev 11512)
+++ trunk/usr.bin/gzip/zforce	2018-07-07 19:18:55 UTC (rev 11513)
@@ -2,7 +2,7 @@
 #
 # $NetBSD: zforce,v 1.2 2003/12/28 12:43:43 wiz Exp $
 # $OpenBSD: zforce,v 1.2 2003/08/05 18:22:17 deraadt Exp $
-#
+# $MidnightBSD$
 #-
 # Copyright (c) 2003 Otto Moerbeek <otto at drijf.net>
 #
@@ -18,7 +18,7 @@
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #
-# $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/gzip/zforce 166255 2007-01-26 10:19:08Z delphij $
 prog=`basename $0`
 USAGE="usage: $prog file ..."
 if test $# -eq 0; then


Property changes on: trunk/usr.bin/gzip/zforce
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/gzip/zforce.1
===================================================================
--- trunk/usr.bin/gzip/zforce.1	2018-07-07 19:16:31 UTC (rev 11512)
+++ trunk/usr.bin/gzip/zforce.1	2018-07-07 19:18:55 UTC (rev 11513)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\"	$NetBSD: zforce.1,v 1.2 2003/12/28 12:43:43 wiz Exp $
 .\"	$OpenBSD: zforce.1,v 1.1 2003/07/29 11:50:09 otto Exp $
 .\"
@@ -15,7 +16,7 @@
 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.bin/gzip/zforce.1 166255 2007-01-26 10:19:08Z delphij $
 .Dd January 26, 2007
 .Dt ZFORCE 1
 .Os


Property changes on: trunk/usr.bin/gzip/zforce.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/gzip/zmore
===================================================================
--- trunk/usr.bin/gzip/zmore	2018-07-07 19:16:31 UTC (rev 11512)
+++ trunk/usr.bin/gzip/zmore	2018-07-07 19:18:55 UTC (rev 11513)
@@ -1,8 +1,9 @@
 #!/bin/sh -
 #
-# $NetBSD: zmore,v 1.3 2004/03/29 09:59:42 wiz Exp $
-# $OpenBSD: zmore,v 1.4 2003/07/29 07:42:45 otto Exp $
+# $NetBSD: zmore,v 1.5 2013/12/06 13:33:15 pettai Exp $
 #
+# $OpenBSD: zmore,v 1.6 2008/08/20 09:22:02 mpf Exp $
+# $MidnightBSD$
 #-
 # Copyright (c) 2003 Todd C. Miller <Todd.Miller at courtesan.com>
 #
@@ -22,7 +23,7 @@
 # Agency (DARPA) and Air Force Research Laboratory, Air Force
 # Materiel Command, USAF, under agreement number F39502-99-1-0512.
 #
-# $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/gzip/zmore 274262 2014-11-08 00:51:31Z delphij $
 
 # Pull out any command line flags so we can pass them to more/less
 flags=
@@ -42,15 +43,21 @@
 	esac
 done
 
+if [ `basename $0` = "zless" ] ; then
+	pager=${PAGER-less}
+else
+	pager=${PAGER-more}
+fi
+
 # No files means read from stdin
 if [ $# -eq 0 ]; then
-	gzip -cdfq 2>&1 | ${PAGER-more} $flags
+	gzip -cdfq 2>&1 | $pager $flags
 	exit 0
 fi
 
 oterm=`stty -g 2>/dev/null`
 while test $# -ne 0; do
-	gzip -cdfq "$1" 2>&1 | ${PAGER-more} $flags
+	gzip -cdfq "$1" 2>&1 | $pager $flags
 	prev="$1"
 	shift
 	if tty -s && test -n "$oterm" -a $# -gt 0; then


Property changes on: trunk/usr.bin/gzip/zmore
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/gzip/zmore.1
===================================================================
--- trunk/usr.bin/gzip/zmore.1	2018-07-07 19:16:31 UTC (rev 11512)
+++ trunk/usr.bin/gzip/zmore.1	2018-07-07 19:18:55 UTC (rev 11513)
@@ -1,5 +1,6 @@
-.\"	$NetBSD: zmore.1,v 1.3 2003/12/28 12:47:52 wiz Exp $
-.\"	$OpenBSD: zmore.1,v 1.3 2003/06/23 21:00:48 deraadt Exp $
+.\" $MidnightBSD$
+.\"	$NetBSD: zmore.1,v 1.4 2013/11/12 21:58:37 pettai Exp $
+.\"	$OpenBSD: zmore.1,v 1.10 2009/08/16 09:41:08 sobrado Exp $
 .\"
 .\" Copyright (c) 2003 Todd C. Miller <Todd.Miller at courtesan.com>
 .\"
@@ -19,17 +20,21 @@
 .\" Agency (DARPA) and Air Force Research Laboratory, Air Force
 .\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
 .\"
-.\" $MidnightBSD$
-.Dd February 06, 2011
+.\" $FreeBSD: stable/10/usr.bin/gzip/zmore.1 274262 2014-11-08 00:51:31Z delphij $
+.Dd October 22, 2014
 .Dt ZMORE 1
 .Os
 .Sh NAME
-.Nm zmore
+.Nm zmore ,
+.Nm zless
 .Nd view compressed files
 .Sh SYNOPSIS
 .Nm zmore
 .Op Ar flags
-.Op Ar file ...
+.Op Ar
+.Nm zless
+.Op Ar flags
+.Op Ar
 .Sh DESCRIPTION
 .Nm
 is a filter that allows the viewing of files compressed with Lempel-Ziv
@@ -51,6 +56,14 @@
 .Pa /usr/bin/more
 by default).
 .Pp
+.Nm zless
+is equivalent to
+.Nm zmore
+but uses
+.Xr less 1
+as a pager instead of
+.Xr more 1 .
+.Pp
 When multiple files are specified,
 .Nm
 will pause at the end of each file and present the following prompt to the user:
@@ -86,7 +99,11 @@
 Program used to display files.
 If unset,
 .Pa /usr/bin/more
-is used.
+is used
+.Pq Nm zmore
+or
+.Pa /usr/bin/less
+.Pq Nm zless .
 .El
 .Sh SEE ALSO
 .Xr compress 1 ,


Property changes on: trunk/usr.bin/gzip/zmore.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/gzip/znew
===================================================================
--- trunk/usr.bin/gzip/znew	2018-07-07 19:16:31 UTC (rev 11512)
+++ trunk/usr.bin/gzip/znew	2018-07-07 19:18:55 UTC (rev 11513)
@@ -18,6 +18,7 @@
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #
+# $FreeBSD: stable/10/usr.bin/gzip/znew 180136 2008-06-30 23:53:15Z delphij $
 # $MidnightBSD$
 
 # Return 0 if the first arg file size is smaller than the second, 1 otherwise.


Property changes on: trunk/usr.bin/gzip/znew
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/gzip/znew.1
===================================================================
--- trunk/usr.bin/gzip/znew.1	2018-07-07 19:16:31 UTC (rev 11512)
+++ trunk/usr.bin/gzip/znew.1	2018-07-07 19:18:55 UTC (rev 11513)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\"	$NetBSD: znew.1,v 1.2 2003/12/28 12:43:43 wiz Exp $
 .\"	$OpenBSD: znew.1,v 1.1 2003/08/02 20:52:50 otto Exp $
 .\"
@@ -15,7 +16,7 @@
 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.bin/gzip/znew.1 166255 2007-01-26 10:19:08Z delphij $
 .Dd January 26, 2007
 .Dt ZNEW 1
 .Os


Property changes on: trunk/usr.bin/gzip/znew.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/gzip/zuncompress.c
===================================================================
--- trunk/usr.bin/gzip/zuncompress.c	2018-07-07 19:16:31 UTC (rev 11512)
+++ trunk/usr.bin/gzip/zuncompress.c	2018-07-07 19:18:55 UTC (rev 11513)
@@ -1,4 +1,5 @@
-/*	$NetBSD: zuncompress.c,v 1.8 2010/11/06 21:42:32 mrg Exp $ */
+/* $MidnightBSD$ */
+/*	$NetBSD: zuncompress.c,v 1.11 2011/08/16 13:55:02 joerg Exp $ */
 
 /*-
  * Copyright (c) 1985, 1986, 1992, 1993
@@ -33,7 +34,7 @@
  * SUCH DAMAGE.
  *
  * from: NetBSD: zopen.c,v 1.8 2003/08/07 11:13:29 agc Exp
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.bin/gzip/zuncompress.c 327172 2017-12-25 04:34:10Z delphij $
  */
 
 /* This file is #included by gzip.c */
@@ -77,10 +78,9 @@
 static char_type rmask[9] =
 	{0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
 
-/* XXX zuncompress global */
-off_t total_compressed_bytes;
-size_t compressed_prelen;
-char *compressed_pre;
+static off_t total_compressed_bytes;
+static size_t compressed_prelen;
+static char *compressed_pre;
 
 struct s_zstate {
 	FILE *zs_fp;			/* File stream for I/O */
@@ -146,7 +146,7 @@
 	else
 		compressed_pre = NULL;
 
-	while ((bin = fread(buf, 1, sizeof(buf), in)) != 0) {
+	while ((bin = fread(buf, 1, BUFSIZE, in)) != 0) {
 		if (tflag == 0 && (off_t)fwrite(buf, 1, bin, out) != bin) {
 			free(buf);
 			return -1;
@@ -280,7 +280,7 @@
 			if (zs->u.r.zs_code > zs->zs_free_ent ||
 			    zs->u.r.zs_oldcode == -1) {
 				/* Bad stream. */
-				errno = EINVAL;
+				errno = EFTYPE;
 				return (-1);
 			}
 			*zs->u.r.zs_stackp++ = zs->u.r.zs_finchar;



More information about the Midnightbsd-cvs mailing list