X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=gzip.c;h=cceb42000d48e80536f3c352a103c6cea63aa644;hb=d738e90e8360e101b94fca8c79147f59565f62d8;hp=5fc6ded293c785ed584812e0b7eae73bcb0ecc9c;hpb=f277ee25feefa0c56bcc71d96d99a78a4c17bffb;p=debian%2Fgzip diff --git a/gzip.c b/gzip.c index 5fc6ded..cceb420 100644 --- 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) */ @@ -223,7 +225,7 @@ static int handled_sig[] = #ifdef SIGHUP , SIGHUP #endif -#ifdef SIGPIPE +#if SIGPIPE , SIGPIPE #endif #ifdef SIGTERM @@ -256,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 */ @@ -334,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 @@ -438,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': @@ -461,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': @@ -859,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); + } } } }