CVS commit: src/usr.bin/gzip

2021-06-24 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Thu Jun 24 07:16:49 UTC 2021

Modified Files:
src/usr.bin/gzip: gzip.c

Log Message:
Call check_siginfo() in compression loop to provide SIGINFO compression
progress.
Suggested by mrg@.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/usr.bin/gzip/gzip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.116 src/usr.bin/gzip/gzip.c:1.117
--- src/usr.bin/gzip/gzip.c:1.116	Sat Oct 27 11:39:12 2018
+++ src/usr.bin/gzip/gzip.c	Thu Jun 24 07:16:49 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: gzip.c,v 1.116 2018/10/27 11:39:12 skrll Exp $	*/
+/*	$NetBSD: gzip.c,v 1.117 2021/06/24 07:16:49 simonb Exp $	*/
 
 /*
  * Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008, 2009, 2010, 2011, 2015, 2017
@@ -31,7 +31,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008,\
  2009, 2010, 2011, 2015, 2017 Matthew R. Green.  All rights reserved.");
-__RCSID("$NetBSD: gzip.c,v 1.116 2018/10/27 11:39:12 skrll Exp $");
+__RCSID("$NetBSD: gzip.c,v 1.117 2021/06/24 07:16:49 simonb Exp $");
 #endif /* not lint */
 
 /*
@@ -622,6 +622,7 @@ gz_compress(int in, int out, off_t *gsiz
 
 	crc = crc32(0L, Z_NULL, 0);
 	for (;;) {
+		check_siginfo();
 		if (z.avail_out == 0) {
 			if (write_retry(out, outbufp, BUFLEN) != BUFLEN) {
 maybe_warn("write");



CVS commit: src/usr.bin/gzip

2018-11-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Nov 11 01:42:36 UTC 2018

Modified Files:
src/usr.bin/gzip: unlz.c

Log Message:
use the data size in case stdout was a pipe (M. Levinson)


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/gzip/unlz.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/unlz.c
diff -u src/usr.bin/gzip/unlz.c:1.5 src/usr.bin/gzip/unlz.c:1.6
--- src/usr.bin/gzip/unlz.c:1.5	Sun Oct 28 20:14:37 2018
+++ src/usr.bin/gzip/unlz.c	Sat Nov 10 20:42:36 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: unlz.c,v 1.5 2018/10/29 00:14:37 christos Exp $	*/
+/*	$NetBSD: unlz.c,v 1.6 2018/11/11 01:42:36 christos Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -575,7 +575,12 @@ lz_decode(int fin, int fdout, unsigned d
 	}
 	if (insize)
 		*insize = rv;
+#if 0
+	/* Does not work with pipes */
 	rv = ftello(lz.fout);
+#else
+	rv = data_size;
+#endif
 out:
 	lz_destroy();
 	return rv;



CVS commit: src/usr.bin/gzip

2018-10-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Oct 29 00:14:37 UTC 2018

Modified Files:
src/usr.bin/gzip: unlz.c

Log Message:
fix typo.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/gzip/unlz.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/unlz.c
diff -u src/usr.bin/gzip/unlz.c:1.4 src/usr.bin/gzip/unlz.c:1.5
--- src/usr.bin/gzip/unlz.c:1.4	Sat Oct 27 19:40:04 2018
+++ src/usr.bin/gzip/unlz.c	Sun Oct 28 20:14:37 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: unlz.c,v 1.4 2018/10/27 23:40:04 christos Exp $	*/
+/*	$NetBSD: unlz.c,v 1.5 2018/10/29 00:14:37 christos Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -597,7 +597,7 @@ static unsigned
 lz_get_dict_size(unsigned char c)
 {
 	unsigned dict_size = 1 << (c & 0x1f);
-	dict_size = (dict_size >> 2) * ( (c >> 5) & 0x7);
+	dict_size -= (dict_size >> 2) * ( (c >> 5) & 0x7);
 	if (dict_size < MIN_DICTIONARY_SIZE || dict_size > MAX_DICTIONARY_SIZE)
 		return 0;
 	return dict_size;



CVS commit: src/usr.bin/gzip

2018-10-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Oct 27 23:40:04 UTC 2018

Modified Files:
src/usr.bin/gzip: unlz.c

Log Message:
handle stdin with header partially read.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/gzip/unlz.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/unlz.c
diff -u src/usr.bin/gzip/unlz.c:1.3 src/usr.bin/gzip/unlz.c:1.4
--- src/usr.bin/gzip/unlz.c:1.3	Sat Oct 27 09:20:21 2018
+++ src/usr.bin/gzip/unlz.c	Sat Oct 27 19:40:04 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: unlz.c,v 1.3 2018/10/27 13:20:21 christos Exp $	*/
+/*	$NetBSD: unlz.c,v 1.4 2018/10/27 23:40:04 christos Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -537,7 +537,7 @@ lz_decode_member(struct lz_decoder *lz)
 
 
 static off_t
-lz_decode(int fin, int fdout, unsigned dict_size)
+lz_decode(int fin, int fdout, unsigned dict_size, off_t *insize)
 {
 	struct lz_decoder lz;
 	off_t rv = -1;
@@ -568,15 +568,14 @@ lz_decode(int fin, int fdout, unsigned d
 	if (crc != lz_get_crc() || data_size != lz_get_data_position())
 		goto out;
 
-#if 0
 	rv = 0;
 	for (int i = 19; i >= 12; --i) {
 		rv <<= 8;
 		rv += trailer[i];
 	}
-#else
+	if (insize)
+		*insize = rv;
 	rv = ftello(lz.fout);
-#endif
 out:
 	lz_destroy();
 	return rv;
@@ -612,13 +611,21 @@ unlz(int fin, int fout, char *pre, size_
 
 	char header[HDR_SIZE];
 
-	switch (read(fin, header, sizeof(header))) {
+	if (prelen > sizeof(header))
+		return -1;
+	if (pre && prelen)
+		memcpy(header, pre, prelen);
+	
+	ssize_t nr = read(fin, header + prelen, sizeof(header) - prelen);
+	switch (nr) {
+	case -1:
+		return -1;
 	case 0:
-		return 0;
-	case sizeof(header):
-		break;
+		return prelen ? -1 : 0;
 	default:
-		return -1;
+		if ((size_t)nr != sizeof(header) - prelen)
+			return -1;
+		break;
 	}
 
 	if (memcmp(header, hdrmagic, sizeof(hdrmagic)) != 0)
@@ -628,5 +635,5 @@ unlz(int fin, int fout, char *pre, size_
 	if (dict_size == 0)
 		return -1;
 
-	return lz_decode(fin, fout, dict_size);
+	return lz_decode(fin, fout, dict_size, bytes_in);
 }



CVS commit: src/usr.bin/gzip

2018-10-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Oct 27 13:20:21 UTC 2018

Modified Files:
src/usr.bin/gzip: unlz.c

Log Message:
remove debugging.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/gzip/unlz.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/unlz.c
diff -u src/usr.bin/gzip/unlz.c:1.2 src/usr.bin/gzip/unlz.c:1.3
--- src/usr.bin/gzip/unlz.c:1.2	Sat Oct 27 07:52:26 2018
+++ src/usr.bin/gzip/unlz.c	Sat Oct 27 09:20:21 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: unlz.c,v 1.2 2018/10/27 11:52:26 kre Exp $	*/
+/*	$NetBSD: unlz.c,v 1.3 2018/10/27 13:20:21 christos Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -577,7 +577,6 @@ lz_decode(int fin, int fdout, unsigned d
 #else
 	rv = ftello(lz.fout);
 #endif
-	fprintf(stderr, "%jd\n", (intmax_t)rv);
 out:
 	lz_destroy();
 	return rv;



CVS commit: src/usr.bin/gzip

2018-10-27 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Oct 27 11:39:12 UTC 2018

Modified Files:
src/usr.bin/gzip: gzip.c

Log Message:
Fix previous


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/usr.bin/gzip/gzip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.115 src/usr.bin/gzip/gzip.c:1.116
--- src/usr.bin/gzip/gzip.c:1.115	Fri Oct 26 22:10:15 2018
+++ src/usr.bin/gzip/gzip.c	Sat Oct 27 11:39:12 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: gzip.c,v 1.115 2018/10/26 22:10:15 christos Exp $	*/
+/*	$NetBSD: gzip.c,v 1.116 2018/10/27 11:39:12 skrll Exp $	*/
 
 /*
  * Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008, 2009, 2010, 2011, 2015, 2017
@@ -31,7 +31,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008,\
  2009, 2010, 2011, 2015, 2017 Matthew R. Green.  All rights reserved.");
-__RCSID("$NetBSD: gzip.c,v 1.115 2018/10/26 22:10:15 christos Exp $");
+__RCSID("$NetBSD: gzip.c,v 1.116 2018/10/27 11:39:12 skrll Exp $");
 #endif /* not lint */
 
 /*
@@ -1156,8 +1156,8 @@ file_gettype(u_char *buf)
 #ifndef NO_LZ_SUPPORT
 	if (memcmp(buf, LZ_MAGIC, 4) == 0)
 		return FT_LZ;
-#endif
 	else
+#endif
 		return FT_UNKNOWN;
 }
 



CVS commit: src/usr.bin/gzip

2018-10-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Oct 26 22:10:15 UTC 2018

Modified Files:
src/usr.bin/gzip: gzip.1 gzip.c
Added Files:
src/usr.bin/gzip: unlz.c

Log Message:
Add lzip support to gzip based on the example lzip decoder.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/gzip/gzip.1
cvs rdiff -u -r1.114 -r1.115 src/usr.bin/gzip/gzip.c
cvs rdiff -u -r0 -r1.1 src/usr.bin/gzip/unlz.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.1
diff -u src/usr.bin/gzip/gzip.1:1.30 src/usr.bin/gzip/gzip.1:1.31
--- src/usr.bin/gzip/gzip.1:1.30	Sun Oct 22 13:36:49 2017
+++ src/usr.bin/gzip/gzip.1	Fri Oct 26 18:10:15 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: gzip.1,v 1.30 2017/10/22 17:36:49 abhinav Exp $
+.\"	$NetBSD: gzip.1,v 1.31 2018/10/26 22:10:15 christos Exp $
 .\"
 .\" Copyright (c) 1997, 2003, 2004, 2008, 2009, 2015, 2017 Matthew R. Green
 .\" All rights reserved.
@@ -96,6 +96,7 @@ This version of
 is also capable of decompressing files compressed using
 .Xr compress 1 ,
 .Xr bzip2 1 ,
+.Ar lzip ,
 or
 .Xr xz 1 .
 .Sh OPTIONS

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.114 src/usr.bin/gzip/gzip.c:1.115
--- src/usr.bin/gzip/gzip.c:1.114	Sat Oct  6 12:36:45 2018
+++ src/usr.bin/gzip/gzip.c	Fri Oct 26 18:10:15 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: gzip.c,v 1.114 2018/10/06 16:36:45 martin Exp $	*/
+/*	$NetBSD: gzip.c,v 1.115 2018/10/26 22:10:15 christos Exp $	*/
 
 /*
  * Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008, 2009, 2010, 2011, 2015, 2017
@@ -31,7 +31,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008,\
  2009, 2010, 2011, 2015, 2017 Matthew R. Green.  All rights reserved.");
-__RCSID("$NetBSD: gzip.c,v 1.114 2018/10/06 16:36:45 martin Exp $");
+__RCSID("$NetBSD: gzip.c,v 1.115 2018/10/26 22:10:15 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -85,6 +85,9 @@ enum filetype {
 #ifndef NO_XZ_SUPPORT
 	FT_XZ,
 #endif
+#ifndef NO_LZ_SUPPORT
+	FT_LZ,
+#endif
 	FT_LAST,
 	FT_UNKNOWN
 };
@@ -111,6 +114,11 @@ enum filetype {
 #define XZ_MAGIC	"\3757zXZ"
 #endif
 
+#ifndef NO_LZ_SUPPORT
+#define LZ_SUFFIX	".lz"
+#define LZ_MAGIC	"LZIP"
+#endif
+
 #define GZ_SUFFIX	".gz"
 
 #define BUFLEN		(64 * 1024)
@@ -154,6 +162,9 @@ static suffixes_t suffixes[] = {
 #ifndef NO_XZ_SUPPORT
 	SUFFIX(XZ_SUFFIX,	""),
 #endif
+#ifndef NO_LZ_SUPPORT
+	SUFFIX(LZ_SUFFIX,	""),
+#endif
 	SUFFIX(GZ_SUFFIX,	""),	/* Overwritten by -S "" */
 #endif /* SMALL */
 #undef SUFFIX
@@ -260,6 +271,10 @@ static	off_t	unxz(int, int, char *, size
 static	off_t	unxz_len(int);
 #endif
 
+#ifndef NO_LZ_SUPPORT
+static	off_t	unlz(int, int, char *, size_t, off_t *);
+#endif
+
 #ifdef SMALL
 #define getopt_long(a,b,c,d,e) getopt(a,b,c)
 #else
@@ -1138,6 +1153,11 @@ file_gettype(u_char *buf)
 		return FT_XZ;
 	else
 #endif
+#ifndef NO_LZ_SUPPORT
+	if (memcmp(buf, LZ_MAGIC, 4) == 0)
+		return FT_LZ;
+#endif
+	else
 		return FT_UNKNOWN;
 }
 
