blob: ef30ff8945b500149490e1be187674908dd74e79 [file] [log] [blame]
Glenn L McGrath7fd92942001-04-11 03:11:33 +00001#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 McGratheb1c9402001-06-20 07:48:00 +00009extern FILE *gz_open(FILE *compressed_file, int *pid)
Glenn L McGrath7fd92942001-04-11 03:11:33 +000010{
11 int unzip_pipe[2];
12
13 if (pipe(unzip_pipe)!=0) {
14 error_msg("pipe error");
Glenn L McGratheb1c9402001-06-20 07:48:00 +000015 return(NULL);
Glenn L McGrath7fd92942001-04-11 03:11:33 +000016 }
17 if ((*pid = fork()) == -1) {
Eric Andersen20aab262001-07-19 22:28:02 +000018 error_msg("fork failed");
Glenn L McGratheb1c9402001-06-20 07:48:00 +000019 return(NULL);
Glenn L McGrath7fd92942001-04-11 03:11:33 +000020 }
21 if (*pid==0) {
22 /* child process */
23 close(unzip_pipe[0]);
24 unzip(compressed_file, fdopen(unzip_pipe[1], "w"));
Glenn L McGrath7fd92942001-04-11 03:11:33 +000025 fflush(NULL);
26 fclose(compressed_file);
27 close(unzip_pipe[1]);
28 exit(EXIT_SUCCESS);
29 }
Glenn L McGrath7fd92942001-04-11 03:11:33 +000030 close(unzip_pipe[1]);
Glenn L McGratheb1c9402001-06-20 07:48:00 +000031 if (unzip_pipe[0] == -1) {
Eric Andersen20aab262001-07-19 22:28:02 +000032 error_msg("gzip stream init failed");
Glenn L McGratheb1c9402001-06-20 07:48:00 +000033 }
34 return(fdopen(unzip_pipe[0], "r"));
35}