Move compare_string_array to libbb
[oweals/busybox.git] / archival / gunzip.c
index 4489204fb914376de6a69705ac4ef3f53da056c8..e9963a8d23fa40592efd32c8c846497874d2151a 100644 (file)
@@ -143,6 +143,11 @@ extern int gunzip_main(int argc, char **argv)
                        new_path = xstrdup(old_path);
 
                        extension = strrchr(new_path, '.');
+#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS
+                       if (extension && (strcmp(extension, ".Z") == 0)) {
+                               *extension = '\0';
+                       } else
+#endif
                        if (extension && (strcmp(extension, ".gz") == 0)) {
                                *extension = '\0';
                        } else if (extension && (strcmp(extension, ".tgz") == 0)) {
@@ -163,11 +168,28 @@ extern int gunzip_main(int argc, char **argv)
                }
 
                /* do the decompression, and cleanup */
-               check_header_gzip(src_fd);
-               if (inflate(src_fd, dst_fd) != 0) {
-                       error_msg("Error inflating");
+               if (xread_char(src_fd) == 0x1f) {
+                       unsigned char magic2;
+                       
+                       magic2 = xread_char(src_fd);
+#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS
+                       if (magic2 == 0x9d) {
+                               status = uncompress(src_fd, dst_fd);
+                       } else 
+#endif
+                               if (magic2 == 0x8b) {
+                                       check_header_gzip(src_fd);
+                                       status = inflate(src_fd, dst_fd);
+                                       if (status != 0) {
+                                               error_msg_and_die("Error inflating");
+                                       }
+                                       check_trailer_gzip(src_fd);
+                               } else {
+                                       error_msg_and_die("Invalid magic");
+                               }
+               } else {
+                       error_msg_and_die("Invalid magic");
                }
-               check_trailer_gzip(src_fd);
 
                if ((status != EXIT_SUCCESS) && (new_path)) {
                        /* Unzip failed, remove new path instead of old path */