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 "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-10-01 15:55:11 +00:00
|
|
|
int open_transformer(int src_fd,
|
|
|
|
USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd))
|
2003-11-15 23:19:05 +00:00
|
|
|
{
|
|
|
|
int fd_pipe[2];
|
|
|
|
int pid;
|
|
|
|
|
2007-05-26 16:44:20 +00:00
|
|
|
xpipe(fd_pipe);
|
2003-11-15 23:19:05 +00:00
|
|
|
|
|
|
|
pid = fork();
|
|
|
|
if (pid == -1) {
|
2006-10-14 02:23:43 +00:00
|
|
|
bb_perror_msg_and_die("fork failed");
|
2003-11-15 23:19:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pid == 0) {
|
|
|
|
/* child process */
|
2006-10-14 02:23:43 +00:00
|
|
|
close(fd_pipe[0]); /* We don't wan't to read from the parent */
|
|
|
|
// FIXME: error check?
|
|
|
|
transformer(src_fd, fd_pipe[1]);
|
2007-09-04 19:33:22 +00:00
|
|
|
if (ENABLE_FEATURE_CLEAN_UP) {
|
|
|
|
close(fd_pipe[1]); /* Send EOF */
|
|
|
|
close(src_fd);
|
|
|
|
}
|
2006-10-14 02:23:43 +00:00
|
|
|
exit(0);
|
|
|
|
/* notreached */
|
2003-11-15 23:19:05 +00:00
|
|
|
}
|
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
|
|
|
|
2006-10-01 15:55:11 +00:00
|
|
|
return fd_pipe[0];
|
2003-11-15 23:19:05 +00:00
|
|
|
}
|