Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-2]: src/usr.bin/gzip Apply patch (requested by riz in ticket #1111):
details: https://anonhg.NetBSD.org/src/rev/f22274d35c70
branches: netbsd-2
changeset: 563932:f22274d35c70
user: tron <tron%NetBSD.org@localhost>
date: Sun Jul 24 21:21:17 2005 +0000
description:
Apply patch (requested by riz in ticket #1111):
Synchronize gzip(1) with NetBSD-current.
diffstat:
usr.bin/gzip/gzexe | 3 +-
usr.bin/gzip/gzip.c | 888 +++++++++++++++++++++++---------------------
usr.bin/gzip/unbzip2.c | 18 +-
usr.bin/gzip/zuncompress.c | 28 +-
4 files changed, 500 insertions(+), 437 deletions(-)
diffs (truncated from 1607 to 300 lines):
diff -r e73d653da0dd -r f22274d35c70 usr.bin/gzip/gzexe
--- a/usr.bin/gzip/gzexe Sun Jul 24 14:39:49 2005 +0000
+++ b/usr.bin/gzip/gzexe Sun Jul 24 21:21:17 2005 +0000
@@ -1,6 +1,6 @@
#!/bin/sh -
#
-# $NetBSD: gzexe,v 1.2 2003/12/28 12:43:43 wiz Exp $
+# $NetBSD: gzexe,v 1.2.4.1 2005/07/24 21:21:17 tron Exp $
#
# $OpenBSD: gzexe,v 1.3 2003/08/05 18:22:17 deraadt Exp $
#
@@ -27,7 +27,6 @@
# Write the decompression script to stdout
header () {
- typeset prog tmp
# first section needs variable expansion, second not
cat <<- EOF
#!/bin/sh -
diff -r e73d653da0dd -r f22274d35c70 usr.bin/gzip/gzip.c
--- a/usr.bin/gzip/gzip.c Sun Jul 24 14:39:49 2005 +0000
+++ b/usr.bin/gzip/gzip.c Sun Jul 24 21:21:17 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gzip.c,v 1.29.2.29.2.2 2005/05/13 17:21:22 riz Exp $ */
+/* $NetBSD: gzip.c,v 1.29.2.29.2.3 2005/07/24 21:21:17 tron Exp $ */
/*
* Copyright (c) 1997, 1998, 2003, 2004 Matthew R. Green
@@ -32,14 +32,17 @@
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004 Matthew R. Green\n\
All rights reserved.\n");
-__RCSID("$NetBSD: gzip.c,v 1.29.2.29.2.2 2005/05/13 17:21:22 riz Exp $");
+__RCSID("$NetBSD: gzip.c,v 1.29.2.29.2.3 2005/07/24 21:21:17 tron Exp $");
#endif /* not lint */
/*
* gzip.c -- GPL free gzip using zlib.
*
+ * RFC 1950 covers the zlib format
+ * RFC 1951 covers the deflate format
+ * RFC 1952 covers the gzip format
+ *
* TODO:
- * - handle .taz/.tgz files?
* - use mmap where possible
* - handle some signals better (remove outfile?)
* - make bzip2/compress -v/-t/-l support work as well as possible
@@ -49,6 +52,7 @@
#include <sys/stat.h>
#include <sys/time.h>
+#include <inttypes.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
@@ -63,6 +67,10 @@
#include <getopt.h>
#include <time.h>
+#ifndef PRIdOFF
+#define PRIdOFF PRId64
+#endif
+
/* what type of file are we dealing with */
enum filetype {
FT_GZIP,
@@ -106,20 +114,35 @@
#define OS_CODE 3 /* Unix */
+typedef struct {
+ const char *zipped;
+ int ziplen;
+ const char *normal; /* for unzip - must not be longer than zipped */
+} suffixes_t;
+static suffixes_t suffixes[] = {
+#define SUFFIX(Z, N) {Z, sizeof Z - 1, N}
+ SUFFIX(GZ_SUFFIX, ""), /* Overwritten by -S .xxx */
#ifndef SMALL
-static char const *suffixes[] = {
- GZ_SUFFIX, ".z", ".taz", ".tgz", "-gz", "-z", "_z",
+ SUFFIX(GZ_SUFFIX, ""),
+ SUFFIX(".z", ""),
+ SUFFIX("-gz", ""),
+ SUFFIX("-z", ""),
+ SUFFIX("_z", ""),
+ SUFFIX(".taz", ".tar"),
+ SUFFIX(".tgz", ".tar"),
#ifndef NO_BZIP2_SUPPORT
- BZ2_SUFFIX,
+ SUFFIX(BZ2_SUFFIX, ""),
#endif
#ifndef NO_COMPRESS_SUPPORT
- Z_SUFFIX,
+ SUFFIX(Z_SUFFIX, ""),
#endif
- NULL
+ SUFFIX(GZ_SUFFIX, ""), /* Overwritten by -S "" */
+#endif /* SMALL */
+#undef SUFFIX
};
-#endif /* SMALL */
+#define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0])
-static const char gzip_version[] = "NetBSD gzip 20040711";
+static const char gzip_version[] = "NetBSD gzip 20040830";
static int cflag; /* stdout mode */
static int dflag; /* decompress mode */
@@ -133,28 +156,34 @@
static int qflag; /* quiet mode */
static int rflag; /* recursive mode */
static int tflag; /* test */
-static char *Sflag;
static int vflag; /* verbose mode */
#else
#define qflag 0
+#define tflag 0
#endif
static int exit_value = 0; /* exit value */
-static const char *suffix;
-#define suffix_len (strlen(suffix) + 1) /* len + nul */
static char *infile; /* name of file coming in */
-static void maybe_err(const char *fmt, ...);
-static void maybe_errx(const char *fmt, ...);
-static void maybe_warn(const char *fmt, ...);
-static void maybe_warnx(const char *fmt, ...);
+static void maybe_err(const char *fmt, ...)
+ __attribute__((__format__(__printf__, 1, 2)));
+#ifndef NO_BZIP2_SUPPORT
+static void maybe_errx(const char *fmt, ...)
+ __attribute__((__format__(__printf__, 1, 2)));
+#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 enum filetype file_gettype(u_char *);
-static off_t gz_compress(FILE *, int, off_t *, const char *, time_t);
+#ifdef SMALL
+#define gz_compress(if, of, sz, fn, tm) gz_compress(if, of, sz)
+#endif
+static off_t gz_compress(int, int, off_t *, const char *, uint32_t);
static off_t gz_uncompress(int, int, char *, size_t, off_t *, const char *);
static off_t file_compress(char *, char *, size_t);
static off_t file_uncompress(char *, char *, size_t);
-static off_t cat_fd(unsigned char *, size_t, off_t *, int fd);
static void handle_pathname(char *);
static void handle_file(char *, struct stat *);
static void handle_stdin(void);
@@ -163,15 +192,19 @@
static void print_list(int fd, off_t, const char *, time_t);
static void usage(void);
static void display_version(void);
+static const suffixes_t *check_suffix(char *, int);
+static ssize_t read_retry(int, void *, size_t);
-#ifndef SMALL
+#ifdef SMALL
+#define unlink_input(f, sb) unlink(f)
+#else
+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 *, struct stat *);
-static void print_verbage(char *, char *, off_t, off_t);
+static void print_verbage(const char *, const char *, off_t, off_t);
static void print_test(const char *, int);
static void copymodes(const char *, struct stat *);
static int check_outfile(const char *outfile, struct stat *sb);
-static const char *check_suffix(char *);
#endif
#ifndef NO_BZIP2_SUPPORT
@@ -179,7 +212,7 @@
#endif
#ifndef NO_COMPRESS_SUPPORT
-static FILE *zopen(const char *, FILE *);
+static FILE *zdopen(int);
static off_t zuncompress(FILE *, FILE *, char *, size_t, off_t *);
#endif
@@ -224,13 +257,12 @@
const char *progname = getprogname();
#ifndef SMALL
char *gzip;
+ int len;
#endif
int ch;
/* XXX set up signals */
- suffix = GZ_SUFFIX;
-
#ifndef SMALL
if ((gzip = getenv("GZIP")) != NULL)
prepend_gzip(gzip, &argc, &argv);
@@ -252,7 +284,7 @@
#define OPT_LIST "cdfhHlnNqrS:tvV123456789"
#endif
- while ((ch = getopt_long(argc, argv, OPT_LIST, longopts, NULL)) != -1)
+ while ((ch = getopt_long(argc, argv, OPT_LIST, longopts, NULL)) != -1) {
switch (ch) {
case 'c':
cflag = 1;
@@ -291,7 +323,14 @@
rflag = 1;
break;
case 'S':
- Sflag = optarg;
+ len = strlen(optarg);
+ if (len != 0) {
+ suffixes[0].zipped = optarg;
+ suffixes[0].ziplen = len;
+ } else {
+ suffixes[NUM_SUFFIXES - 1].zipped = "";
+ suffixes[NUM_SUFFIXES - 1].ziplen = 0;
+ }
break;
case 't':
cflag = 1;
@@ -306,6 +345,7 @@
usage();
/* NOTREACHED */
}
+ }
argv += optind;
argc -= optind;
@@ -370,6 +410,7 @@
exit(2);
}
+#ifndef NO_BZIP2_SUPPORT
/* ... without an errno. */
void
maybe_errx(const char *fmt, ...)
@@ -383,6 +424,7 @@
}
exit(2);
}
+#endif
#ifndef SMALL
/* split up $GZIP and prepend it to the argument list */
@@ -393,16 +435,17 @@
int nenvarg = 0, i;
/* scan how many arguments there are */
- for (s = gzip; *s; s++) {
- if (*s == ' ' || *s == '\t')
- continue;
+ for (s = gzip;;) {
+ while (*s == ' ' || *s == '\t')
+ s++;
+ if (*s == 0)
+ goto count_done;
nenvarg++;
- for (; *s; s++)
- if (*s == ' ' || *s == '\t')
- break;
- if (*s == 0x0)
- break;
+ while (*s != ' ' && *s != '\t')
+ if (*s++ == 0)
+ goto count_done;
}
+count_done:
/* punt early */
if (nenvarg == 0)
return;
@@ -425,16 +468,22 @@
s = strdup(gzip);
if (s == NULL)
maybe_err("strdup");
- for (; *s; s++) {
- if (*s == ' ' || *s == '\t')
- continue;
+ for (;;) {
+ /* Skip whitespaces. */
+ while (*s == ' ' || *s == '\t')
+ s++;
+ if (*s == 0)
+ goto copy_done;
nargv[i++] = s;
- for (; *s; s++)
- if (*s == ' ' || *s == '\t') {
- *s = 0;
- break;
- }
+ /* Find the end of this argument. */
+ while (*s != ' ' && *s != '\t')
+ if (*s++ == 0)
+ /* Argument followed by NUL. */
+ goto copy_done;
Home |
Main Index |
Thread Index |
Old Index