new upstream no longer requires this patch
[debian/gzip] / gzip.c
diff --git a/gzip.c b/gzip.c
index 35b36031f4f3f9739c442578f7e308e7894eed53..cceb42000d48e80536f3c352a103c6cea63aa644 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-2007, 2009-2012 Free Software
+   Copyright (C) 1999, 2001-2002, 2006-2007, 2009-2013 Free Software
    Foundation, Inc.
    Copyright (C) 1992-1993 Jean-loup Gailly
 
@@ -74,6 +74,7 @@ static char const *const license_msg[] = {
 #include "ignore-value.h"
 #include "stat-time.h"
 #include "version.h"
+#include "yesno.h"
 
                 /* configuration */
 
@@ -166,6 +167,7 @@ static int ascii = 0;        /* convert end-of-lines to local OS conventions */
        int to_stdout = 0;    /* output to stdout (-c) */
 static int decompress = 0;   /* decompress (-d) */
 static int force = 0;        /* don't ask questions, compress links (-f) */
+static int keep = 0;         /* keep (don't delete) input files */
 static int no_name = -1;     /* don't save or restore the original file name */
 static int no_time = -1;     /* don't save or restore the original file time */
 static int recursive = 0;    /* recurse through directories (-r) */
@@ -213,6 +215,7 @@ int  ofd;                  /* output file descriptor */
 unsigned insize;           /* valid bytes in inbuf */
 unsigned inptr;            /* index of next byte to be processed in inbuf */
 unsigned outcnt;           /* bytes in output buffer */
+int rsync = 0;             /* make ryncable chunks */
 
 static int handled_sig[] =
   {
@@ -222,7 +225,9 @@ static int handled_sig[] =
 #ifdef SIGHUP
     , SIGHUP
 #endif
+#if SIGPIPE
     , SIGPIPE
+#endif
 #ifdef SIGTERM
     , SIGTERM
 #endif
@@ -253,6 +258,7 @@ static const struct option longopts[] =
     {"force",      0, 0, 'f'}, /* force overwrite of output file */
     {"help",       0, 0, 'h'}, /* give help */
  /* {"pkzip",      0, 0, 'k'},    force output in pkzip format */
+    {"keep",       0, 0, 'k'}, /* keep (don't delete) input files */
     {"list",       0, 0, 'l'}, /* list .gz file contents */
     {"license",    0, 0, 'L'}, /* display software license */
     {"no-name",    0, 0, 'n'}, /* don't save or restore original name & time */
@@ -270,7 +276,7 @@ static const struct option longopts[] =
     {"best",       0, 0, '9'}, /* compress better */
     {"lzw",        0, 0, 'Z'}, /* make output compatible with old compress */
     {"bits",       1, 0, 'b'}, /* max number of bits per code (implies -Z) */
-
+    {"rsyncable",  0, 0, 'R'}, /* make rsync-friendly archive */
     { 0, 0, 0, 0 }
 };
 
@@ -331,6 +337,7 @@ local void help()
  "  -f, --force       force overwrite of output file and compress links",
  "  -h, --help        give this help",
 /*  -k, --pkzip       force output in pkzip format */
+ "  -k, --keep        keep (don't delete) input files",
  "  -l, --list        list compressed file contents",
  "  -L, --license     display software license",
 #ifdef UNDOCUMENTED
@@ -353,6 +360,7 @@ local void help()
  "  -Z, --lzw         produce output compatible with old compress",
  "  -b, --bits=BITS   max number of bits per code (implies -Z)",
 #endif
+ "  --rsyncable       Make rsync-friendly archive",
  "",
  "With no FILE, or when FILE is -, read standard input.",
  "",
@@ -434,7 +442,7 @@ int main (int argc, char **argv)
     z_suffix = Z_SUFFIX;
     z_len = strlen(z_suffix);
 
-    while ((optc = getopt_long (argc, argv, "ab:cdfhH?lLmMnNqrS:tvVZ123456789",
+    while ((optc = getopt_long (argc, argv, "ab:cdfhH?klLmMnNqrS:tvVZ123456789",
                                 longopts, (int *)0)) != -1) {
         switch (optc) {
         case 'a':
@@ -457,6 +465,8 @@ int main (int argc, char **argv)
             force++; break;
         case 'h': case 'H':
             help(); do_exit(OK); break;
+        case 'k':
+            keep = 1; break;
         case 'l':
             list = decompress = to_stdout = 1; break;
         case 'L':
@@ -481,8 +491,11 @@ int main (int argc, char **argv)
 #else
             recursive = 1;
 #endif
-            break;
-        case 'S':
+           break;
+        case 'R':
+           rsync = 1; break;
+
+       case 'S':
 #ifdef NO_MULTIPLE_DOTS
             if (*optarg == '.') optarg++;
 #endif
@@ -549,7 +562,11 @@ int main (int argc, char **argv)
     ALLOC(ush, tab_prefix1, 1L<<(BITS-1));
 #endif
 
+#ifdef SIGPIPE
     exiting_signal = quiet ? SIGPIPE : 0;
+#else
+    exiting_signal = 0;
+#endif
     install_signal_handlers ();
 
     /* And get to work */
@@ -848,25 +865,29 @@ local void treat_file(iname)
 
     if (!to_stdout)
       {
-        sigset_t oldset;
-        int unlink_errno;
 
         copy_stat (&istat);
         if (close (ofd) != 0)
           write_error ();
 
-        sigprocmask (SIG_BLOCK, &caught_signals, &oldset);
-        remove_ofname_fd = -1;
-        unlink_errno = xunlink (ifname) == 0 ? 0 : errno;
-        sigprocmask (SIG_SETMASK, &oldset, NULL);
-
-        if (unlink_errno)
+        if (!keep)
           {
-            WARN ((stderr, "%s: ", program_name));
-            if (!quiet)
+            sigset_t oldset;
+            int unlink_errno;
+
+            sigprocmask (SIG_BLOCK, &caught_signals, &oldset);
+            remove_ofname_fd = -1;
+            unlink_errno = xunlink (ifname) == 0 ? 0 : errno;
+            sigprocmask (SIG_SETMASK, &oldset, NULL);
+
+            if (unlink_errno)
               {
-                errno = unlink_errno;
-                perror (ifname);
+                WARN ((stderr, "%s: ", program_name));
+                if (!quiet)
+                  {
+                    errno = unlink_errno;
+                    perror (ifname);
+                  }
               }
           }
       }