@@ -1589,6 +1609,15 @@ file_uncompress(char *file, char *outfil
 		break;
 #endif
 
+#ifndef NO_LZ_SUPPORT
+	case FT_LZ:
+		if (lflag) {
+			maybe_warnx("no -l with lzip files");
+			goto lose;
+		}
+		size = unlz(fd, zfd, NULL, 0, NULL);
+		break;
+#endif
 #ifndef SMALL
 	case FT_UNKNOWN:
 		if (lflag) {
@@ -1821,6 +1850,12 @@ handle_stdin(void)
 			 (char *)header1, sizeof header1, );
 		break;
 #endif
+#ifndef NO_LZ_SUPPORT
+	case FT_LZ:
+		usize = unlz(STDIN_FILENO, STDOUT_FILENO,
+			 (char *)header1, sizeof header1, );
+		break;
+#endif
 	}
 
 #ifndef SMALL
@@ -2217,6 +2252,9 @@ display_version(void)
 #ifndef NO_XZ_SUPPORT
 #include "unxz.c"
 #endif
+#ifndef NO_LZ_SUPPORT
+#include "unlz.c"
+#endif
 
 static ssize_t
 read_retry(int fd, void *buf, size_t sz)

Added files:

Index: src/usr.bin/gzip/unlz.c
diff -u /dev/null src/usr.bin/gzip/unlz.c:1.1
--- /dev/null	Fri Oct 26 18:10:16 2018
+++ src/usr.bin/gzip/unlz.c	Fri Oct 26 18:10:15 2018
@@ -0,0 +1,633 @@
+/*	$NetBSD: unlz.c,v 1.1 2018/10/26 22:10:15 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2018 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 

CVS commit: src/usr.bin/gzip

2018-10-06 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Oct  6 16:36:45 UTC 2018

Modified Files:
src/usr.bin/gzip: gzip.c unxz.c

Log Message:
Add -l support for xz files


To generate a diff of this commit:
cvs rdiff -u -r1.113 -r1.114 src/usr.bin/gzip/gzip.c
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/gzip/unxz.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.113 src/usr.bin/gzip/gzip.c:1.114
--- src/usr.bin/gzip/gzip.c:1.113	Tue Jun 12 00:42:17 2018
+++ src/usr.bin/gzip/gzip.c	Sat Oct  6 16:36:45 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: gzip.c,v 1.113 2018/06/12 00:42:17 kamil Exp $	*/
+/*	$NetBSD: gzip.c,v 1.114 2018/10/06 16:36:45 martin Exp $	*/
 
 /*
  * Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008, 2009, 2010, 2011, 2015, 2017
@@ -31,7 +31,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008,\
  2009, 2010, 2011, 2015, 2017 Matthew R. Green.  All rights reserved.");
-__RCSID("$NetBSD: gzip.c,v 1.113 2018/06/12 00:42:17 kamil Exp $");
+__RCSID("$NetBSD: gzip.c,v 1.114 2018/10/06 16:36:45 martin Exp $");
 #endif /* not lint */
 
 /*
@@ -213,6 +213,7 @@ __dead static	void	display_version(void)
 static	const suffixes_t *check_suffix(char *, int);
 static	ssize_t	read_retry(int, void *, size_t);
 static	ssize_t	write_retry(int, const void *, size_t);
+static void	print_list_out(off_t, off_t, const char*);
 
 #ifdef SMALL
 #define infile_set(f,t) infile_set(f)
@@ -256,6 +257,7 @@ static	off_t	unpack(int, int, char *, si
 
 #ifndef NO_XZ_SUPPORT
 static	off_t	unxz(int, int, char *, size_t, off_t *);
+static	off_t	unxz_len(int);
 #endif
 
 #ifdef SMALL
@@ -1579,10 +1581,10 @@ file_uncompress(char *file, char *outfil
 #ifndef NO_XZ_SUPPORT
 	case FT_XZ:
 		if (lflag) {
-			maybe_warnx("no -l with xz files");
-			goto lose;
+			size = unxz_len(fd);
+			print_list_out(in_size, size, file);
+			return -1;
 		}
-
 		size = unxz(fd, zfd, NULL, 0, NULL);
 		break;
 #endif
@@ -2147,6 +2149,12 @@ print_list(int fd, off_t out, const char
 	in_tot += in;
 	out_tot += out;
 #endif
+	print_list_out(out, in, outfile);
+}
+
+static void
+print_list_out(off_t out, off_t in, const char *outfile)
+{
 	printf("%12llu %12llu ", (unsigned long long)out, (unsigned long long)in);
 	print_ratio(in, out, stdout);
 	printf(" %s\n", outfile);

Index: src/usr.bin/gzip/unxz.c
diff -u src/usr.bin/gzip/unxz.c:1.7 src/usr.bin/gzip/unxz.c:1.8
--- src/usr.bin/gzip/unxz.c:1.7	Fri Aug  4 07:27:08 2017
+++ src/usr.bin/gzip/unxz.c	Sat Oct  6 16:36:45 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: unxz.c,v 1.7 2017/08/04 07:27:08 mrg Exp $	*/
+/*	$NetBSD: unxz.c,v 1.8 2018/10/06 16:36:45 martin Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: unxz.c,v 1.7 2017/08/04 07:27:08 mrg Exp $");
+__RCSID("$NetBSD: unxz.c,v 1.8 2018/10/06 16:36:45 martin Exp $");
 
 #include 
 #include 
@@ -154,3 +154,322 @@ unxz(int i, int o, char *pre, size_t pre
 		}
 	}
 }
+
+#include 
+
+/*
+ * Copied various bits and pieces from xz support code or brute force
+ * replacements.
+ */
+
+#define	my_min(A,B)	((A)<(B)?(A):(B))
+
+// Some systems have suboptimal BUFSIZ. Use a bit bigger value on them.
+// We also need that IO_BUFFER_SIZE is a multiple of 8 (sizeof(uint64_t))
+#if BUFSIZ <= 1024
+#   define IO_BUFFER_SIZE 8192
+#else
+#   define IO_BUFFER_SIZE (BUFSIZ & ~7U)
+#endif
+
+/// is_sparse() accesses the buffer as uint64_t for maximum speed.
+/// Use an union to make sure that the buffer is properly aligned.
+typedef union {
+uint8_t u8[IO_BUFFER_SIZE];
+uint32_t u32[IO_BUFFER_SIZE / sizeof(uint32_t)];
+uint64_t u64[IO_BUFFER_SIZE / sizeof(uint64_t)];
+} io_buf;
+
+
+static bool
+io_pread(int fd, io_buf *buf, size_t size, off_t pos)
+{
+	// Using lseek() and read() is more portable than pread() and
+	// for us it is as good as real pread().
+	if (lseek(fd, pos, SEEK_SET) != pos) {
+		return true;
+	}
+
+	const size_t amount = read(fd, buf, size);
+	if (amount == SIZE_MAX)
+		return true;
+
+	if (amount != size) {
+		return true;
+	}
+
+	return false;
+}
+
+/*
+ * Most of the following is copied (mostly verbatim) from the xz
+ * distribution, from file src/xz/list.c
+ */
+
+///
+//
+/// \file   list.c
+/// \brief  Listing information about .xz files
+//
+//  Author: Lasse Collin
+//
+//  This file has been put into the public domain.
+//  You can do whatever you want with this file.
+//
+///
+
+
+/// Information about a .xz file
+typedef struct {
+	/// Combined Index of all Streams in the file
+	lzma_index *idx;
+
+	/// Total amount of Stream Padding
+	uint64_t stream_padding;
+
+	/// Highest 

CVS commit: src/usr.bin/gzip

2018-06-11 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Jun 12 00:42:17 UTC 2018

Modified Files:
src/usr.bin/gzip: gzip.c

Log Message:
Correct Undefined Behavior in gzip(1)

Unportable left shift reported with MKSANITIZER=yes USE_SANITIZER=undefined:

# progress -zf ./games.tgz  tar -xp -C "./" -f -
/public/src.git/usr.bin/gzip/gzip.c:2126:33: runtime error: left shift of 251 
by 24 places cannot be represented in type 'int'
100% 
||
 44500 KiB  119.69 MiB/s00:00 ETA

Refactor the following code into something that is more clear
and fix signed integer shift, by casting all buf[] elements to
(unsigned int):

unsigned char buf[8];
uint32_t usize;
[...]
else {
usize = buf[4] | buf[5] << 8 |
buf[6] << 16 | buf[7] << 24;
[...]

New version:

usize = buf[4];
usize |= (unsigned int)buf[5] << 8;
usize |= (unsigned int)buf[6] << 16;
usize |= (unsigned int)buf[7] << 24;

Only the "<< 24" part needs explicit cast, but for consistency make the
integer promotion explicit and clear to a code reader.

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 src/usr.bin/gzip/gzip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.112 src/usr.bin/gzip/gzip.c:1.113
--- src/usr.bin/gzip/gzip.c:1.112	Wed Aug 23 13:04:17 2017
+++ src/usr.bin/gzip/gzip.c	Tue Jun 12 00:42:17 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: gzip.c,v 1.112 2017/08/23 13:04:17 christos Exp $	*/
+/*	$NetBSD: gzip.c,v 1.113 2018/06/12 00:42:17 kamil Exp $	*/
 
 /*
  * Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008, 2009, 2010, 2011, 2015, 2017
@@ -31,7 +31,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008,\
  2009, 2010, 2011, 2015, 2017 Matthew R. Green.  All rights reserved.");
-__RCSID("$NetBSD: gzip.c,v 1.112 2017/08/23 13:04:17 christos Exp $");
+__RCSID("$NetBSD: gzip.c,v 1.113 2018/06/12 00:42:17 kamil Exp $");
 #endif /* not lint */
 
 /*
@@ -2118,12 +2118,16 @@ print_list(int fd, off_t out, const char
 maybe_warnx("read of uncompressed size");
 
 			else {
-usize = buf[4] | buf[5] << 8 |
-	buf[6] << 16 | buf[7] << 24;
+usize = buf[4];
+usize |= (unsigned int)buf[5] << 8;
+usize |= (unsigned int)buf[6] << 16;
+usize |= (unsigned int)buf[7] << 24;
 in = (off_t)usize;
 #ifndef SMALL
-crc = buf[0] | buf[1] << 8 |
-  buf[2] << 16 | buf[3] << 24;
+crc = buf[0];
+crc |= (unsigned int)buf[1] << 8;
+crc |= (unsigned int)buf[2] << 16;
+crc |= (unsigned int)buf[3] << 24;
 #endif
 			}
 		}



CVS commit: src/usr.bin/gzip

2017-10-22 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Sun Oct 22 17:36:49 UTC 2017

Modified Files:
src/usr.bin/gzip: gzip.1

Log Message:
Add gunzip and zcat to the NAME section as well


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/gzip/gzip.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.1
diff -u src/usr.bin/gzip/gzip.1:1.29 src/usr.bin/gzip/gzip.1:1.30
--- src/usr.bin/gzip/gzip.1:1.29	Fri Aug  4 07:27:08 2017
+++ src/usr.bin/gzip/gzip.1	Sun Oct 22 17:36:49 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: gzip.1,v 1.29 2017/08/04 07:27:08 mrg Exp $
+.\"	$NetBSD: gzip.1,v 1.30 2017/10/22 17:36:49 abhinav Exp $
 .\"
 .\" Copyright (c) 1997, 2003, 2004, 2008, 2009, 2015, 2017 Matthew R. Green
 .\" All rights reserved.
@@ -28,7 +28,9 @@
 .Dt GZIP 1
 .Os
 .Sh NAME
-.Nm gzip
+.Nm gzip ,
+.Nm gunzip ,
+.Nm zcat
 .Nd compression/decompression tool using Lempel-Ziv coding (LZ77)
 .Sh SYNOPSIS
 .Nm



CVS commit: src/usr.bin/gzip

2017-08-23 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Aug 23 13:04:17 UTC 2017

Modified Files:
src/usr.bin/gzip: gzip.c

Log Message:
now that we are processing SIGINFO write can be interrupted and return
partial results (well, it could before too but it was harder to trigger);
provide write_fully like we have read_fully already.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/usr.bin/gzip/gzip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.111 src/usr.bin/gzip/gzip.c:1.112
--- src/usr.bin/gzip/gzip.c:1.111	Fri Aug  4 03:27:08 2017
+++ src/usr.bin/gzip/gzip.c	Wed Aug 23 09:04:17 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: gzip.c,v 1.111 2017/08/04 07:27:08 mrg Exp $	*/
+/*	$NetBSD: gzip.c,v 1.112 2017/08/23 13:04:17 christos Exp $	*/
 
 /*
  * Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008, 2009, 2010, 2011, 2015, 2017
@@ -31,7 +31,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008,\
  2009, 2010, 2011, 2015, 2017 Matthew R. Green.  All rights reserved.");
-__RCSID("$NetBSD: gzip.c,v 1.111 2017/08/04 07:27:08 mrg Exp $");
+__RCSID("$NetBSD: gzip.c,v 1.112 2017/08/23 13:04:17 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -212,6 +212,7 @@ __dead static	void	usage(void);
 __dead static	void	display_version(void);
 static	const suffixes_t *check_suffix(char *, int);
 static	ssize_t	read_retry(int, void *, size_t);
+static	ssize_t	write_retry(int, const void *, size_t);
 
 #ifdef SMALL
 #define infile_set(f,t) infile_set(f)
@@ -605,7 +606,7 @@ gz_compress(int in, int out, off_t *gsiz
 	crc = crc32(0L, Z_NULL, 0);
 	for (;;) {
 		if (z.avail_out == 0) {
-			if (write(out, outbufp, BUFLEN) != BUFLEN) {
+			if (write_retry(out, outbufp, BUFLEN) != BUFLEN) {
 maybe_warn("write");
 out_tot = -1;
 goto out;
@@ -655,7 +656,7 @@ gz_compress(int in, int out, off_t *gsiz
 
 		len = (char *)z.next_out - outbufp;
 
-		w = write(out, outbufp, len);
+		w = write_retry(out, outbufp, len);
 		if (w == -1 || (size_t)w != len) {
 			maybe_warn("write");
 			out_tot = -1;
@@ -690,7 +691,7 @@ gz_compress(int in, int out, off_t *gsiz
 	if (in_tot > 0x)
 		maybe_warn("input file size >= 4GB cannot be saved");
 #endif
-	if (write(out, outbufp, i) != i) {
+	if (write_retry(out, outbufp, i) != i) {
 		maybe_warn("write");
 		in_tot = -1;
 	} else
@@ -957,7 +958,7 @@ gz_uncompress(int in, int out, char *pre
 /* don't write anything with -t */
 tflag == 0 &&
 #endif
-write(out, outbufp, wr) != wr) {
+write_retry(out, outbufp, wr) != wr) {
 	maybe_warn("error writing to output");
 	goto stop_and_fail;
 }
@@ -1699,7 +1700,7 @@ cat_fd(unsigned char * prepend, size_t c
 	ssize_t w;
 
 	in_tot = count;
-	w = write(STDOUT_FILENO, prepend, count);
+	w = write_retry(STDOUT_FILENO, prepend, count);
 	if (w == -1 || (size_t)w != count) {
 		maybe_warn("write to stdout");
 		return -1;
@@ -1716,7 +1717,7 @@ cat_fd(unsigned char * prepend, size_t c
 		}
 		infile_newdata(rv);
 
-		if (write(STDOUT_FILENO, buf, rv) != rv) {
+		if (write_retry(STDOUT_FILENO, buf, rv) != rv) {
 			maybe_warn("write to stdout");
 			break;
 		}
@@ -2226,3 +2227,25 @@ read_retry(int fd, void *buf, size_t sz)
 
 	return sz - left;
 }
+
+static ssize_t
+write_retry(int fd, const void *buf, size_t sz)
+{
+	const char *cp = buf;
+	size_t left = MIN(sz, (size_t) SSIZE_MAX);
+
+	while (left > 0) {
+		ssize_t ret;
+
+		ret = write(fd, cp, left);
+		if (ret == -1) {
+			return ret;
+		} else if (ret == 0) {
+			abort();	/* Can't happen */
+		}
+		cp += ret;
+		left -= ret;
+	}
+
+	return sz - left;
+}



CVS commit: src/usr.bin/gzip

2017-08-04 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Fri Aug  4 07:27:08 UTC 2017

Modified Files:
src/usr.bin/gzip: gzip.1 gzip.c unbzip2.c unpack.c unxz.c

Log Message:
add SIGINFO support.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/gzip/gzip.1
cvs rdiff -u -r1.110 -r1.111 src/usr.bin/gzip/gzip.c
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/gzip/unbzip2.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/gzip/unpack.c
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/gzip/unxz.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.1
diff -u src/usr.bin/gzip/gzip.1:1.28 src/usr.bin/gzip/gzip.1:1.29
--- src/usr.bin/gzip/gzip.1:1.28	Sat Jun  3 21:28:48 2017
+++ src/usr.bin/gzip/gzip.1	Fri Aug  4 07:27:08 2017
@@ -1,6 +1,6 @@
-.\"	$NetBSD: gzip.1,v 1.28 2017/06/03 21:28:48 mrg Exp $
+.\"	$NetBSD: gzip.1,v 1.29 2017/08/04 07:27:08 mrg Exp $
 .\"
-.\" Copyright (c) 1997, 2003, 2004, 2008, 2009, 2015 Matthew R. Green
+.\" Copyright (c) 1997, 2003, 2004, 2008, 2009, 2015, 2017 Matthew R. Green
 .\" All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -179,6 +179,13 @@ The
 utility exits 0 on success,
 1 on errors,
 and 2 if a warning occurs.
+.Sh SIGNALS
+.Nm
+responds to the following signals:
+.Bl -tag -width indent
+.It Dv SIGINFO
+Report progress to standard error.
+.El
 .Sh SEE ALSO
 .Xr bzip2 1 ,
 .Xr compress 1 ,
@@ -202,7 +209,7 @@ program for
 This manual documents
 .Nx
 .Nm
-version 20150113.
+version 20170803.
 .Sh AUTHORS
 This implementation of
 .Nm

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.110 src/usr.bin/gzip/gzip.c:1.111
--- src/usr.bin/gzip/gzip.c:1.110	Sat Jun  3 21:28:48 2017
+++ src/usr.bin/gzip/gzip.c	Fri Aug  4 07:27:08 2017
@@ -1,7 +1,7 @@
-/*	$NetBSD: gzip.c,v 1.110 2017/06/03 21:28:48 mrg Exp $	*/
+/*	$NetBSD: gzip.c,v 1.111 2017/08/04 07:27:08 mrg Exp $	*/
 
 /*
- * Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008, 2009, 2010, 2011, 2015
+ * Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008, 2009, 2010, 2011, 2015, 2017
  *Matthew R. Green
  * All rights reserved.
  *
@@ -30,8 +30,8 @@
 #include 
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008,\
- 2009, 2010, 2011, 2015 Matthew R. Green.  All rights reserved.");
-__RCSID("$NetBSD: gzip.c,v 1.110 2017/06/03 21:28:48 mrg Exp $");
+ 2009, 2010, 2011, 2015, 2017 Matthew R. Green.  All rights reserved.");
+__RCSID("$NetBSD: gzip.c,v 1.111 2017/08/04 07:27:08 mrg Exp $");
 #endif /* not lint */
 
 /*
@@ -161,7 +161,7 @@ static suffixes_t suffixes[] = {
 #define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0])
 #define SUFFIX_MAXLEN	30
 
-static	const char	gzip_version[] = "NetBSD gzip 20150113";
+static	const char	gzip_version[] = "NetBSD gzip 20170803";
 
 static	int	cflag;			/* stdout mode */
 static	int	dflag;			/* decompress mode */
@@ -177,6 +177,7 @@ static	int	qflag;			/* quiet mode */
 static	int	rflag;			/* recursive mode */
 static	int	tflag;			/* test */
 static	int	vflag;			/* verbose mode */
+static	sig_atomic_t print_info = 0;
 #else
 #define		qflag	0
 #define		tflag	0
@@ -184,7 +185,7 @@ static	int	vflag;			/* verbose mode */
 
 static	int	exit_value = 0;		/* exit value */
 
-static	char	*infile;		/* name of file coming in */
+static	const char *infile;		/* name of file coming in */
 
 static	void	maybe_err(const char *fmt, ...) __printflike(1, 2) __dead;
 #if !defined(NO_BZIP2_SUPPORT) || !defined(NO_PACK_SUPPORT) ||	\
@@ -213,8 +214,20 @@ static	const suffixes_t *check_suffix(ch
 static	ssize_t	read_retry(int, void *, size_t);
 
 #ifdef SMALL
+#define infile_set(f,t) infile_set(f)
+#endif
+static	void	infile_set(const char *newinfile, off_t total);
+
+#ifdef SMALL
 #define unlink_input(f, sb) unlink(f)
+#define check_siginfo() /* nothing */
+#define setup_signals() /* nothing */
+#define infile_newdata(t) /* nothing */
 #else
+static	off_t	infile_total;		/* total expected to read/write */
+static	off_t	infile_current;		/* current read/write */
+
+static	void	check_siginfo(void);
 static	off_t	cat_fd(unsigned char *, size_t, off_t *, int fd);
 static	void	prepend_gzip(char *, int *, char ***);
 static	void	handle_dir(char *);
@@ -222,6 +235,9 @@ static	void	print_verbage(const char *, 
 static	void	print_test(const char *, int);
 static	void	copymodes(int fd, const struct stat *, const char *file);
 static	int	check_outfile(const char *outfile);
+static	void	setup_signals(void);
+static	void	infile_newdata(size_t newdata);
+static	void	infile_clear(void);
 #endif
 
 #ifndef NO_BZIP2_SUPPORT
@@ -285,7 +301,7 @@ main(int argc, char **argv)
 #endif
 	int ch;
 
-	/* XXX set up signals */
+	setup_signals();
 
 #ifndef SMALL
 	if ((gzip = getenv("GZIP")) != NULL)
@@ -559,7 +575,7 @@ gz_compress(int in, int out, off_t *gsiz
 		origname = "";
 	}
 
-	i = snprintf(outbufp, BUFLEN, "%c%c%c%c%c%c%c%c%c%c%s", 
+	

CVS commit: src/usr.bin/gzip

2017-06-03 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Jun  3 21:28:48 UTC 2017

Modified Files:
src/usr.bin/gzip: gzip.1 gzip.c

Log Message:
update copyright strings.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/usr.bin/gzip/gzip.1
cvs rdiff -u -r1.109 -r1.110 src/usr.bin/gzip/gzip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.1
diff -u src/usr.bin/gzip/gzip.1:1.27 src/usr.bin/gzip/gzip.1:1.28
--- src/usr.bin/gzip/gzip.1:1.27	Sun Jan  8 14:18:31 2017
+++ src/usr.bin/gzip/gzip.1	Sat Jun  3 21:28:48 2017
@@ -1,6 +1,6 @@
-.\"	$NetBSD: gzip.1,v 1.27 2017/01/08 14:18:31 wiz Exp $
+.\"	$NetBSD: gzip.1,v 1.28 2017/06/03 21:28:48 mrg Exp $
 .\"
-.\" Copyright (c) 1997, 2003, 2004 Matthew R. Green
+.\" Copyright (c) 1997, 2003, 2004, 2008, 2009, 2015 Matthew R. Green
 .\" All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.109 src/usr.bin/gzip/gzip.c:1.110
--- src/usr.bin/gzip/gzip.c:1.109	Tue Oct 27 07:36:18 2015
+++ src/usr.bin/gzip/gzip.c	Sat Jun  3 21:28:48 2017
@@ -1,7 +1,8 @@
-/*	$NetBSD: gzip.c,v 1.109 2015/10/27 07:36:18 mrg Exp $	*/
+/*	$NetBSD: gzip.c,v 1.110 2017/06/03 21:28:48 mrg Exp $	*/
 
 /*
- * Copyright (c) 1997, 1998, 2003, 2004, 2006 Matthew R. Green
+ * Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008, 2009, 2010, 2011, 2015
+ *Matthew R. Green
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -28,9 +29,9 @@
 
 #include 
 #ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006\
- Matthew R. Green.  All rights reserved.");
-__RCSID("$NetBSD: gzip.c,v 1.109 2015/10/27 07:36:18 mrg Exp $");
+__COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008,\
+ 2009, 2010, 2011, 2015 Matthew R. Green.  All rights reserved.");
+__RCSID("$NetBSD: gzip.c,v 1.110 2017/06/03 21:28:48 mrg Exp $");
 #endif /* not lint */
 
 /*



CVS commit: src/usr.bin/gzip

2017-01-08 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Jan  8 14:18:31 UTC 2017

Modified Files:
src/usr.bin/gzip: gzip.1

Log Message:
Document --keep. From Timo Buhrmester  on netbsd-docs.

Use more macros while here.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/gzip/gzip.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.1
diff -u src/usr.bin/gzip/gzip.1:1.26 src/usr.bin/gzip/gzip.1:1.27
--- src/usr.bin/gzip/gzip.1:1.26	Tue Oct 27 07:36:18 2015
+++ src/usr.bin/gzip/gzip.1	Sun Jan  8 14:18:31 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: gzip.1,v 1.26 2015/10/27 07:36:18 mrg Exp $
+.\"	$NetBSD: gzip.1,v 1.27 2017/01/08 14:18:31 wiz Exp $
 .\"
 .\" Copyright (c) 1997, 2003, 2004 Matthew R. Green
 .\" All rights reserved.
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd October 26, 2015
+.Dd January 8, 2017
 .Dt GZIP 1
 .Os
 .Sh NAME
@@ -99,7 +99,7 @@ or
 .Sh OPTIONS
 The following options are available:
 .Bl -tag -width XXrXXXrecursiveX
-.It Fl 1 , -fast
+.It Fl 1 , Fl Fl fast
 .It Fl 2
 .It Fl 3
 .It Fl 4
@@ -107,58 +107,62 @@ The following options are available:
 .It Fl 6
 .It Fl 7
 .It Fl 8
-.It Fl 9 , -best
+.It Fl 9 , Fl Fl best
 These options change the compression level used, with the
 .Fl 1
 option being the fastest, with less compression, and the
 .Fl 9
 option being the slowest, with optimal compression.
 The default compression level is 6.
-.It Fl c , -stdout , -to-stdout
+.It Fl c , Fl Fl stdout , Fl Fl to-stdout
 This option specifies that output will go to the standard output
 stream, leaving files intact.
-.It Fl d , -decompress , -uncompress
+.It Fl d , Fl Fl decompress , Fl Fl uncompress
 This option selects decompression rather than compression.
-.It Fl f , -force
+.It Fl f , Fl Fl force
 This option turns on force mode.
 This allows files with multiple links, overwriting of pre-existing
 files, reading from or writing to a terminal, and when combined
 with the
 .Fl c
 option, allowing non-compressed data to pass through unchanged.
-.It Fl h , -help
+.It Fl h , Fl Fl help
 This option prints a usage summary and exits.
-.It Fl l , -list
+.It Fl k , Fl Fl keep
+This option prevents
+.Nm
+from deleting input files after (de)compression.
+.It Fl l , Fl Fl list
 This option displays information about the file's compressed and
 uncompressed size, ratio, uncompressed name.
 With the
 .Fl v
 option, it also displays the compression method, CRC, date and time
 embedded in the file.
-.It Fl N , -name
+.It Fl N , Fl Fl name
 This option causes the stored filename in the input file to be used
 as the output file.
-.It Fl n , -no-name
+.It Fl n , Fl Fl no-name
 This option stops the filename and timestamp from being stored in
 the output file.
-.It Fl q , -quiet
+.It Fl q , Fl Fl quiet
 With this option, no warnings or errors are printed.
-.It Fl r , -recursive
+.It Fl r , Fl Fl recursive
 This option is used to
 .Nm
 the files in a directory tree individually, using the
 .Xr fts 3
 library.
-.It Fl S Ar suffix , Fl -suffix Ar suffix
+.It Fl S Ar suffix , Fl Fl suffix Ar suffix
 This option changes the default suffix from .gz to
 .Ar suffix .
-.It Fl t , -test
+.It Fl t , Fl Fl test
 This option will test compressed files for integrity.
-.It Fl V , -version
+.It Fl V , Fl Fl version
 This option prints the version of the
 .Nm
 program.
-.It Fl v , -verbose
+.It Fl v , Fl Fl verbose
 This option turns on verbose mode, which prints the compression
 ratio for each file compressed.
 .El



CVS commit: src/usr.bin/gzip

2016-01-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 29 15:19:01 UTC 2016

Modified Files:
src/usr.bin/gzip: unxz.c

Log Message:
remove clauses 3, 4


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/gzip/unxz.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/unxz.c
diff -u src/usr.bin/gzip/unxz.c:1.5 src/usr.bin/gzip/unxz.c:1.6
--- src/usr.bin/gzip/unxz.c:1.5	Thu Sep 29 21:32:21 2011
+++ src/usr.bin/gzip/unxz.c	Fri Jan 29 10:19:01 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: unxz.c,v 1.5 2011/09/30 01:32:21 christos Exp $	*/
+/*	$NetBSD: unxz.c,v 1.6 2016/01/29 15:19:01 christos Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -15,13 +15,6 @@
  * 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.
- * 3. All advertising materials mentioning features or use of this software
- *must display the following acknowledgement:
- *This product includes software developed by the NetBSD
- *Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *contributors may be used to endorse or promote products derived
- *from this software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -36,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: unxz.c,v 1.5 2011/09/30 01:32:21 christos Exp $");
+__RCSID("$NetBSD: unxz.c,v 1.6 2016/01/29 15:19:01 christos Exp $");
 
 #include 
 #include 



CVS commit: src/usr.bin/gzip

2015-10-27 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Oct 27 07:36:18 UTC 2015

Modified Files:
src/usr.bin/gzip: gzip.1 gzip.c

Log Message:
port across the change from freebsd rev 290024:

In gunzip(1), treat trailing garbage as a warning and not an error.  This
allows scripts to distinguish it between real fatal errors, for instance a
CRC mismatch.

Update manual page for the behavior change.

PR: bin/203873
Submitted by:   Eugene Grosbein 
MFC after:  2 weeks


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/gzip/gzip.1
cvs rdiff -u -r1.108 -r1.109 src/usr.bin/gzip/gzip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.1
diff -u src/usr.bin/gzip/gzip.1:1.25 src/usr.bin/gzip/gzip.1:1.26
--- src/usr.bin/gzip/gzip.1:1.25	Mon Apr  6 21:41:17 2015
+++ src/usr.bin/gzip/gzip.1	Tue Oct 27 07:36:18 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: gzip.1,v 1.25 2015/04/06 21:41:17 wiz Exp $
+.\"	$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,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd April 6, 2015
+.Dd October 26, 2015
 .Dt GZIP 1
 .Os
 .Sh NAME
@@ -169,6 +169,12 @@ is set, it is parsed as a white-space se
 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 ,

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.108 src/usr.bin/gzip/gzip.c:1.109
--- src/usr.bin/gzip/gzip.c:1.108	Wed Apr 15 02:29:12 2015
+++ src/usr.bin/gzip/gzip.c	Tue Oct 27 07:36:18 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: gzip.c,v 1.108 2015/04/15 02:29:12 christos Exp $	*/
+/*	$NetBSD: gzip.c,v 1.109 2015/10/27 07:36:18 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.108 2015/04/15 02:29:12 christos Exp $");
+__RCSID("$NetBSD: gzip.c,v 1.109 2015/10/27 07:36:18 mrg Exp $");
 #endif /* not lint */
 
 /*
@@ -788,6 +788,7 @@ gz_uncompress(int in, int out, char *pre
 	goto stop;
 }
 maybe_warnx("input not gziped (MAGIC0)");
+exit_value = 2;
 goto stop_and_fail;
 			}
 			ADVANCE();



CVS commit: src/usr.bin/gzip

2015-07-06 Thread Takeshi Nakayama
Module Name:src
Committed By:   nakayama
Date:   Mon Jul  6 12:05:40 UTC 2015

Modified Files:
src/usr.bin/gzip: zgrep

Log Message:
zgrep(1): suppress the prefixing of filename on output when only
one file is specified to match the grep(1)'s output.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/gzip/zgrep

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/zgrep
diff -u src/usr.bin/gzip/zgrep:1.8 src/usr.bin/gzip/zgrep:1.9
--- src/usr.bin/gzip/zgrep:1.8	Thu Jul 25 12:25:23 2013
+++ src/usr.bin/gzip/zgrep	Mon Jul  6 12:05:40 2015
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: zgrep,v 1.8 2013/07/25 12:25:23 pgoyette Exp $
+# $NetBSD: zgrep,v 1.9 2015/07/06 12:05:40 nakayama Exp $
 #
 # Copyright (c) 2003 Thomas Klausner.
 #
@@ -113,7 +113,7 @@ then
 ${zcat} -fq - | ${grep} ${grep_args} -- ${pattern} -
 else
 # ... on all files given on the command line
-if [ ${silent} -lt 1 ]; then
+if [ ${silent} -lt 1 -a $# -gt 1 ]; then
 	grep_args=-H ${grep_args}
 fi
 while [ $# -gt 0 ]



CVS commit: src/usr.bin/gzip

2015-04-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Apr 15 02:29:13 UTC 2015

Modified Files:
src/usr.bin/gzip: gzip.c

Log Message:
Coverity CID 1264915, Via FreeBSD (Xin Li)

When reading in the original file name from gzip header, we read
in PATH_MAX + 1 bytes from the file.  In r281500, strrchr() is
used to strip possible path portion of the file name to mitigate
a possible attack.  Unfortunately, strrchr() expects a buffer
that is NUL-terminated, and since we are processing potentially
untrusted data, we can not assert that be always true.

Solve this by reading in one less byte (now PATH_MAX) and
explicitly terminate the buffer after the read size with NUL.


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/usr.bin/gzip/gzip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.107 src/usr.bin/gzip/gzip.c:1.108
--- src/usr.bin/gzip/gzip.c:1.107	Mon Jan 12 21:37:20 2015
+++ src/usr.bin/gzip/gzip.c	Tue Apr 14 22:29:12 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: gzip.c,v 1.107 2015/01/13 02:37:20 mrg Exp $	*/
+/*	$NetBSD: gzip.c,v 1.108 2015/04/15 02:29:12 christos 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.107 2015/01/13 02:37:20 mrg Exp $);
+__RCSID($NetBSD: gzip.c,v 1.108 2015/04/15 02:29:12 christos Exp $);
 #endif /* not lint */
 
 /*
@@ -1366,14 +1366,17 @@ file_uncompress(char *file, char *outfil
 		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)



CVS commit: src/usr.bin/gzip

2015-04-06 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Mon Apr  6 21:41:17 UTC 2015

Modified Files:
src/usr.bin/gzip: gzip.1

Log Message:
Document xz decompression support better. From Joachim Henke on netbsd-docs.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/gzip/gzip.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.1
diff -u src/usr.bin/gzip/gzip.1:1.24 src/usr.bin/gzip/gzip.1:1.25
--- src/usr.bin/gzip/gzip.1:1.24	Tue Jan 13 02:37:20 2015
+++ src/usr.bin/gzip/gzip.1	Mon Apr  6 21:41:17 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: gzip.1,v 1.24 2015/01/13 02:37:20 mrg Exp $
+.\	$NetBSD: gzip.1,v 1.25 2015/04/06 21:41:17 wiz Exp $
 .\
 .\ Copyright (c) 1997, 2003, 2004 Matthew R. Green
 .\ All rights reserved.
@@ -24,7 +24,7 @@
 .\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\ SUCH DAMAGE.
 .\
-.Dd January 13, 2015
+.Dd April 6, 2015
 .Dt GZIP 1
 .Os
 .Sh NAME
@@ -92,9 +92,10 @@ options are enabled.
 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



CVS commit: src/usr.bin/gzip

2015-01-12 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Jan 13 02:37:20 UTC 2015

Modified Files:
src/usr.bin/gzip: gzip.1 gzip.c

Log Message:
do not use directory paths present in gzip files with the -N flag,
similar to the problem reported in pigz.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/gzip/gzip.1
cvs rdiff -u -r1.106 -r1.107 src/usr.bin/gzip/gzip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.1
diff -u src/usr.bin/gzip/gzip.1:1.23 src/usr.bin/gzip/gzip.1:1.24
--- src/usr.bin/gzip/gzip.1:1.23	Tue Mar 18 18:20:45 2014
+++ src/usr.bin/gzip/gzip.1	Tue Jan 13 02:37:20 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: gzip.1,v 1.23 2014/03/18 18:20:45 riastradh Exp $
+.\	$NetBSD: gzip.1,v 1.24 2015/01/13 02:37:20 mrg Exp $
 .\
 .\ Copyright (c) 1997, 2003, 2004 Matthew R. Green
 .\ All rights reserved.
@@ -24,7 +24,7 @@
 .\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\ SUCH DAMAGE.
 .\
-.Dd June 18, 2011
+.Dd January 13, 2015
 .Dt GZIP 1
 .Os
 .Sh NAME
@@ -191,7 +191,7 @@ program for
 This manual documents
 .Nx
 .Nm
-version 20040427.
+version 20150113.
 .Sh AUTHORS
 This implementation of
 .Nm

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.106 src/usr.bin/gzip/gzip.c:1.107
--- src/usr.bin/gzip/gzip.c:1.106	Sat Oct 18 08:33:30 2014
+++ src/usr.bin/gzip/gzip.c	Tue Jan 13 02:37:20 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: gzip.c,v 1.106 2014/10/18 08:33:30 snj Exp $	*/
+/*	$NetBSD: gzip.c,v 1.107 2015/01/13 02:37:20 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.106 2014/10/18 08:33:30 snj Exp $);
+__RCSID($NetBSD: gzip.c,v 1.107 2015/01/13 02:37:20 mrg Exp $);
 #endif /* not lint */
 
 /*
@@ -160,7 +160,7 @@ static suffixes_t suffixes[] = {
 #define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0])
 #define SUFFIX_MAXLEN	30
 
-static	const char	gzip_version[] = NetBSD gzip 20101018;
+static	const char	gzip_version[] = NetBSD gzip 20150113;
 
 static	int	cflag;			/* stdout mode */
 static	int	dflag;			/* decompress mode */
@@ -1311,7 +1311,7 @@ file_uncompress(char *file, char *outfil
 #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 */
@@ -1372,15 +1372,24 @@ file_uncompress(char *file, char *outfil
 goto lose;
 			}
 			if (name[0] != 0) {
+char *dp, *nf;
+
+/* 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
 	dp++;
 snprintf(outfile, outsize, %.*s%.*s,
 		(int) (dp - file), 
-		file, (int) rbytes, name);
+		file, (int) rbytes, nf);
 			}
 		}
 	}



CVS commit: src/usr.bin/gzip

2013-12-06 Thread Fredrik Pettai
Module Name:src
Committed By:   pettai
Date:   Fri Dec  6 13:33:15 UTC 2013

Modified Files:
src/usr.bin/gzip: zmore

Log Message:
fix == compatibility problem


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/gzip/zmore

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/zmore
diff -u src/usr.bin/gzip/zmore:1.4 src/usr.bin/gzip/zmore:1.5
--- src/usr.bin/gzip/zmore:1.4	Tue Nov 12 21:58:37 2013
+++ src/usr.bin/gzip/zmore	Fri Dec  6 13:33:15 2013
@@ -1,6 +1,6 @@
 #!/bin/sh -
 #
-# $NetBSD: zmore,v 1.4 2013/11/12 21:58:37 pettai 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 $
 #
@@ -41,7 +41,7 @@ while test $# -ne 0; do
 	esac
 done
 
-if [ `basename $0` == zless ] ; then
+if [ `basename $0` = zless ] ; then
 	pager=${PAGER-less}
 else
 	pager=${PAGER-more}
@@ -49,13 +49,13 @@ fi
 
 # No files means read from stdin
 if [ $# -eq 0 ]; then
-	gzip -cdfq 21 | ${PAGER-more} $flags
+	gzip -cdfq 21 | $pager $flags
 	exit 0
 fi
 
 oterm=`stty -g 2/dev/null`
 while test $# -ne 0; do
-	gzip -cdfq $1 21 | ${PAGER-more} $flags
+	gzip -cdfq $1 21 | $pager $flags
 	prev=$1
 	shift
 	if tty -s  test -n $oterm -a $# -gt 0; then



CVS commit: src/usr.bin/gzip

2013-11-13 Thread Fredrik Pettai
Module Name:src
Committed By:   pettai
Date:   Wed Nov 13 11:12:24 UTC 2013

Modified Files:
src/usr.bin/gzip: Makefile

Log Message:
Add zfgrep that fell off from last update


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/gzip/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/Makefile
diff -u src/usr.bin/gzip/Makefile:1.17 src/usr.bin/gzip/Makefile:1.18
--- src/usr.bin/gzip/Makefile:1.17	Tue Nov 12 21:58:37 2013
+++ src/usr.bin/gzip/Makefile	Wed Nov 13 11:12:24 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.17 2013/11/12 21:58:37 pettai Exp $
+#	$NetBSD: Makefile,v 1.18 2013/11/13 11:12:24 pettai Exp $
 
 USE_FORT?= yes	# data-driven bugs?
 
@@ -23,6 +23,7 @@ LINKS+=		${BINDIR}/gzip ${BINDIR}/gunzip
 		${BINDIR}/gzip ${BINDIR}/zcat \
 		${BINDIR}/zdiff ${BINDIR}/zcmp \
 		${BINDIR}/zgrep ${BINDIR}/zegrep \
+		${BINDIR}/zgrep ${BINDIR}/zfgrep \
 		${BINDIR}/zmore ${BINDIR}/zless
 
 .include bsd.prog.mk



CVS commit: src/usr.bin/gzip

2013-07-25 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Thu Jul 25 12:25:23 UTC 2013

Modified Files:
src/usr.bin/gzip: zgrep

Log Message:
fferentiate zegrep and zfgrep by their basename only, so they can be
invoked with a pathname (ie, /usr/bin/z{e,f}grep).

OK wiz@


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/gzip/zgrep

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/zgrep
diff -u src/usr.bin/gzip/zgrep:1.7 src/usr.bin/gzip/zgrep:1.8
--- src/usr.bin/gzip/zgrep:1.7	Thu May  8 15:35:23 2008
+++ src/usr.bin/gzip/zgrep	Thu Jul 25 12:25:23 2013
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: zgrep,v 1.7 2008/05/08 15:35:23 wiz Exp $
+# $NetBSD: zgrep,v 1.8 2013/07/25 12:25:23 pgoyette Exp $
 #
 # Copyright (c) 2003 Thomas Klausner.
 #
@@ -33,7 +33,7 @@ grep_args=
 hyphen=0
 silent=0
 
-prg=$0
+prg=$(basename $0)
 
 # handle being called 'zegrep' or 'zfgrep'
 case ${prg} in



CVS commit: src/usr.bin/gzip

2011-09-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Sep 30 01:32:21 UTC 2011

Modified Files:
src/usr.bin/gzip: unxz.c

Log Message:
add copyright


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/gzip/unxz.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/unxz.c
diff -u src/usr.bin/gzip/unxz.c:1.4 src/usr.bin/gzip/unxz.c:1.5
--- src/usr.bin/gzip/unxz.c:1.4	Wed Aug 17 10:07:45 2011
+++ src/usr.bin/gzip/unxz.c	Thu Sep 29 21:32:21 2011
@@ -1,3 +1,42 @@
+/*	$NetBSD: unxz.c,v 1.5 2011/09/30 01:32:21 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *must display the following acknowledgement:
+ *This product includes software developed by the NetBSD
+ *Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * 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
+__RCSID($NetBSD: unxz.c,v 1.5 2011/09/30 01:32:21 christos Exp $);
 
 #include stdarg.h
 #include errno.h



CVS commit: src/usr.bin/gzip

2011-08-30 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Aug 30 23:06:01 UTC 2011

Modified Files:
src/usr.bin/gzip: gzip.c

Log Message:
Use __printflike and __dead.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/usr.bin/gzip/gzip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.104 src/usr.bin/gzip/gzip.c:1.105
--- src/usr.bin/gzip/gzip.c:1.104	Wed Aug 17 14:07:31 2011
+++ src/usr.bin/gzip/gzip.c	Tue Aug 30 23:06:00 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: gzip.c,v 1.104 2011/08/17 14:07:31 christos Exp $	*/
+/*	$NetBSD: gzip.c,v 1.105 2011/08/30 23:06:00 joerg 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.104 2011/08/17 14:07:31 christos Exp $);
+__RCSID($NetBSD: gzip.c,v 1.105 2011/08/30 23:06:00 joerg Exp $);
 #endif /* not lint */
 
 /*
@@ -185,17 +185,13 @@
 
 static	char	*infile;		/* name of file coming in */
 
-static	void	maybe_err(const char *fmt, ...)
-__attribute__((__noreturn__,__format__(__printf__, 1, 2)));
+static	void	maybe_err(const char *fmt, ...) __printflike(1, 2) __dead;
 #if !defined(NO_BZIP2_SUPPORT) || !defined(NO_PACK_SUPPORT) ||	\
 !defined(NO_XZ_SUPPORT)
-static	void	maybe_errx(const char *fmt, ...)
-__attribute__((__noreturn__,__format__(__printf__, 1, 2)));
+static	void	maybe_errx(const char *fmt, ...) __printflike(1, 2) __dead;
 #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)
@@ -210,8 +206,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);
+__dead static	void	usage(void);
+__dead static	void	display_version(void);
 static	const suffixes_t *check_suffix(char *, int);
 static	ssize_t	read_retry(int, void *, size_t);
 
@@ -244,8 +240,6 @@
 static	off_t	unxz(int, int, char *, size_t, off_t *);
 #endif
 
-int main(int, char *p[]);
-
 #ifdef SMALL
 #define getopt_long(a,b,c,d,e) getopt(a,b,c)
 #else



CVS commit: src/usr.bin/gzip

2011-08-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Aug 17 14:07:31 UTC 2011

Modified Files:
src/usr.bin/gzip: gzip.c

Log Message:
add noreturn atttribute.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/usr.bin/gzip/gzip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.103 src/usr.bin/gzip/gzip.c:1.104
--- src/usr.bin/gzip/gzip.c:1.103	Tue Jun 21 09:25:45 2011
+++ src/usr.bin/gzip/gzip.c	Wed Aug 17 10:07:31 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: gzip.c,v 1.103 2011/06/21 13:25:45 joerg Exp $	*/
+/*	$NetBSD: gzip.c,v 1.104 2011/08/17 14:07:31 christos 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.103 2011/06/21 13:25:45 joerg Exp $);
+__RCSID($NetBSD: gzip.c,v 1.104 2011/08/17 14:07:31 christos Exp $);
 #endif /* not lint */
 
 /*
@@ -186,11 +186,11 @@
 static	char	*infile;		/* name of file coming in */
 
 static	void	maybe_err(const char *fmt, ...)
-__attribute__((__format__(__printf__, 1, 2)));
+__attribute__((__noreturn__,__format__(__printf__, 1, 2)));
 #if !defined(NO_BZIP2_SUPPORT) || !defined(NO_PACK_SUPPORT) ||	\
 !defined(NO_XZ_SUPPORT)
 static	void	maybe_errx(const char *fmt, ...)
-__attribute__((__format__(__printf__, 1, 2)));
+__attribute__((__noreturn__,__format__(__printf__, 1, 2)));
 #endif
 static	void	maybe_warn(const char *fmt, ...)
 __attribute__((__format__(__printf__, 1, 2)));



CVS commit: src/usr.bin/gzip

2011-08-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Aug 17 14:07:45 UTC 2011

Modified Files:
src/usr.bin/gzip: unxz.c

Log Message:
fix non-literal format strings


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/gzip/unxz.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/unxz.c
diff -u src/usr.bin/gzip/unxz.c:1.3 src/usr.bin/gzip/unxz.c:1.4
--- src/usr.bin/gzip/unxz.c:1.3	Sat Jun 18 22:19:45 2011
+++ src/usr.bin/gzip/unxz.c	Wed Aug 17 10:07:45 2011
@@ -111,11 +111,11 @@
 break;
 
 			default:
-msg = Unknown error (%d);
+maybe_errx(Unknown error (%d), ret);
 break;
 			}
+			maybe_errx(%s, msg);
 
-			maybe_errx(msg, ret);
 		}
 	}
 }



CVS commit: src/usr.bin/gzip

2011-08-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Aug 16 03:21:47 UTC 2011

Modified Files:
src/usr.bin/gzip: zuncompress.c

Log Message:
provisional fix for CVS-2011-2895, buffer overflow when uncompressing


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/gzip/zuncompress.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/zuncompress.c
diff -u src/usr.bin/gzip/zuncompress.c:1.8 src/usr.bin/gzip/zuncompress.c:1.9
--- src/usr.bin/gzip/zuncompress.c:1.8	Sat Nov  6 17:42:32 2010
+++ src/usr.bin/gzip/zuncompress.c	Mon Aug 15 23:21:47 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: zuncompress.c,v 1.8 2010/11/06 21:42:32 mrg Exp $ */
+/*	$NetBSD: zuncompress.c,v 1.9 2011/08/16 03:21:47 christos Exp $ */
 
 /*-
  * Copyright (c) 1985, 1986, 1992, 1993
@@ -288,6 +288,8 @@
 
 		/* Generate output characters in reverse order. */
 		while (zs-u.r.zs_code = 256) {
+			if (zs-u.r.zs_stackp - de_stack = HSIZE - 1)
+return -1;
 			*zs-u.r.zs_stackp++ = tab_suffixof(zs-u.r.zs_code);
 			zs-u.r.zs_code = tab_prefixof(zs-u.r.zs_code);
 		}



CVS commit: src/usr.bin/gzip

2011-08-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Aug 16 03:25:35 UTC 2011

Modified Files:
src/usr.bin/gzip: zuncompress.c

Log Message:
set errno on overflow return.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/gzip/zuncompress.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/zuncompress.c
diff -u src/usr.bin/gzip/zuncompress.c:1.9 src/usr.bin/gzip/zuncompress.c:1.10
--- src/usr.bin/gzip/zuncompress.c:1.9	Mon Aug 15 23:21:47 2011
+++ src/usr.bin/gzip/zuncompress.c	Mon Aug 15 23:25:34 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: zuncompress.c,v 1.9 2011/08/16 03:21:47 christos Exp $ */
+/*	$NetBSD: zuncompress.c,v 1.10 2011/08/16 03:25:34 christos Exp $ */
 
 /*-
  * Copyright (c) 1985, 1986, 1992, 1993
@@ -288,8 +288,10 @@
 
 		/* Generate output characters in reverse order. */
 		while (zs-u.r.zs_code = 256) {
-			if (zs-u.r.zs_stackp - de_stack = HSIZE - 1)
+			if (zs-u.r.zs_stackp - de_stack = HSIZE - 1) {
+errno = EOVERFLOW;
 return -1;
+			}
 			*zs-u.r.zs_stackp++ = tab_suffixof(zs-u.r.zs_code);
 			zs-u.r.zs_code = tab_prefixof(zs-u.r.zs_code);
 		}



CVS commit: src/usr.bin/gzip

2011-06-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jun 19 00:43:54 UTC 2011

Modified Files:
src/usr.bin/gzip: Makefile gzip.c
Added Files:
src/usr.bin/gzip: unxz.c

Log Message:
Add lzma (.xz) support. Somehow this does not decode after the first read yet.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/gzip/Makefile
cvs rdiff -u -r1.99 -r1.100 src/usr.bin/gzip/gzip.c
cvs rdiff -u -r0 -r1.1 src/usr.bin/gzip/unxz.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/Makefile
diff -u src/usr.bin/gzip/Makefile:1.13 src/usr.bin/gzip/Makefile:1.14
--- src/usr.bin/gzip/Makefile:1.13	Tue Apr 14 18:15:20 2009
+++ src/usr.bin/gzip/Makefile	Sat Jun 18 20:43:54 2011
@@ -1,12 +1,12 @@
-#	$NetBSD: Makefile,v 1.13 2009/04/14 22:15:20 lukem Exp $
+#	$NetBSD: Makefile,v 1.14 2011/06/19 00:43:54 christos Exp $
 
 USE_FORT?= yes	# data-driven bugs?
 
 PROG=		gzip
 MAN=		gzip.1 gzexe.1 zdiff.1 zforce.1 zgrep.1 zmore.1 znew.1
 
-DPADD=		${LIBZ} ${LIBBZ2}
-LDADD=		-lz -lbz2
+DPADD=		${LIBZ} ${LIBBZ2} ${LIBLZMA}
+LDADD=		-lz -lbz2 -llzma
 
 SCRIPTS=	gzexe zdiff zforce zgrep zmore znew
 

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.99 src/usr.bin/gzip/gzip.c:1.100
--- src/usr.bin/gzip/gzip.c:1.99	Wed Mar 23 08:59:44 2011
+++ src/usr.bin/gzip/gzip.c	Sat Jun 18 20:43:54 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: gzip.c,v 1.99 2011/03/23 12:59:44 tsutsui Exp $	*/
+/*	$NetBSD: gzip.c,v 1.100 2011/06/19 00:43:54 christos 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.99 2011/03/23 12:59:44 tsutsui Exp $);
+__RCSID($NetBSD: gzip.c,v 1.100 2011/06/19 00:43:54 christos Exp $);
 #endif /* not lint */
 
 /*
@@ -81,6 +81,9 @@
 #ifndef NO_PACK_SUPPORT
 	FT_PACK,
 #endif
+#ifndef NO_XZ_SUPPORT
+	FT_XZ,
+#endif
 	FT_LAST,
 	FT_UNKNOWN
 };
@@ -101,6 +104,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)
@@ -227,6 +236,10 @@
 static	off_t	unpack(int, int, char *, size_t, off_t *);
 #endif
 
+#ifndef NO_XZ_SUPPORT
+static	off_t	unxz(int, int, char *, size_t, off_t *);
+#endif
+
 int main(int, char *p[]);
 
 #ifdef SMALL
@@ -1097,6 +1110,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;
 }
 
@@ -1326,7 +1344,6 @@
 	}
 
 	method = file_gettype(header1);
-
 #ifndef SMALL
 	if (fflag == 0  method == FT_UNKNOWN) {
 		maybe_warnx(%s: not in gzip format, file);
@@ -1401,9 +1418,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);
@@ -1411,11 +1428,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 */
@@ -1448,30 +1465,42 @@
 			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;
 		}
 
 		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);
@@ -1479,6 +1508,7 @@
 		}
 
 		size = gz_uncompress(fd, zfd, NULL, 0, NULL, file);
