Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-2-0]: src/usr.bin/gzip Backout last change, two revision got pull...



details:   https://anonhg.NetBSD.org/src/rev/028e44c238e5
branches:  netbsd-2-0
changeset: 561231:028e44c238e5
user:      tron <tron%NetBSD.org@localhost>
date:      Sun May 30 14:54:53 2004 +0000

description:
Backout last change, two revision got pulled up together by accident.

diffstat:

 usr.bin/gzip/gzip.c |  435 ++++++++++++++++++++-------------------------------
 1 files changed, 172 insertions(+), 263 deletions(-)

diffs (truncated from 898 to 300 lines):

diff -r 6363a1f43f21 -r 028e44c238e5 usr.bin/gzip/gzip.c
--- a/usr.bin/gzip/gzip.c       Sun May 30 14:48:32 2004 +0000
+++ b/usr.bin/gzip/gzip.c       Sun May 30 14:54:53 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gzip.c,v 1.29.2.10 2004/05/30 14:48:21 tron Exp $      */
+/*     $NetBSD: gzip.c,v 1.29.2.11 2004/05/30 14:54:53 tron Exp $      */
 
 /*
  * Copyright (c) 1997, 1998, 2003, 2004 Matthew R. Green
@@ -32,7 +32,7 @@
 #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.10 2004/05/30 14:48:21 tron Exp $");
+__RCSID("$NetBSD: gzip.c,v 1.29.2.11 2004/05/30 14:54:53 tron Exp $");
 #endif /* not lint */
 
 /*
@@ -42,6 +42,7 @@
  *     - handle .taz/.tgz files?
  *     - use mmap where possible
  *     - handle some signals better (remove outfile?)
+ *     - audit maybe_err()/maybe_warn() usage
  *     - make bzip2/compress -v/-t/-l support work as well as possible
  */
 
@@ -102,7 +103,7 @@
 
 #define OS_CODE                3       /* Unix */
 
-static const char      gzip_version[] = "NetBSD gzip 20040524";
+static const char      gzip_version[] = "NetBSD gzip 20040427";
 
 static int     cflag;                  /* stdout mode */
 static int     dflag;                  /* decompress mode */
@@ -122,22 +123,20 @@
 #define                qflag   0
 #endif
 
-static int     exit_value = 0;         /* exit value */
-
-static const char      *suffix;
+static char    *suffix;
 #define suffix_len     (strlen(suffix) + 1)    /* len + nul */
+static char    *newfile;               /* name of newly created file */
 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_err(int rv, const char *fmt, ...);
+static void    maybe_errx(int rv, const char *fmt, ...);
 static void    maybe_warn(const char *fmt, ...);
 static void    maybe_warnx(const char *fmt, ...);
 static enum filetype file_gettype(u_char *);
-static int     check_outfile(const char *outfile, struct stat *sb);
 static off_t   gz_compress(FILE *, int, off_t *, const char *, time_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   gz_uncompress(int, int, char *, size_t, off_t *);
+static off_t   file_compress(char *);
+static off_t   file_uncompress(char *);
 static void    handle_pathname(char *);
 static void    handle_file(char *, struct stat *);
 static void    handle_stdin(void);
@@ -151,7 +150,7 @@
 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_test(const char *, int);
+static void    print_test(char *, int);
 static void    copymodes(const char *, struct stat *);
 #endif
 
@@ -304,7 +303,7 @@
        if (qflag == 0 && lflag && argc > 1)
                print_list(-1, 0, "(totals)", 0);
 #endif
-       exit(exit_value);
+       exit(0);
 }
 
 /* maybe print a warning */
@@ -318,11 +317,8 @@
                vwarn(fmt, ap);
                va_end(ap);
        }
-       if (exit_value == 0)
-               exit_value = 1;
 }
 
-/* ... without an errno. */
 void
 maybe_warnx(const char *fmt, ...)
 {
@@ -333,13 +329,11 @@
                vwarnx(fmt, ap);
                va_end(ap);
        }
-       if (exit_value == 0)
-               exit_value = 1;
 }
 
-/* maybe print an error */
+/* maybe print a warning */
 void
-maybe_err(const char *fmt, ...)
+maybe_err(int rv, const char *fmt, ...)
 {
        va_list ap;
 
@@ -348,12 +342,12 @@
                vwarn(fmt, ap);
                va_end(ap);
        }
-       exit(2);
+       exit(rv);
 }
 
-/* ... without an errno. */
+/* maybe print a warning */
 void
-maybe_errx(const char *fmt, ...)
+maybe_errx(int rv, const char *fmt, ...)
 {
        va_list ap;
 
@@ -362,7 +356,7 @@
                vwarnx(fmt, ap);
                va_end(ap);
        }
-       exit(2);
+       exit(rv);
 }
 
 #ifndef SMALL
@@ -381,7 +375,7 @@
                for (; *s; s++)
                        if (*s == ' ' || *s == '\t')
                                break;
-               if (*s == 0x0)
+               if (*s == 0)
                        break;
        }
        /* punt early */
