Glenn L McGrath | 7fd9294 | 2001-04-11 03:11:33 +0000 | [diff] [blame] | 1 | #include <sys/types.h> |
| 2 | #include <sys/wait.h> |
| 3 | #include <signal.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <string.h> |
| 6 | #include <unistd.h> |
| 7 | #include "libbb.h" |
| 8 | |
Glenn L McGrath | eb1c940 | 2001-06-20 07:48:00 +0000 | [diff] [blame] | 9 | extern FILE *gz_open(FILE *compressed_file, int *pid) |
Glenn L McGrath | 7fd9294 | 2001-04-11 03:11:33 +0000 | [diff] [blame] | 10 | { |
| 11 | int unzip_pipe[2]; |
| 12 | |
| 13 | if (pipe(unzip_pipe)!=0) { |
| 14 | error_msg("pipe error"); |
Glenn L McGrath | eb1c940 | 2001-06-20 07:48:00 +0000 | [diff] [blame] | 15 | return(NULL); |
Glenn L McGrath | 7fd9294 | 2001-04-11 03:11:33 +0000 | [diff] [blame] | 16 | } |
| 17 | if ((*pid = fork()) == -1) { |
Eric Andersen | 20aab26 | 2001-07-19 22:28:02 +0000 | [diff] [blame] | 18 | error_msg("fork failed"); |
Glenn L McGrath | eb1c940 | 2001-06-20 07:48:00 +0000 | [diff] [blame] | 19 | return(NULL); |
Glenn L McGrath | 7fd9294 | 2001-04-11 03:11:33 +0000 | [diff] [blame] | 20 | } |
| 21 | if (*pid==0) { |
| 22 | /* child process */ |
| 23 | close(unzip_pipe[0]); |
| 24 | unzip(compressed_file, fdopen(unzip_pipe[1], "w")); |
Glenn L McGrath | 7fd9294 | 2001-04-11 03:11:33 +0000 | [diff] [blame] | 25 | fflush(NULL); |
| 26 | fclose(compressed_file); |
| 27 | close(unzip_pipe[1]); |
| 28 | exit(EXIT_SUCCESS); |
| 29 | } |
Glenn L McGrath | 7fd9294 | 2001-04-11 03:11:33 +0000 | [diff] [blame] | 30 | close(unzip_pipe[1]); |
Glenn L McGrath | eb1c940 | 2001-06-20 07:48:00 +0000 | [diff] [blame] | 31 | if (unzip_pipe[0] == -1) { |
Eric Andersen | 20aab26 | 2001-07-19 22:28:02 +0000 | [diff] [blame] | 32 | error_msg("gzip stream init failed"); |
Glenn L McGrath | eb1c940 | 2001-06-20 07:48:00 +0000 | [diff] [blame] | 33 | } |
| 34 | return(fdopen(unzip_pipe[0], "r")); |
| 35 | } |