/* untarzip.c - unzipping and untarring a file. It is invoked with exactly one parameter of the form name.tar.Z It has the same effect as the command uncompress filename | tar -xfv - */ #include #include #include int main(int argc, char *argv[]) { int p[2]; /* pipe established between parent and child */ pid_t id; /* value returned by fork operation */ if (argc != 2) { printf("Usage: %s filename\n", argv[0]); exit(0); } if (pipe(p) < 0) { perror("Unable to create pipe"); exit(0); } if ((id = fork()) > 0) { /* parent */ close(1); dup(p[1]); close(p[0]); execlp ("uncompress", "uncompress", "-c", argv[1], NULL); } else if (id == 0) { /* child */ close(0); dup(p[0]); close(p[1]); execlp("tar", "tar", "-xf", "-", NULL); } else { /* error case */ perror("Unable to fork"); exit(0); } return 0; }