@@ -393,7 +387,7 @@
 
        nargv = (char **)malloc((*argc + 1) * sizeof(char *));
        if (nargv == NULL)
-               maybe_err("malloc");
+               maybe_err(1, "malloc");
 
        /* stash this away */
        *argv = nargv;
@@ -405,7 +399,7 @@
        /* take a copy of $GZIP and add it to the array */
        s = strdup(gzip);
        if (s == NULL)
-               maybe_err("strdup");
+               maybe_err(1, "strdup");
        for (; *s; s++) {
                if (*s == ' ' || *s == '\t')
                        continue;
@@ -445,14 +439,11 @@
                     (int)(mtime >> 24) & 0xff,
                     0, OS_CODE, origname ? origname : "");
        if (i == -1)     
-               maybe_err("asprintf");
+               maybe_err(1, "asprintf");
        if (origname)
                i++;
-       if (write(out, str, i) != i) {
-               maybe_warn("write");
-               in_tot = -1;
-               goto out;
-       }
+       if (write(out, str, i) != i)
+               maybe_err(1, "write");
        free(str);
 
        memset(&z, 0, sizeof z);
@@ -464,20 +455,14 @@
 
        error = deflateInit2(&z, numflag, Z_DEFLATED,
                             -MAX_WBITS, 8, Z_DEFAULT_STRATEGY);
-       if (error != Z_OK) {
-               maybe_warnx("deflateInit2 failed");
-               in_tot = -1;
-               goto out;
-       }
+       if (error != Z_OK)
+               maybe_errx(1, "deflateInit2 failed");
 
        crc = crc32(0L, Z_NULL, 0);
        for (;;) {
                if (z.avail_out == 0) {
-                       if (write(out, outbuf, sizeof outbuf) != sizeof outbuf) {
-                               maybe_warn("write");
-                               in_tot = -1;
-                               goto out;
-                       }
+                       if (write(out, outbuf, sizeof outbuf) != sizeof outbuf)
+                               maybe_err(1, "write");
 
                        out_tot += sizeof outbuf;
                        z.next_out = outbuf;
@@ -486,11 +471,8 @@
 
                if (z.avail_in == 0) {
                        in_size = fread(inbuf, 1, sizeof inbuf, in);
-                       if (ferror(in)) {
-                               maybe_warn("fread");
-                               in_tot = -1;
-                               goto out;
-                       }
+                       if (ferror(in))
+                               maybe_err(1, "fread");
                        if (in_size == 0)
                                break;
 
@@ -501,11 +483,8 @@
                }
 
                error = deflate(&z, Z_NO_FLUSH);
-               if (error != Z_OK && error != Z_STREAM_END) {
-                       maybe_warnx("deflate failed");
-                       in_tot = -1;
-                       goto out;
-               }
+               if (error != Z_OK && error != Z_STREAM_END)
+                       maybe_errx(1, "deflate failed");
        }
 
        /* clean up */
@@ -513,19 +492,13 @@
                size_t len;
 
                error = deflate(&z, Z_FINISH);
-               if (error != Z_OK && error != Z_STREAM_END) {
-                       maybe_warnx("deflate failed");
-                       in_tot = -1;
-                       goto out;
-               }
+               if (error != Z_OK && error != Z_STREAM_END)
+                       maybe_errx(1, "deflate failed");
 
                len = sizeof outbuf - z.avail_out;
 
-               if (write(out, outbuf, len) != len) {
-                       maybe_warn("write");
-                       out_tot = -1;
-                       goto out;
-               }
+               if (write(out, outbuf, len) != len)
+                       maybe_err(1, "write");
                out_tot += len;
                z.next_out = outbuf;
                z.avail_out = sizeof outbuf;
@@ -534,11 +507,8 @@
                        break;
        }
 
-       if (deflateEnd(&z) != Z_OK) {
-               maybe_warnx("deflateEnd failed");
-               in_tot = -1;
-               goto out;
-       }
+       if (deflateEnd(&z) != Z_OK)
+               maybe_errx(1, "deflateEnd failed");
 
        i = asprintf(&str, "%c%c%c%c%c%c%c%c", 
                 (int)crc & 0xff,
@@ -550,14 +520,14 @@
                 (int)(in_tot >> 16) & 0xff,
                 (int)(in_tot >> 24) & 0xff);
        if (i != 8)
-               maybe_err("asprintf");
-       if (write(out, str, i) != i) {
-               maybe_warn("write");
-               in_tot = -1;
-       }
+               maybe_err(1, "asprintf");
+       if (write(out, str, i) != i)
+               maybe_err(1, "write");
        free(str);
 
-out:
+       if (fclose(in) != 0)
+               maybe_err(1, "failed fclose");
+
        if (gsizep)
                *gsizep = out_tot;
        return in_tot;
@@ -569,8 +539,7 @@
  * into `*gsizep'.
  */
 static off_t
-gz_uncompress(int in, int out, char *pre, size_t prelen, off_t *gsizep,
-             const char *filename)
+gz_uncompress(int in, int out, char *pre, size_t prelen, off_t *gsizep)



Home | Main Index | Thread Index | Old Index