2006-07-02 19:47:05 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
2003-11-15 23:19:05 +00:00
|
|
|
/*
|
2006-04-02 21:50:01 +00:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
2003-11-15 23:19:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "libbb.h"
|
|
|
|
|
2006-04-02 21:50:01 +00:00
|
|
|
#include "unarchive.h"
|
|
|
|
|
2003-11-15 23:19:05 +00:00
|
|
|
/* transformer(), more than meets the eye */
|
2006-03-06 20:47:33 +00:00
|
|
|
int open_transformer(int src_fd, int (*transformer)(int src_fd, int dst_fd))
|
2003-11-15 23:19:05 +00:00
|
|
|
{
|
|
|
|
int fd_pipe[2];
|
|
|
|
int pid;
|
|
|
|
|
|
|
|
if (pipe(fd_pipe) != 0) {
|
|
|
|
bb_perror_msg_and_die("Can't create pipe");
|
|
|
|
}
|
|
|
|
|
|
|
|
pid = fork();
|
|
|
|
if (pid == -1) {
|
|
|
|
bb_perror_msg_and_die("Fork failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pid == 0) {
|
|
|
|
/* child process */
|
2003-11-18 21:31:19 +00:00
|
|
|
close(fd_pipe[0]); /* We don't wan't to read from the parent */
|
2003-11-15 23:19:05 +00:00
|
|
|
transformer(src_fd, fd_pipe[1]);
|
|
|
|
close(fd_pipe[1]); /* Send EOF */
|
2003-11-18 21:31:19 +00:00
|
|
|
close(src_fd);
|
2003-11-15 23:19:05 +00:00
|
|
|
exit(0);
|
|
|
|
/* notreached */
|
|
|
|
}
|
2003-11-18 21:31:19 +00:00
|
|
|
|
2003-11-15 23:19:05 +00:00
|
|
|
/* parent process */
|
2003-11-18 21:31:19 +00:00
|
|
|
close(fd_pipe[1]); /* Don't want to write to the child */
|
2003-11-15 23:19:05 +00:00
|
|
|
|
|
|
|
return(fd_pipe[0]);
|
|
|
|
}
|