+		break;
 	}
 
 	if (close(fd) != 0)
@@ -1661,6 +1691,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
@@ -2037,6 +2073,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 files:

Index: src/usr.bin/gzip/unxz.c
diff -u /dev/null src/usr.bin/gzip/unxz.c:1.1
--- /dev/null	Sat Jun 18 20:43:55 2011
+++ src/usr.bin/gzip/unxz.c	Sat Jun 18 20:43:54 2011
@@ -0,0 +1,113 @@
+
+#include stdarg.h
+#include errno.h
+#include stdio.h
+#include unistd.h
+#include 

CVS commit: src/usr.bin/gzip

2011-06-18 Thread Izumi Tsutsui
Module Name:src
Committed By:   tsutsui
Date:   Sun Jun 19 01:20:19 UTC 2011

Modified Files:
src/usr.bin/gzip: gzip.c

Log Message:
XZ_SUPPORT requires maybe_errx().


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/usr.bin/gzip/gzip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.100 src/usr.bin/gzip/gzip.c:1.101
--- src/usr.bin/gzip/gzip.c:1.100	Sun Jun 19 00:43:54 2011
+++ src/usr.bin/gzip/gzip.c	Sun Jun 19 01:20:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: gzip.c,v 1.100 2011/06/19 00:43:54 christos Exp $	*/
+/*	$NetBSD: gzip.c,v 1.101 2011/06/19 01:20:19 tsutsui 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.100 2011/06/19 00:43:54 christos Exp $);
+__RCSID($NetBSD: gzip.c,v 1.101 2011/06/19 01:20:19 tsutsui Exp $);
 #endif /* not lint */
 
 /*
@@ -184,7 +184,8 @@
 
 static	void	maybe_err(const char *fmt, ...)
 __attribute__((__format__(__printf__, 1, 2)));
-#if !defined(NO_BZIP2_SUPPORT) || !defined(NO_PACK_SUPPORT)
+#if !defined(NO_BZIP2_SUPPORT) || !defined(NO_PACK_SUPPORT) ||	\
+!defined(NO_XZ_SUPPORT)
 static	void	maybe_errx(const char *fmt, ...)
 __attribute__((__format__(__printf__, 1, 2)));
 #endif
@@ -440,7 +441,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, ...)



CVS commit: src/usr.bin/gzip

2011-06-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jun 19 01:52:28 UTC 2011

Modified Files:
src/usr.bin/gzip: unxz.c

Log Message:
- remove unused call
- read headers separately
- print error id.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/gzip/unxz.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/unxz.c
diff -u src/usr.bin/gzip/unxz.c:1.1 src/usr.bin/gzip/unxz.c:1.2
--- src/usr.bin/gzip/unxz.c:1.1	Sat Jun 18 20:43:54 2011
+++ src/usr.bin/gzip/unxz.c	Sat Jun 18 21:52:28 2011
@@ -9,33 +9,29 @@
 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;
 	off_t x = 0;
-
-	// Initialize the decoder
-	ret = lzma_alone_decoder(strm, UINT64_MAX);
-	if (ret != LZMA_OK) {
-		errno = ret == LZMA_MEM_ERROR ? ENOMEM : EINVAL;
-		maybe_errx(Cannot initialize decoder);
-	}
-
-	// Input and output buffers
 	uint8_t ibuf[BUFSIZ];
 	uint8_t obuf[BUFSIZ];
 
-	*bytes_in = prelen;
 	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_errx(Read failed);
+	*bytes_in = prelen + strm.avail_in;
 
-	memcpy(ibuf, pre, 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);
 
 	strm.next_out = obuf;
 	strm.avail_out = sizeof(obuf);
-	if ((ret = lzma_stream_decoder(strm, UINT64_MAX, 0)) != LZMA_OK)
-		maybe_errx(Can't initialize decoder);
 
 	for (;;) {
 		if (strm.avail_in == 0) {
@@ -101,13 +97,12 @@
 msg = Reached memory limit;
 break;
 
-
 			default:
-msg = Internal error (bug);
+msg = Unknown error (%d);
 break;
 			}
 
-			maybe_errx(%s, msg);
+			maybe_errx(msg, ret);
 		}
 	}
 }



CVS commit: src/usr.bin/gzip

2011-06-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jun 19 02:19:09 UTC 2011

Modified Files:
src/usr.bin/gzip: gzip.c

Log Message:
recognize .xz suffix


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/usr.bin/gzip/gzip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.101 src/usr.bin/gzip/gzip.c:1.102
--- src/usr.bin/gzip/gzip.c:1.101	Sat Jun 18 21:20:19 2011
+++ src/usr.bin/gzip/gzip.c	Sat Jun 18 22:19:09 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: gzip.c,v 1.101 2011/06/19 01:20:19 tsutsui Exp $	*/
+/*	$NetBSD: gzip.c,v 1.102 2011/06/19 02:19:09 christos 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.101 2011/06/19 01:20:19 tsutsui Exp $);
+__RCSID($NetBSD: gzip.c,v 1.102 2011/06/19 02:19:09 christos Exp $);
 #endif /* not lint */
 
 /*
@@ -150,6 +150,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



CVS commit: src/usr.bin/gzip

2011-06-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jun 19 02:19:45 UTC 2011

Modified Files:
src/usr.bin/gzip: unxz.c

Log Message:
make this work:
- forgot to account for prelen in the input length
- deal with EOF properly


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/gzip/unxz.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/unxz.c
diff -u src/usr.bin/gzip/unxz.c:1.2 src/usr.bin/gzip/unxz.c:1.3
--- src/usr.bin/gzip/unxz.c:1.2	Sat Jun 18 21:52:28 2011
+++ src/usr.bin/gzip/unxz.c	Sat Jun 18 22:19:45 2011
@@ -11,16 +11,21 @@
 	lzma_stream strm = LZMA_STREAM_INIT;
 	static const int flags = LZMA_TELL_UNSUPPORTED_CHECK|LZMA_CONCATENATED;
 	lzma_ret ret;
-	off_t x = 0;
+	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_errx(Read failed);
-	*bytes_in = prelen + strm.avail_in;
+		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);
@@ -30,6 +35,7 @@
 	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);
 
@@ -37,13 +43,20 @@
 		if (strm.avail_in == 0) {
 			strm.next_in = ibuf;
 			strm.avail_in = read(i, ibuf, sizeof(ibuf));
-//			fprintf(stderr, read = %zu\n, strm.avail_in);
-			if (strm.avail_in == (size_t)-1)
-maybe_errx(Read failed);
+			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, LZMA_RUN);
-//		fprintf(stderr, ret = %d %zu %zu\n, ret, strm.avail_in, strm.avail_out);
+		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
@@ -56,7 +69,7 @@
 
 			strm.next_out = obuf;
 			strm.avail_out = sizeof(obuf);
-			x += write_size;
+			bytes_out += write_size;
 		}
 
 		if (ret != LZMA_OK) {
@@ -66,7 +79,7 @@
 	ret = LZMA_DATA_ERROR;
 else {
 	lzma_end(strm);
-	return x;
+	return bytes_out;
 }
 			}
 



CVS commit: src/usr.bin/gzip

2011-06-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jun 19 02:22:37 UTC 2011

Modified Files:
src/usr.bin/gzip: gzip.1

Log Message:
cross reference xz.1


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/gzip/gzip.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.1
diff -u src/usr.bin/gzip/gzip.1:1.20 src/usr.bin/gzip/gzip.1:1.21
--- src/usr.bin/gzip/gzip.1:1.20	Wed Apr  1 04:15:37 2009
+++ src/usr.bin/gzip/gzip.1	Sat Jun 18 22:22:36 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: gzip.1,v 1.20 2009/04/01 08:15:37 mrg Exp $
+.\	$NetBSD: gzip.1,v 1.21 2011/06/19 02:22:36 christos Exp $
 .\
 .\ Copyright (c) 1997, 2003, 2004 Matthew R. Green
 .\ All rights reserved.
@@ -24,7 +24,7 @@
 .\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\ SUCH DAMAGE.
 .\
-.Dd April 1, 2009
+.Dd June 18, 2011
 .Dt GZIP 1
 .Os
 .Sh NAME
@@ -171,6 +171,7 @@
 .Sh SEE ALSO
 .Xr bzip2 1 ,
 .Xr compress 1 ,
+.Xr xz 1 ,
 .Xr fts 3 ,
 .Xr zlib 3
 .Sh HISTORY



CVS commit: src/usr.bin/gzip

2011-03-23 Thread Izumi Tsutsui
Module Name:src
Committed By:   tsutsui
Date:   Wed Mar 23 12:59:44 UTC 2011

Modified Files:
src/usr.bin/gzip: gzip.c

Log Message:
Fix OPT_LIST. -t is not available in SMALL case.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/usr.bin/gzip/gzip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.98 src/usr.bin/gzip/gzip.c:1.99
--- src/usr.bin/gzip/gzip.c:1.98	Sat Nov  6 21:42:32 2010
+++ src/usr.bin/gzip/gzip.c	Wed Mar 23 12:59:44 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: gzip.c,v 1.98 2010/11/06 21:42:32 mrg Exp $	*/
+/*	$NetBSD: gzip.c,v 1.99 2011/03/23 12:59:44 tsutsui 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.98 2010/11/06 21:42:32 mrg Exp $);
+__RCSID($NetBSD: gzip.c,v 1.99 2011/03/23 12:59:44 tsutsui Exp $);
 #endif /* not lint */
 
 /*
@@ -291,7 +291,7 @@
 		dflag = cflag = 1;
 
 #ifdef SMALL
-#define OPT_LIST 123456789cdhltV
+#define OPT_LIST 123456789cdhlV
 #else
 #define OPT_LIST 123456789cdfhklNnqrS:tVv
 #endif



CVS commit: src/usr.bin/gzip

2010-11-06 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Nov  6 21:42:32 UTC 2010

Modified Files:
src/usr.bin/gzip: gzip.c unpack.c zuncompress.c

Log Message:
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!


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/usr.bin/gzip/gzip.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/gzip/unpack.c
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/gzip/zuncompress.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.97 src/usr.bin/gzip/gzip.c:1.98
--- src/usr.bin/gzip/gzip.c:1.97	Sun Oct 11 09:17:21 2009
+++ src/usr.bin/gzip/gzip.c	Sat Nov  6 21:42:32 2010
@@ -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 @@
 #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 @@
 
 #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 @@
 	{ 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 @@
 #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 @@
 		case 'f':
 			fflag = 1;
 			break;
+		case 'k':
+			kflag = 1;
+			break;
 		case 'N':
 			nflag = 0;
 			Nflag = 1;
@@ -886,6 +891,9 @@
 			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 @@
 {
 	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 @@
 --uncompress\n
  -f --force   force overwriting  compress links\n
  -h --helpdisplay this help\n
+ -k --keepdon't delete input files during operation\n
  -l --listlist compressed file contents\n
  -N --namesave or restore original file name and time stamp\n
  -n --no-name don't save original file name or time stamp\n

Index: src/usr.bin/gzip/unpack.c
diff -u src/usr.bin/gzip/unpack.c:1.1 src/usr.bin/gzip/unpack.c:1.2
--- src/usr.bin/gzip/unpack.c:1.1	Sun Oct 11 07:07:54 2009
+++ src/usr.bin/gzip/unpack.c	Sat Nov  6 21:42:32 2010
@@ -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 delp...@freebsd.org
@@ -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 

CVS commit: src/usr.bin/gzip

2010-04-14 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Wed Apr 14 18:55:12 UTC 2010

Modified Files:
src/usr.bin/gzip: zdiff zdiff.1

Log Message:
Refactor zdiff and extend functionality to the common suffixes for bzip2
and xz.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/gzip/zdiff src/usr.bin/gzip/zdiff.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/zdiff
diff -u src/usr.bin/gzip/zdiff:1.3 src/usr.bin/gzip/zdiff:1.4
--- src/usr.bin/gzip/zdiff:1.3	Mon Mar 29 10:01:00 2004
+++ src/usr.bin/gzip/zdiff	Wed Apr 14 18:55:12 2010
@@ -1,10 +1,11 @@
 #!/bin/sh -
 #
-# $NetBSD: zdiff,v 1.3 2004/03/29 10:01:00 wiz Exp $
+# $NetBSD: zdiff,v 1.4 2010/04/14 18:55:12 joerg Exp $
 #
 # $OpenBSD: zdiff,v 1.2 2003/07/29 07:42:44 otto Exp $
 #
 # Copyright (c) 2003 Todd C. Miller todd.mil...@courtesan.com
+# Copyright (c) 2010 Joerg Sonnenberger jo...@netbsd.org
 #
 # Permission to use, copy, modify, and distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above
@@ -30,7 +31,57 @@
 	*)	prog=diff
 		;;
 esac
-USAGE=usage: z$prog [options] file1 [file2]
+USAGE=usage: $0 [options] file1 [file2]
+
+check_suffix() {
+	case $1 in
+	*[._-][Zz])
+		setvar $2 ${1%??}
+		setvar $3 gzip -cdqf
+		;;
+	*[._-]bz)
+		setvar $2 ${1%???}
+		setvar $3 bzip2 -cdqf
+		;;
+	*[._-]gz)
+		setvar $2 ${1%???}
+		setvar $3 gzip -cdqf
+		;;
+	*[._-]xz)
+		setvar $2 ${1%???}
+		setvar $3 xz -cdqf
+		;;
+	*[._-]bz2)
+		setvar $2 ${1%}
+		setvar $3 bzip2 -cdqf
+		;;
+	*[._-]lzma)
+		setvar $2 ${1%?}
+		setvar $3 xz -cdqf
+		;;
+	*.t[ag]z)
+		setvar $2 ${1%??}ar
+		setvar $3 gzip -cdqf
+		;;
+	*.tbz)
+		setvar $2 ${1%??}ar
+		setvar $3 bzip2 -cdqf
+		;;
+	*.tbz2)
+		setvar $2 ${1%???}ar
+		setvar $3 bzip2 -cdqf
+		;;
+	*.t[lx]z)
+		setvar $2 ${1%??}ar
+		setvar $3 xz -cdqf
+		;;
+	*)
+		setvar $2 $1
+		setvar $3 
+		;;
+	esac
+}
+
 
 # Pull out any command line flags so we can pass them to diff/cmp
 # XXX - assumes there is no optarg
@@ -41,6 +92,9 @@
 			shift
 			break
 			;;
+		-)
+			break
+			;;
 		-*)
 			flags=$flags $1
 			shift
@@ -54,52 +108,28 @@
 if [ $# -eq 1 ]; then
 	# One file given, compare compressed to uncompressed
 	files=$1
-	case $1 in
-		*[._-][Zz])
-			files=${1%??}
-			;;
-		*[._-]gz)
-			files=${1%???}
-			;;
-		*.t[ag]z)
-			files=${1%??}ar
-			;;
-		*)	echo z$prog: unknown suffix 12
-			exit 1
-	esac
-	gzip -cdfq $1 | $prog $flags - $files
+	check_suffix $1 files filt
+	if [ -z $filt ]; then
+		echo z$prog: unknown suffix 12
+		exit 1
+	fi
+	$filt -cdfq $1 | $prog $flags - $files
 	status=$?
 elif [ $# -eq 2 ]; then
 	# Two files given, compare the two uncompressing as needed
-	case $1 in
-		*[._-][Zz]|*[._-]gz|*.t[ag]z)
-			files=-
-			filt=gzip -cdfq $1
-			;;
-		*)
-			files=$1
-			;;
-	esac
-	case $2 in
-		*[._-][Zz]|*[._-]gz|*.t[ag]z)
-			if [ $files = - ]; then
-tmp=`mktemp -t z$prog.XX` || exit 1
-trap rm -f $tmp 0 1 2 3 13 15
-gzip -cdfq $2  $tmp
-files=$files $tmp
-			else
-files=$files -
-filt=gzip -cdfq $2
-			fi
-			;;
-		*)
-			files=$files $2
-			;;
-	esac
-	if [ -n $filt ]; then
-		$filt | $prog $flags $files
+	check_suffix $1 files filt
+	check_suffix $2 files2 filt2
+	if [ -z $filt -a -z $filt2 ]; then
+		$prog $flags $1 $2
+	elif [ -z $filt -a -n $filt2 -a $1 != - ]; then
+		$filt2 $2 | $prog $flags $1 -
+	elif [ -n $filt -a -z $filt2 -a $2 != - ]; then
+		$filt $1 | $prog $flags - $2
 	else
-		$prog $flags $files
+		tmp=`mktemp -t z$prog.XX` || exit 1
+		trap rm -f $tmp 0 1 2 3 13 15
+		${filt2:-cat} $2  $tmp || exit $?
+		${filt:-cat} $1 | $prog $flags - $tmp
 	fi
 	status=$?
 else
Index: src/usr.bin/gzip/zdiff.1
diff -u src/usr.bin/gzip/zdiff.1:1.3 src/usr.bin/gzip/zdiff.1:1.4
--- src/usr.bin/gzip/zdiff.1:1.3	Sun Dec 28 12:48:03 2003
+++ src/usr.bin/gzip/zdiff.1	Wed Apr 14 18:55:12 2010
@@ -1,7 +1,8 @@
-.\	$NetBSD: zdiff.1,v 1.3 2003/12/28 12:48:03 wiz Exp $
+.\	$NetBSD: zdiff.1,v 1.4 2010/04/14 18:55:12 joerg Exp $
 .\	$OpenBSD: zdiff.1,v 1.2 2003/07/13 17:39:14 millert Exp $
 .\
 .\ Copyright (c) 2003 Todd C. Miller todd.mil...@courtesan.com
+.\ Copyright (c) 2010 Joerg Sonnenberger jo...@netbsd.org
 .\
 .\ Permission to use, copy, modify, and distribute this software for any
 .\ purpose with or without fee is hereby granted, provided that the above
@@ -19,7 +20,7 @@
 .\ Agency (DARPA) and Air Force Research Laboratory, Air Force
 .\ Materiel Command, USAF, under agreement number F39502-99-1-0512.
 .\
-.Dd June 23, 2003
+.Dd April 14, 2010
 .Dt ZDIFF 1
 .Os
 .Sh NAME
@@ -44,15 +45,6 @@
 or
 .Xr diff 1
 respectively to compare compressed files.
-Such files generally have a
-.Dq Z
-or
-.Dq gz
-extension (both the
-.Xr compress 1
-and
-.Xr gzip 1
-formats are supported).
 Any
 .Ar options
 that are specified are passed to
@@ -69,6 +61,45 @@
 or
 .Ar file2
 are 

CVS commit: src/usr.bin/gzip

2010-04-14 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Apr 14 19:52:05 UTC 2010

Modified Files:
src/usr.bin/gzip: zdiff.1

Log Message:
Sort SEE ALSO, fix an xref.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/gzip/zdiff.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/zdiff.1
diff -u src/usr.bin/gzip/zdiff.1:1.4 src/usr.bin/gzip/zdiff.1:1.5
--- src/usr.bin/gzip/zdiff.1:1.4	Wed Apr 14 18:55:12 2010
+++ src/usr.bin/gzip/zdiff.1	Wed Apr 14 19:52:05 2010
@@ -1,4 +1,4 @@
-.\	$NetBSD: zdiff.1,v 1.4 2010/04/14 18:55:12 joerg Exp $
+.\	$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 $
 .\
 .\ Copyright (c) 2003 Todd C. Miller todd.mil...@courtesan.com
@@ -76,7 +76,7 @@
 .El
 .Pp
 Extensions handled by
-.Xr bzip 1 :
+.Xr bzip2 1 :
 .Bl -bullet -compact
 .It
 bz,
@@ -120,8 +120,8 @@
 .Sh SEE ALSO
 .Xr bzip2 1 ,
 .Xr cmp 1 ,
-.Xr gzip 1 ,
 .Xr diff 1 ,
+.Xr gzip 1 ,
 .Xr xz 1
 .Sh CAVEATS
 .Nm zcmp



CVS commit: src/usr.bin/gzip

2010-04-14 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Wed Apr 14 20:30:28 UTC 2010

Modified Files:
src/usr.bin/gzip: zdiff

Log Message:
Consistently use -- for all programs called. Drop some redundant flags
for the no file argument case.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/gzip/zdiff

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/zdiff
diff -u src/usr.bin/gzip/zdiff:1.4 src/usr.bin/gzip/zdiff:1.5
--- src/usr.bin/gzip/zdiff:1.4	Wed Apr 14 18:55:12 2010
+++ src/usr.bin/gzip/zdiff	Wed Apr 14 20:30:28 2010
@@ -1,6 +1,6 @@
 #!/bin/sh -
 #
-# $NetBSD: zdiff,v 1.4 2010/04/14 18:55:12 joerg Exp $
+# $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 $
 #
@@ -113,23 +113,23 @@
 		echo z$prog: unknown suffix 12
 		exit 1
 	fi
-	$filt -cdfq $1 | $prog $flags - $files
+	$filt -- $1 | $prog $flags -- - $files
 	status=$?
 elif [ $# -eq 2 ]; then
 	# Two files given, compare the two uncompressing as needed
 	check_suffix $1 files filt
 	check_suffix $2 files2 filt2
 	if [ -z $filt -a -z $filt2 ]; then
-		$prog $flags $1 $2
+		$prog $flags -- $1 $2
 	elif [ -z $filt -a -n $filt2 -a $1 != - ]; then
-		$filt2 $2 | $prog $flags $1 -
+		$filt2 -- $2 | $prog $flags -- $1 -
 	elif [ -n $filt -a -z $filt2 -a $2 != - ]; then
-		$filt $1 | $prog $flags - $2
+		$filt -- $1 | $prog $flags -- - $2
 	else
 		tmp=`mktemp -t z$prog.XX` || exit 1
 		trap rm -f $tmp 0 1 2 3 13 15
-		${filt2:-cat} $2  $tmp || exit $?
-		${filt:-cat} $1 | $prog $flags - $tmp
+		${filt2:-cat} -- $2  $tmp || exit $?
+		${filt:-cat} -- $1 | $prog $flags -- - $tmp
 	fi
 	status=$?
 else



CVS commit: src/usr.bin/gzip

2009-12-04 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Dec  5 03:23:37 UTC 2009

Modified Files:
src/usr.bin/gzip: unbzip2.c

Log Message:
apply a change from Xin LI delp...@delphij.net to avoid problems when
reading from pipes.  introduced with the multi-part bz2 fixes.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/gzip/unbzip2.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/unbzip2.c
diff -u src/usr.bin/gzip/unbzip2.c:1.12 src/usr.bin/gzip/unbzip2.c:1.13
--- src/usr.bin/gzip/unbzip2.c:1.12	Sun Oct 11 05:17:20 2009
+++ src/usr.bin/gzip/unbzip2.c	Sat Dec  5 03:23:37 2009
@@ -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.
@@ -34,7 +34,7 @@
 static off_t
 unbzip2(int in, int out, char *pre, size_t prelen, off_t *bytes_in)
 {
-	int		ret, end_of_file;
+	int		ret, end_of_file, cold = 0;
 	off_t		bytes_out = 0;
 	bz_stream	bzs;
 	static char	*inbuf, *outbuf;
@@ -84,8 +84,18 @@
 	switch (ret) {
 	case BZ_STREAM_END:
 	case BZ_OK:
-	if (ret == BZ_OK  end_of_file)
-	maybe_err(read);
+	if (ret == BZ_OK  end_of_file) {
+/*
+ * If we hit this after a stream end, consider
+ * it as the end of the whole file and don't
+ * bail out.
+ */
+if (cold == 1)
+	ret = BZ_STREAM_END;
+else
+	maybe_errx(truncated file);
+			}
+			cold = 0;
 	if (!tflag  bzs.avail_out != BUFLEN) {
 ssize_t	n;
 
@@ -98,6 +108,7 @@
 if (BZ2_bzDecompressEnd(bzs) != BZ_OK ||
 BZ2_bzDecompressInit(bzs, 0, 0) != BZ_OK)
 	maybe_errx(bzip2 re-init);
+cold = 1;
 ret = BZ_OK;
 			}
 			break;



