/* ========================================================================
* Signal and error handler.
*/
+
static void abort_gzip()
{
error_msg("gzip aborted\n");
-// exit(ERROR);
- return;
+ exit(ERROR);
}
static void make_crc_table()
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;
return 0;
}
-extern FILE *gz_open(FILE *compressed_file, int *pid)
+#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 NULL;
+ return(EXIT_FAILURE);
}
if ((*pid = fork()) == -1) {
error_msg("fork failured");
- return NULL;
+ return(EXIT_FAILURE);
}
if (*pid==0) {
/* child process */
close(unzip_pipe[0]);
unzip(compressed_file, fdopen(unzip_pipe[1], "w"));
-// printf("finished unzipping\n");
+ printf("finished unzipping\n");
fflush(NULL);
-// printf("fluched\n");
fclose(compressed_file);
close(unzip_pipe[1]);
exit(EXIT_SUCCESS);
}
close(unzip_pipe[1]);
- return (fdopen(unzip_pipe[0], "r"));
+ return(unzip_pipe[0]);
}
extern void gz_close(int gunzip_pid)
free(window);
free(crc_table);
}
+#endif
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 */
+ }
}
}
}
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 */
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 {