From e4029d1e70c5cbf2185e1f0900f3713cffc9a1a4 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sun, 23 Oct 2016 13:54:53 -0700 Subject: [PATCH] gzip, gunzip: warning rather than error when output file already exists This matches the behavior of GNU gzip. --- programs/prog_util.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/programs/prog_util.c b/programs/prog_util.c index dbf6f4b..6966fc9 100644 --- a/programs/prog_util.c +++ b/programs/prog_util.c @@ -234,6 +234,8 @@ xopen_for_read(const tchar *path, struct file_stream *strm) int xopen_for_write(const tchar *path, bool overwrite, struct file_stream *strm) { + int ret = -1; + strm->mmap_mem = NULL; if (path == NULL) { @@ -263,6 +265,7 @@ retry: if (!isatty(STDERR_FILENO) || !isatty(STDIN_FILENO)) { msg("%"TS" already exists; use -f to overwrite", strm->name); + ret = -2; /* warning only */ goto err; } fprintf(stderr, "%"TS": %"TS" already exists; " @@ -284,7 +287,7 @@ retry: err: free(strm->name); - return -1; + return ret; } /* Map the contents of a file into memory */