CVS commit: src/usr.bin/gzip

2009-10-11 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Oct 11 07:07:54 UTC 2009

Modified Files:
src/usr.bin/gzip: gzip.c
Added Files:
src/usr.bin/gzip: unpack.c

Log Message:
add pack uncompression support, from Xin LI delp...@delphij.net


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/usr.bin/gzip/gzip.c
cvs rdiff -u -r0 -r1.1 src/usr.bin/gzip/unpack.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.94 src/usr.bin/gzip/gzip.c:1.95
--- src/usr.bin/gzip/gzip.c:1.94	Sun Apr 12 10:31:14 2009
+++ src/usr.bin/gzip/gzip.c	Sun Oct 11 07:07:54 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: gzip.c,v 1.94 2009/04/12 10:31:14 lukem Exp $	*/
+/*	$NetBSD: gzip.c,v 1.95 2009/10/11 07:07:54 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.94 2009/04/12 10:31:14 lukem Exp $);
+__RCSID($NetBSD: gzip.c,v 1.95 2009/10/11 07:07:54 mrg Exp $);
 #endif /* not lint */
 
 /*
@@ -78,6 +78,9 @@
 #ifndef NO_COMPRESS_SUPPORT
 	FT_Z,
 #endif
+#ifndef NO_PACK_SUPPORT
+	FT_PACK,
+#endif
 	FT_LAST,
 	FT_UNKNOWN
 };
@@ -94,6 +97,10 @@
 #define Z_MAGIC		\037\235
 #endif
 
+#ifndef NO_PACK_SUPPORT
+#define PACK_MAGIC	\037\036
+#endif
+
 #define GZ_SUFFIX	.gz
 
 #define BUFLEN		(64 * 1024)
@@ -166,7 +173,7 @@
 
 static	void	maybe_err(const char *fmt, ...)
 __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, ...)
 __attribute__((__format__(__printf__, 1, 2)));
 #endif
@@ -214,6 +221,10 @@
 static	off_t	zuncompress(FILE *, FILE *, char *, size_t, off_t *);
 #endif
 
+#ifndef NO_PACK_SUPPORT
+static	off_t	unpack(int, int, char *, size_t, off_t *);
+#endif
+
 int main(int, char *p[]);
 
 #ifdef SMALL
@@ -408,7 +419,7 @@
 	exit(2);
 }
 
-#ifndef NO_BZIP2_SUPPORT
+#if !defined(NO_BZIP2_SUPPORT) || !defined(NO_PACK_SUPPORT)
 /* ... without an errno. */
 void
 maybe_errx(const char *fmt, ...)
