source: branches/stable/mindi-busybox/archival/libunarchive/open_transformer.c @ 821

Last change on this file since 821 was 821, checked in by bruno, 13 years ago

Addition of busybox 1.2.1 as a mindi-busybox new package
This should avoid delivering binary files in mindi not built there (Fedora and Debian are quite serious about that)

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