gz_open and gz_close were left in, even when BB_FEATURE_TAR_GZIP was disabled.
[oweals/busybox.git] / gunzip.c
index 9d81031d704795698ea4f66ae20306cfa96f2064..51541f15553ed8b66029b660d7786800c3782009 100644 (file)
--- a/gunzip.c
+++ b/gunzip.c
@@ -126,11 +126,11 @@ unsigned short mask_bits[] = {
 /* ========================================================================
  * Signal and error handler.
  */
 static void abort_gzip()
 {
        error_msg("gzip aborted\n");
-//     exit(ERROR);
-       return;
+       exit(ERROR);
 }
 
 static void make_crc_table()
@@ -432,7 +432,6 @@ static int inflate_codes(huft_t *tl, huft_t *td, int bl, int bd)
                if (e == 16) {          /* then it's a literal */
                        window[w++] = (unsigned char) t->v.n;
                        if (w == WSIZE) {
-//                             flush_output(w);
                                outcnt=(w),
                                flush_window();
                                w = 0;
@@ -918,7 +917,7 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file)
        in_file = l_in_file;
        out_file = l_out_file;
 
-/*     if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
+       if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
                (void) signal(SIGINT, (sig_type) abort_gzip);
        }
 #ifdef SIGTERM
@@ -931,7 +930,7 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file)
                (void) signal(SIGHUP, (sig_type) abort_gzip);
        }
 #endif
-*/
+
        /* Allocate all global buffers (for DYN_ALLOC option) */
        window = xmalloc((size_t)(((2L*WSIZE)+1L)*sizeof(unsigned char)));
        outcnt = 0;
@@ -1018,11 +1017,11 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file)
        return 0;
 }
 
+#ifdef BB_FEATURE_TAR_GZIP
 extern int gz_open(FILE *compressed_file, int *pid)
 {
        int unzip_pipe[2];
 
-//     signal(SIGCHLD, abort_gzip);
        if (pipe(unzip_pipe)!=0) {
                error_msg("pipe error");
                return(EXIT_FAILURE);
@@ -1058,6 +1057,7 @@ extern void gz_close(int gunzip_pid)
        free(window);
        free(crc_table);
 }
+#endif 
 
 extern int gunzip_main(int argc, char **argv)
 {
@@ -1076,38 +1076,35 @@ extern int gunzip_main(int argc, char **argv)
        int opt = 0;
        int delete_old_file = FALSE;
 
-#ifdef BB_ZCAT
        /* if called as zcat */
        if (strcmp(applet_name, "zcat") == 0) {
                if (argc != 2) {
                        show_usage();
                }
-               flags |= gunzip_force;
-               flags |= gunzip_to_stdout;
-       } else
-#endif
-       {
+               optind = 1;
+               flags |= (gunzip_force | gunzip_to_stdout);
+       } else {
                /* workout flags as regular gunzip */
                /* set default flags */
                if (argc == 1) {
                        flags |= (gunzip_from_stdin | gunzip_to_stdout);
-               }
-
-               /* Parse any options */
-               while ((opt = getopt(argc, argv, "ctfh")) != -1) {
-                       switch (opt) {
-                       case 'c':
-                               flags |= gunzip_to_stdout;
-                               break;
-                       case 'f':
-                               flags |= gunzip_force;
-                               break;
-                       case 't':
-                               flags |= gunzip_test;
-                               break;
-                       case 'h':
-                       default:
-                               show_usage(); /* exit's inside usage */
+               } else {
+                       /* Parse any options */
+                       while ((opt = getopt(argc, argv, "ctfh")) != -1) {
+                               switch (opt) {
+                               case 'c':
+                                       flags |= gunzip_to_stdout;
+                                       break;
+                               case 'f':
+                                       flags |= gunzip_force;
+                                       break;
+                               case 't':
+                                       flags |= gunzip_test;
+                                       break;
+                               case 'h':
+                               default:
+                                       show_usage(); /* exit's inside usage */
+                               }
                        }
                }
        }
@@ -1118,7 +1115,6 @@ extern int gunzip_main(int argc, char **argv)
                if ((flags & gunzip_force) == 0) {
                        error_msg_and_die("data not written to terminal. Use -f to force it.");
                }
-               strcpy(if_name, "stdin");
        } else {
                if_name = strdup(argv[optind]);
                /* Open input file */
@@ -1137,8 +1133,6 @@ extern int gunzip_main(int argc, char **argv)
                if (isatty(fileno(out_file)) && ((flags & gunzip_force) == 0)) {
                        error_msg_and_die("data not written to terminal. Use -f to force it.");
                }
-
-               strcpy(of_name, "stdout");
        } else if (flags & gunzip_test) {
                out_file = xfopen("/dev/null", "w"); /* why does test use filenum 2 ? */
        } else {