]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Append extension to output file path based on window_bits when compressing and remove...
authorNathan Moinvaziri <nathan@nathanm.com>
Fri, 11 Mar 2022 23:31:57 +0000 (15:31 -0800)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Wed, 16 Mar 2022 10:42:45 +0000 (11:42 +0100)
test/minideflate.c

index 0352622e9c81a94b91e17cb89a3af1c9f57e3320..07ab2bd407ff86c755346bb1d5f0f36f42d00026 100644 (file)
@@ -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);
         }
     }