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 Pull up revision 1.48 (requested by mrg in...



details:   https://anonhg.NetBSD.org/src/rev/79bb500a44bb
branches:  netbsd-2-0
changeset: 561462:79bb500a44bb
user:      tron <tron%NetBSD.org@localhost>
date:      Fri Jun 18 09:56:35 2004 +0000

description:
Pull up revision 1.48 (requested by mrg in ticket #508):
- maybe restore the timestamp
- don't create the output file with "-l"
both from geoff wing with a few mods by me.

diffstat:

 usr.bin/gzip/gzip.c |  33 +++++++++++++++++++++++++++++----
 1 files changed, 29 insertions(+), 4 deletions(-)

diffs (82 lines):

diff -r 70bbfd5d72dc -r 79bb500a44bb usr.bin/gzip/gzip.c
--- a/usr.bin/gzip/gzip.c       Fri Jun 18 09:53:50 2004 +0000
+++ b/usr.bin/gzip/gzip.c       Fri Jun 18 09:56:35 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gzip.c,v 1.29.2.14 2004/06/18 09:53:50 tron Exp $      */
+/*     $NetBSD: gzip.c,v 1.29.2.15 2004/06/18 09:56:35 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.14 2004/06/18 09:53:50 tron Exp $");
+__RCSID("$NetBSD: gzip.c,v 1.29.2.15 2004/06/18 09:56:35 tron Exp $");
 #endif /* not lint */
 
 /*
@@ -95,6 +95,7 @@
 #define GZIP_MAGIC1    0x8B
 #define GZIP_OMAGIC1   0x9E
 
+#define GZIP_TIMESTAMP (off_t)4
 #define GZIP_ORIGNAME  (off_t)10
 
 #define HEAD_CRC       0x02
@@ -1004,9 +1005,12 @@
        char *s;
        off_t size;
        ssize_t len = strlen(file);
-       int fd, zfd;
        unsigned char header1[4], name[PATH_MAX + 1];
        enum filetype method;
+       int fd, zfd;
+#ifndef SMALL
+       time_t timestamp = 0;
+#endif
 
        /* gather the old name info */
 
@@ -1063,6 +1067,25 @@
        if (method == FT_GZIP && (Nflag || lflag))
 #endif
        {
+#ifndef SMALL
+               unsigned char header2[4];       /* timestamp */
+
+               if (lseek(fd, GZIP_TIMESTAMP, SEEK_SET) == -1) {
+                       maybe_warn("can't lseek %s", file);
+                       goto close_header_read;
+               }
+               if (read(fd, header2, sizeof header2) != sizeof header2) {
+                       if (fflag)
+                               goto lose_close_it;
+                       maybe_warn("can't read %s", file);
+                       goto lose;
+               }
+               timestamp = ((time_t)header2[3] << 24)
+                         + ((time_t)header2[2] << 16)
+                         + ((time_t)header2[1] << 8)
+                         +  (time_t)header2[0];
+#endif
+
                if (header1[3] & ORIG_NAME) {
                        size_t rbytes;
                        int i;
@@ -1111,12 +1134,14 @@
                                    file, isb.st_nlink - 1);
                                goto lose;
                        }
+                       if (nflag == 0 && timestamp)
+                               isb.st_mtime = timestamp;
 #endif
                } else
                        goto lose;
        }
 
-       if (cflag == 0) {
+       if (cflag == 0 && lflag == 0) {
                zfd = open(outfile, O_WRONLY|O_CREAT|O_EXCL, 0600);
                if (zfd == -1) {
                        maybe_warn("can't open %s", outfile);



Home | Main Index | Thread Index | Old Index