From: Nathan Moinvaziri Date: Fri, 11 Mar 2022 23:31:57 +0000 (-0800) Subject: Append extension to output file path based on window_bits when compressing and remove... X-Git-Tag: 2.1.0-beta1~338 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b991b3e1f70031478d5c2af8a4fc97c79848b79a;p=thirdparty%2Fzlib-ng.git Append extension to output file path based on window_bits when compressing and remove extension from output file path when decompressing. --- diff --git a/test/minideflate.c b/test/minideflate.c index 0352622e9..07ab2bd40 100644 --- a/test/minideflate.c +++ b/test/minideflate.c @@ -230,7 +230,6 @@ int main(int argc, char **argv) { uint8_t copyout = 0; uint8_t uncompr = 0; uint8_t keep = 0; - char out_file[320]; FILE *fin = stdin; FILE *fout = stdout; @@ -286,12 +285,31 @@ int main(int argc, char **argv) { exit(1); } if (!copyout) { - snprintf(out_file, sizeof(out_file), "%s%s", argv[i], (window_bits < 0) ? ".zz" : ".gz"); + char *out_file = (char *)calloc(1, strlen(argv[i]) + 6); + if (out_file == NULL) { + fprintf(stderr, "Not enough memory\n"); + exit(1); + } + strcat(out_file, argv[i]); + if (!uncompr) { + if (window_bits < 0) { + strcat(out_file, ".zraw"); + } else if (window_bits > MAX_WBITS) { + strcat(out_file, ".gz"); + } else { + strcat(out_file, ".z"); + } + } else { + char *out_ext = strrchr(out_file, '.'); + if (out_ext != NULL) + *out_ext = 0; + } fout = fopen(out_file, "wb"); if (fout == NULL) { fprintf(stderr, "Failed to open file: %s\n", out_file); exit(1); } + free(out_file); } }