do not use stat.st_mtime of a non-regular file
authorJim Meyering <meyering@redhat.com>
Fri, 19 Mar 2010 17:09:20 +0000 (18:09 +0100)
committerJim Meyering <meyering@redhat.com>
Sat, 20 Mar 2010 11:44:42 +0000 (12:44 +0100)
* gzip.c: Include "timespec.h".
(treat_stdin): Use st_mtime only from a regular file.
This matters at least on Cygwin 1.7.1-1, for which a stdin-pipe has
the mtime of /dev/null, rather than the gzip-documented-for-pipes
"current time".  Reported by Denis Excoffier.

THANKS
gzip.c

diff --git a/THANKS b/THANKS
index b0833e5f124590583430145e7987b5e4a6400acf..a69f8326b16a72bc3904d53c6a08623735907587 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -74,6 +74,7 @@ Paul Eggert             eggert@cs.ucla.edu
 Enami                   enami@sys.ptg.sony.co.jp
 Kristoffer Eriksson     ske@pkmab.se
 Daniel Eriksson         m91der@bellatrix.tdb.uu.se
+Denis Excoffier         3.1416@free.fr
 Rik Faith               faith@cs.unc.edu
 Larry Fahnoe            fahnoe@c1mpls.mn.org
 Cristian Ferretti       cfs@poincare.mat.puc.cl
diff --git a/gzip.c b/gzip.c
index d1105e56b5781b8538eacd9fe40cf8b42a2276c9..41322ec5104d88a76217d393bd40aa69d51868d6 100644 (file)
--- a/gzip.c
+++ b/gzip.c
@@ -67,6 +67,7 @@ static char const *const license_msg[] = {
 #include "gzip.h"
 #include "lzw.h"
 #include "revision.h"
+#include "timespec.h"
 
 #include "fcntl-safer.h"
 #include "getopt.h"
@@ -648,7 +649,12 @@ local void treat_stdin()
     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);
+      {
+        if (S_ISREG (istat.st_mode))
+          time_stamp = get_stat_mtime (&istat);
+        else
+          gettime (&time_stamp);
+      }
 
     clear_bufs(); /* clear input and output buffers */
     to_stdout = 1;