@@ -1070,6 +1081,11 @@
 		return FT_Z;
 	else
 #endif
+#ifndef NO_PACK_SUPPORT
+	if (memcmp(buf, PACK_MAGIC, 2) == 0)
+		return FT_PACK;
+	else
+#endif
 		return FT_UNKNOWN;
 }
 
@@ -1422,6 +1438,17 @@
 	} else
 #endif
 
+#ifndef NO_PACK_SUPPORT
+	if (method == FT_PACK) {
+		if (lflag) {
+			maybe_warnx(no -l with packed files);
+			goto lose;
+		}
+
+		size = unpack(fd, zfd, NULL, 0, NULL);
+	} else
+#endif
+
 #ifndef SMALL
 	if (method == FT_UNKNOWN) {
 		if (lflag) {
@@ -1615,6 +1642,12 @@
 		fclose(in);
 		break;
 #endif
+#ifndef NO_PACK_SUPPORT
+	case FT_PACK:
+		usize = unpack(STDIN_FILENO, STDOUT_FILENO,
+			   (char *)header1, sizeof header1, gsize);
+		break;
+#endif
 	}
 
 #ifndef SMALL
@@ -1987,6 +2020,9 @@
 #ifndef NO_COMPRESS_SUPPORT
 #include zuncompress.c
 #endif
+#ifndef NO_PACK_SUPPORT
+#include unpack.c
+#endif
 
 static ssize_t
 read_retry(int fd, void *buf, size_t sz)

Added files:

Index: src/usr.bin/gzip/unpack.c
diff -u /dev/null src/usr.bin/gzip/unpack.c:1.1
--- /dev/null	Sun Oct 11 07:07:54 2009
+++ src/usr.bin/gzip/unpack.c	Sun Oct 11 07:07:54 2009
@@ -0,0 +1,323 @@
+/*	$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 $	*/
+
+/*-
+ * Copyright (c) 2009 Xin LI delp...@freebsd.org
+ * All rights reserved.
+ *
+ * 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 AUTHOR 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 AUTHOR 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.
+ */
+
+/* This file is #included by gzip.c */
+
+/*
+ * pack(1) 

CVS commit: src/usr.bin/gzip

2009-10-11 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Oct 11 07:09:39 UTC 2009

Modified Files:
src/usr.bin/gzip: gzip.c

Log Message:
avoid an overflow in suffix handling, from Xin LI delp...@delphij.net.


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/usr.bin/gzip/gzip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.95 src/usr.bin/gzip/gzip.c:1.96
--- src/usr.bin/gzip/gzip.c:1.95	Sun Oct 11 07:07:54 2009
+++ src/usr.bin/gzip/gzip.c	Sun Oct 11 07:09:39 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: gzip.c,v 1.95 2009/10/11 07:07:54 mrg Exp $	*/
+/*	$NetBSD: gzip.c,v 1.96 2009/10/11 07:09:39 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.95 2009/10/11 07:07:54 mrg Exp $);
+__RCSID($NetBSD: gzip.c,v 1.96 2009/10/11 07:09:39 mrg Exp $);
 #endif /* not lint */
 
 /*
@@ -146,6 +146,7 @@
 #undef SUFFIX
 };
 #define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0])
+#define SUFFIX_MAXLEN	30
 
 static	const char	gzip_version[] = NetBSD gzip 20060927;
 
@@ -334,6 +335,8 @@
 		case 'S':
 			len = strlen(optarg);
 			if (len != 0) {
+if (len  SUFFIX_MAXLEN)
+	errx(1, incorrect suffix: '%s', optarg);
 suffixes[0].zipped = optarg;
 suffixes[0].ziplen = len;
 			} else {
@@ -1200,7 +1203,7 @@
 		/* 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



CVS commit: src/usr.bin/gzip

2009-10-11 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Oct 11 09:17:21 UTC 2009

Modified Files:
src/usr.bin/gzip: gzip.c

Log Message:
update version to today.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/usr.bin/gzip/gzip.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.96 src/usr.bin/gzip/gzip.c:1.97
--- src/usr.bin/gzip/gzip.c:1.96	Sun Oct 11 07:09:39 2009
+++ src/usr.bin/gzip/gzip.c	Sun Oct 11 09:17:21 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: gzip.c,v 1.96 2009/10/11 07:09:39 mrg 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
@@ -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.96 2009/10/11 07:09:39 mrg Exp $);
+__RCSID($NetBSD: gzip.c,v 1.97 2009/10/11 09:17:21 mrg Exp $);
 #endif /* not lint */
 
 /*
@@ -148,7 +148,7 @@
 #define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0])
 #define SUFFIX_MAXLEN	30
 
-static	const char	gzip_version[] = NetBSD gzip 20060927;
+static	const char	gzip_version[] = NetBSD gzip 20091011;
 
 static	int	cflag;			/* stdout mode */
 static	int	dflag;			/* decompress mode */



CVS commit: src/usr.bin/gzip

2009-10-10 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Oct 11 05:17:20 UTC 2009

Modified Files:
src/usr.bin/gzip: unbzip2.c

Log Message:
fix support for multi-section bzip2 files, as created by pbzip2.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/gzip/unbzip2.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/unbzip2.c
diff -u src/usr.bin/gzip/unbzip2.c:1.11 src/usr.bin/gzip/unbzip2.c:1.12
--- src/usr.bin/gzip/unbzip2.c:1.11	Mon Apr 28 20:24:13 2008
+++ src/usr.bin/gzip/unbzip2.c	Sun Oct 11 05:17:20 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: unbzip2.c,v 1.11 2008/04/28 20:24:13 martin Exp $	*/
+/*	$NetBSD: unbzip2.c,v 1.12 2009/10/11 05:17:20 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
 	if (bytes_in)
 		*bytes_in = prelen;
 
-	while (ret = BZ_OK  ret != BZ_STREAM_END) {
+	while (ret == BZ_OK) {
 	if (bzs.avail_in == 0  !end_of_file) {
 			ssize_t	n;
 
@@ -86,7 +86,7 @@
 	case BZ_OK:
 	if (ret == BZ_OK  end_of_file)
 	maybe_err(read);
-	if (!tflag) {
+	if (!tflag  bzs.avail_out != BUFLEN) {
 ssize_t	n;
 
 	n = write(out, outbuf, BUFLEN - bzs.avail_out);
@@ -94,7 +94,13 @@
 	maybe_err(write);
 		bytes_out += n;
 	}
-	break;
+			if (ret == BZ_STREAM_END  !end_of_file) {
+if (BZ2_bzDecompressEnd(bzs) != BZ_OK ||
+BZ2_bzDecompressInit(bzs, 0, 0) != BZ_OK)
+	maybe_errx(bzip2 re-init);
+ret = BZ_OK;
+			}
+			break;
 
 	case BZ_DATA_ERROR:
 	maybe_warnx(bzip2 data integrity error);
@@ -107,7 +113,10 @@
 	case BZ_MEM_ERROR:
 	maybe_warnx(bzip2 out of memory);
 			break;
-
+		
+		default:	
+			maybe_warnx(unknown bzip2 error: %d, ret);
+			break;
 	}
 	}
 



CVS commit: src/usr.bin/gzip

2009-04-12 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sun Apr 12 10:31:14 UTC 2009

Modified Files:
src/usr.bin/gzip: gzip.c zuncompress.c

Log Message:
fix sign-compare issues


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/usr.bin/gzip/gzip.c
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/gzip/zuncompress.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.93 src/usr.bin/gzip/gzip.c:1.94
--- src/usr.bin/gzip/gzip.c:1.93	Sun Aug  3 09:25:05 2008
+++ src/usr.bin/gzip/gzip.c	Sun Apr 12 10:31:14 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: gzip.c,v 1.93 2008/08/03 09:25:05 skrll Exp $	*/
+/*	$NetBSD: gzip.c,v 1.94 2009/04/12 10:31:14 lukem 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.93 2008/08/03 09:25:05 skrll Exp $);
+__RCSID($NetBSD: gzip.c,v 1.94 2009/04/12 10:31:14 lukem Exp $);
 #endif /* not lint */
 
 /*
@@ -1263,7 +1263,7 @@
 	enum filetype method;
 	int fd, ofd, zfd = -1;
 #ifndef SMALL
-	int rv;
+	ssize_t rv;
 	time_t timestamp = 0;
 	unsigned char name[PATH_MAX + 1];
 #endif
@@ -1311,7 +1311,7 @@
 		unsigned char ts[4];	/* timestamp */
 
 		rv = pread(fd, ts, sizeof ts, GZIP_TIMESTAMP);
-		if (rv = 0  rv  sizeof ts)
+		if (rv = 0  rv  (ssize_t)(sizeof ts))
 			goto unexpected_EOF;
 		if (rv == -1) {
 			if (!fflag)

Index: src/usr.bin/gzip/zuncompress.c
diff -u src/usr.bin/gzip/zuncompress.c:1.6 src/usr.bin/gzip/zuncompress.c:1.7
--- src/usr.bin/gzip/zuncompress.c:1.6	Tue Nov 22 09:05:30 2005
+++ src/usr.bin/gzip/zuncompress.c	Sun Apr 12 10:31:14 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: zuncompress.c,v 1.6 2005/11/22 09:05:30 mrg Exp $ */
+/*	$NetBSD: zuncompress.c,v 1.7 2009/04/12 10:31:14 lukem Exp $ */
 
 /*-
  * Copyright (c) 1985, 1986, 1992, 1993
@@ -146,7 +146,7 @@
 		compressed_pre = NULL;
 
 	while ((bin = fread(buf, 1, sizeof(buf), in)) != 0) {
-		if (tflag == 0  fwrite(buf, 1, bin, out) != bin) {
+		if (tflag == 0  (off_t)fwrite(buf, 1, bin, out) != bin) {
 			free(buf);
 			return -1;
 		}



CVS commit: src/usr.bin/gzip

2009-04-01 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Apr  1 08:15:37 UTC 2009

Modified Files:
src/usr.bin/gzip: gzip.1

Log Message:
note that -n also stops the timestamp from being output.
bump date.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/gzip/gzip.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.1
diff -u src/usr.bin/gzip/gzip.1:1.19 src/usr.bin/gzip/gzip.1:1.20
--- src/usr.bin/gzip/gzip.1:1.19	Thu May 29 14:51:27 2008
+++ src/usr.bin/gzip/gzip.1	Wed Apr  1 08:15:37 2009
@@ -1,4 +1,4 @@
-.\	$NetBSD: gzip.1,v 1.19 2008/05/29 14:51:27 mrg Exp $
+.\	$NetBSD: gzip.1,v 1.20 2009/04/01 08:15:37 mrg Exp $
 .\
 .\ Copyright (c) 1997, 2003, 2004 Matthew R. Green
 .\ All rights reserved.
@@ -24,7 +24,7 @@
 .\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\ SUCH DAMAGE.
 .\
-.Dd April 27, 2004
+.Dd April 1, 2009
 .Dt GZIP 1
 .Os
 .Sh NAME
@@ -138,8 +138,8 @@
 This option causes the stored filename in the input file to be used
 as the output file.
 .It Fl n , -no-name
-This option stops the filename from being stored in the output
-file.
+This option stops the filename and timestamp from being stored in
+the output file.
 .It Fl q , -quiet
 With this option, no warnings or errors are printed.
 .It Fl r , -recursive