silly switch style fix
[oweals/busybox.git] / archival / libunarchive / open_transformer.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
4  */
5
6 #include <stdlib.h>
7 #include <unistd.h>
8
9 #include "libbb.h"
10
11 #include "unarchive.h"
12
13 /* transformer(), more than meets the eye */
14 int open_transformer(int src_fd, int (*transformer)(int src_fd, int dst_fd))
15 {
16         int fd_pipe[2];
17         int pid;
18
19         if (pipe(fd_pipe) != 0) {
20                 bb_perror_msg_and_die("Can't create pipe");
21         }
22
23         pid = fork();
24         if (pid == -1) {
25                 bb_perror_msg_and_die("Fork failed");
26         }
27
28         if (pid == 0) {
29                 /* child process */
30             close(fd_pipe[0]); /* We don't wan't to read from the parent */
31             transformer(src_fd, fd_pipe[1]);
32             close(fd_pipe[1]); /* Send EOF */
33                 close(src_fd);
34             exit(0);
35             /* notreached */
36         }
37
38         /* parent process */
39         close(fd_pipe[1]); /* Don't want to write to the child */
40
41         return(fd_pipe[0]);
42 }