]> git.cworth.org Git - gzip/blobdiff - gzip.c
Imported Debian patch 1.3.12-1
[gzip] / gzip.c
diff --git a/gzip.c b/gzip.c
index 08b5c5fbd6c8fa80d2be549c9becf36973403422..3131e860873cdc5f70fc6cb3260db732df445550 100644 (file)
--- a/gzip.c
+++ b/gzip.c
@@ -1,6 +1,6 @@
 /* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
 
-   Copyright (C) 1999, 2001, 2002, 2006 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2001, 2002, 2006, 2007 Free Software Foundation, Inc.
    Copyright (C) 1992-1993 Jean-loup Gailly
 
    This program is free software; you can redistribute it and/or modify
@@ -28,7 +28,7 @@
  */
 
 static char  *license_msg[] = {
-"Copyright (C) 2006 Free Software Foundation, Inc.",
+"Copyright (C) 2007 Free Software Foundation, Inc.",
 "Copyright (C) 1993 Jean-loup Gailly.",
 "This is free software.  You may redistribute copies of it under the terms of",
 "the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.",
@@ -54,7 +54,7 @@ static char  *license_msg[] = {
  */
 
 #ifdef RCSID
-static char rcsid[] = "$Id: gzip.c,v 1.11 2006/12/12 00:03:17 eggert Exp $";
+static char rcsid[] = "$Id: gzip.c,v 1.16 2007/03/20 05:09:51 eggert Exp $";
 #endif
 
 #include <config.h>
@@ -72,16 +72,9 @@ static char rcsid[] = "$Id: gzip.c,v 1.11 2006/12/12 00:03:17 eggert Exp $";
 #include "fcntl-safer.h"
 #include "getopt.h"
 #include "stat-time.h"
-#include "timespec.h"
 
                /* configuration */
 
-#ifdef HAVE_TIME_H
-#  include <time.h>
-#else
-#  include <sys/time.h>
-#endif
-
 #ifdef HAVE_FCNTL_H
 #  include <fcntl.h>
 #endif
@@ -199,7 +192,7 @@ int verbose = 0;      /* be verbose (-v) */
 int quiet = 0;        /* be very quiet (-q) */
 int do_lzw = 0;       /* generate output compatible with old compress (-Z) */
 int test = 0;         /* test .gz file integrity */
-int foreground;       /* set if program run in foreground */
+int foreground = 0;   /* set if program run in foreground */
 char *program_name;   /* program name */
 int maxbits = BITS;   /* max bits per code for LZW */
 int method = DEFLATED;/* compression method */
@@ -218,7 +211,7 @@ size_t z_len;         /* strlen(z_suffix) */
 /* The set of signals that are caught.  */
 static sigset_t caught_signals;
 
-/* If nonzero then exit with status 1, rather than with the usual
+/* If nonzero then exit with status WARNING, rather than with the usual
    signal status, on receipt of a signal with this value.  This
    suppresses a "Broken Pipe" message with some shells.  */
 static int volatile exiting_signal;
@@ -412,8 +405,11 @@ int main (argc, argv)
     if (env != NULL) args = argv;
 
 #ifndef GNU_STANDARD
+# define GNU_STANDARD 1
+#endif
+#if !GNU_STANDARD
     /* For compatibility with old compress, use program name as an option.
-     * If you compile with -DGNU_STANDARD, this program will behave as
+     * Unless you compile with -DGNU_STANDARD=0, this program will behave as
      * gzip even if it is invoked under the name gunzip or zcat.
      *
      * Systems which do not support links can still use -d or -dc.
@@ -621,22 +617,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;
@@ -715,48 +705,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)
-      {
-       WARN ((stderr, "%s: %s is set-group-ID on execution - ignored\n",
-              program_name, ifname));
-       close (ifd);
-       return;
-      }
-    if (istat.st_mode & S_ISVTX)
+    if (! to_stdout)
       {
-       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
@@ -1887,7 +1886,7 @@ abort_gzip_signal (sig)
     signal (sig, SIG_IGN);
    remove_output_file ();
    if (sig == exiting_signal)
-     _exit (ERROR);
+     _exit (WARNING);
    signal (sig, SIG_DFL);
    raise (sig);
 }