I didn't see any response to my enhancement request from June (see
below) so I've included a patch.
On 27/06/08 10:24 AM Neil Mayhew wrote:
Sometimes it's useful to be able to keep the original file around.
Currently, the only way to keep the original file is either to copy
it, which is wasteful, or to use stdin/stdout redirection, which
doesn't preserve the modification time and requires the user to give
the output file name explicitly, which is error-prone and annoying. I
assume gzip does an unlink of the original file at the end, so the
unlink option would just request that this not be done.
Index: gzip.c
===================================================================
RCS file: /sources/gzip/gzip/gzip.c,v
retrieving revision 1.21
diff -u -r1.21 gzip.c
--- gzip.c 25 Nov 2007 17:19:46 -0000 1.21
+++ gzip.c 17 Sep 2008 19:33:50 -0000
@@ -182,6 +182,7 @@
int ascii = 0; /* convert end-of-lines to local OS conventions */
int to_stdout = 0; /* output to stdout (-c) */
+int keep = 0; /* keep original file (-k) */
int decompress = 0; /* decompress (-d) */
int force = 0; /* don't ask questions, compress links (-f) */
int no_name = -1; /* don't save or restore the original file name */
@@ -267,6 +268,7 @@
/* {"encrypt", 0, 0, 'e'}, encrypt */
{"force", 0, 0, 'f'}, /* force overwrite of output file */
{"help", 0, 0, 'h'}, /* give help */
+ {"keep", 0, 0, 'k'}, /* keep original file */
/* {"pkzip", 0, 0, 'k'}, force output in pkzip format */
{"list", 0, 0, 'l'}, /* list .gz file contents */
{"license", 0, 0, 'L'}, /* display software license */
@@ -342,6 +344,7 @@
/* -e, --encrypt encrypt */
" -f, --force force overwrite of output file and compress links",
" -h, --help give this help",
+ " -k, --keep keep original file",
/* -k, --pkzip force output in pkzip format */
" -l, --list list compressed file contents",
" -L, --license display software license",
@@ -447,7 +450,7 @@
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':
@@ -470,6 +473,8 @@
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':
@@ -846,7 +851,7 @@
if (close (ifd) != 0)
read_error ();
- if (!to_stdout)
+ if (!to_stdout && !keep)
{
sigset_t oldset;
int unlink_errno;