* NEWS: Fix bug reported by Martin Mares in
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 24 Dec 2006 05:45:23 +0000 (05:45 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 24 Dec 2006 05:45:23 +0000 (05:45 +0000)
<http://bugs.debian.org/177942>.
* gzip.c (treat_stdin): Remove NO_STDIN_FSTAT and NO_PIPE_TIMESTAMP
stuff.  It didn't work (led to syntax errors) and was confusing.
Report an error if stdin cannot be statted even if !list && no_time.
Get stdin's size if it is regular.
(treat_file): Do not report an error with setuid, setgid,
sticky, or non-regular, non-directory files if to_stdout.
Allow 'force' to override the caution about sticky files.
Use the same form for time stamps that treat_stdin uses.

ChangeLog
NEWS
gzip.c

index 1213cbbecc7ce7348dce80ef5f649f9c19c5979f..cb2b1953a18d93ccc76973df7ec67ff40f6746e7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2006-12-23  Paul Eggert  <eggert@cs.ucla.edu>
 
+       * NEWS: Fix bug reported by Martin Mares in
+       <http://bugs.debian.org/177942>.
+       * gzip.c (treat_stdin): Remove NO_STDIN_FSTAT and NO_PIPE_TIMESTAMP
+       stuff.  It didn't work (led to syntax errors) and was confusing.
+       Report an error if stdin cannot be statted even if !list && no_time.
+       Get stdin's size if it is regular.
+       (treat_file): Do not report an error with setuid, setgid,
+       sticky, or non-regular, non-directory files if to_stdout.
+       Allow 'force' to override the caution about sticky files.
+       Use the same form for time stamps that treat_stdin uses.
+
        * zdiff.in: Fix typo that broke most usages.  Problem reported by
        Jari Aalto in <http://bugs.debian.org/404114>.  While we're at it,
        fix a bunch of other problems.  Handle "-" better.  Send
diff --git a/NEWS b/NEWS
index ecc9ad5241fb6a5a8172783d28ac925307c98dcc..223d8591086a46f716676fb51424bd4904b1e3f5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,9 @@ Gzip 1.3.10 (200?-??-??)
 
 * zcmp and zdiff did not work in the usual case, due to a typo.
 
+* gzip -c and zcat now work on special files, files with special mode bits,
+  and files with multiple hard links.
+
 Gzip 1.3.9 (2006-12-15)
 
 * No major changes; only porting fixes.
diff --git a/gzip.c b/gzip.c
index 0e36501cb07e84a90a9d10c0d384e0af6736d277..39484a8e48a0d0b5fbacd27c0f27b214b82fb350 100644 (file)
--- a/gzip.c
+++ b/gzip.c
@@ -616,22 +616,16 @@ local void treat_stdin()
     strcpy(ifname, "stdin");
     strcpy(ofname, "stdout");
 
-    /* Get the time stamp on the input file. */
-    time_stamp.tv_nsec = -1;  /* The time is unknown by default.  */
-
-#ifndef NO_STDIN_FSTAT
-    if (list || !no_time) {
-       if (fstat(fileno(stdin), &istat) != 0) {
-           progerror("standard input");
-           do_exit(ERROR);
-       }
-# ifdef NO_PIPE_TIMESTAMP
-       if (S_ISREG(istat.st_mode))
-# endif
-           time_stamp = get_stat_mtime (&istat);
-#endif /* NO_STDIN_FSTAT */
-    }
-    ifile_size = -1L; /* convention for unknown size */
+    /* Get the file's time stamp and size.  */
+    if (fstat (fileno (stdin), &istat) != 0)
+      {
+       progerror ("standard input");
+       do_exit (ERROR);
+      }
+    ifile_size = S_ISREG (istat.st_mode) ? istat.st_size : -1;
+    time_stamp.tv_nsec = -1;
+    if (!no_time || list)
+      time_stamp = get_stat_mtime (&istat);
 
     clear_bufs(); /* clear input and output buffers */
     to_stdout = 1;
@@ -710,48 +704,57 @@ local void treat_file(iname)
               program_name, ifname));
        return;
     }
-    if (!S_ISREG(istat.st_mode)) {
-       WARN((stderr,
-             "%s: %s is not a directory or a regular file - ignored\n",
-             program_name, ifname));
-       close (ifd);
-       return;
-    }
 
-    if (istat.st_mode & S_ISUID)
-      {
-       WARN ((stderr, "%s: %s is set-user-ID on execution - ignored\n",
-              program_name, ifname));
-       close (ifd);
-       return;
-      }
-    if (istat.st_mode & S_ISGID)
+    if (! to_stdout)
       {
-       WARN ((stderr, "%s: %s is set-group-ID on execution - ignored\n",
-              program_name, ifname));
-       close (ifd);
-       return;
-      }
-    if (istat.st_mode & S_ISVTX)
-      {
-       WARN ((stderr, "%s: %s has the sticky bit set - file ignored\n",
-              program_name, ifname));
-       close (ifd);
-       return;
-      }
+       if (! S_ISREG (istat.st_mode))
+         {
+           WARN ((stderr,
+                  "%s: %s is not a directory or a regular file - ignored\n",
+                  program_name, ifname));
+           close (ifd);
+           return;
+         }
+       if (istat.st_mode & S_ISUID)
+         {
+           WARN ((stderr, "%s: %s is set-user-ID on execution - ignored\n",
+                  program_name, ifname));
+           close (ifd);
+           return;
+         }
+       if (istat.st_mode & S_ISGID)
+         {
+           WARN ((stderr, "%s: %s is set-group-ID on execution - ignored\n",
+                  program_name, ifname));
+           close (ifd);
+           return;
+         }
 
-    if (istat.st_nlink > 1 && !to_stdout && !force) {
-       WARN((stderr, "%s: %s has %lu other link%c -- unchanged\n",
-             program_name, ifname, (unsigned long) istat.st_nlink - 1,
-             istat.st_nlink > 2 ? 's' : ' '));
-       close (ifd);
-       return;
-    }
+       if (! force)
+         {
+           if (istat.st_mode & S_ISVTX)
+             {
+               WARN ((stderr,
+                      "%s: %s has the sticky bit set - file ignored\n",
+                      program_name, ifname));
+               close (ifd);
+               return;
+             }
+           if (2 <= istat.st_nlink)
+             {
+               WARN ((stderr, "%s: %s has %lu other link%c -- unchanged\n",
+                      program_name, ifname,
+                      (unsigned long int) istat.st_nlink - 1,
+                      istat.st_nlink == 2 ? ' ' : 's'));
+               close (ifd);
+               return;
+             }
+         }
+      }
 
-    ifile_size = istat.st_size;
-    if (no_time && !list)
-      time_stamp.tv_nsec = -1;
-    else
+    ifile_size = S_ISREG (istat.st_mode) ? istat.st_size : -1;
+    time_stamp.tv_nsec = -1;
+    if (!no_time || list)
       time_stamp = get_stat_mtime (&istat);
 
     /* Generate output file name. For -r and (-t or -l), skip files