2006-07-03 01:17:05 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
2003-11-16 04:49:05 +05:30
|
|
|
/*
|
2006-04-03 03:20:01 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
2003-11-16 04:49:05 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "libbb.h"
|
|
|
|
|
2006-04-03 03:20:01 +05:30
|
|
|
#include "unarchive.h"
|
|
|
|
|
2003-11-16 04:49:05 +05:30
|
|
|
/* transformer(), more than meets the eye */
|
2006-10-01 21:25:11 +05:30
|
|
|
int open_transformer(int src_fd,
|
|
|
|
USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd))
|
2003-11-16 04:49:05 +05:30
|
|
|
{
|
|
|
|
int fd_pipe[2];
|
|
|
|
int pid;
|
|
|
|
|
|
|
|
if (pipe(fd_pipe) != 0) {
|
2006-10-14 07:53:43 +05:30
|
|
|
bb_perror_msg_and_die("can't create pipe");
|
2003-11-16 04:49:05 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
pid = fork();
|
|
|
|
if (pid == -1) {
|
2006-10-14 07:53:43 +05:30
|
|
|
bb_perror_msg_and_die("fork failed");
|
2003-11-16 04:49:05 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if (pid == 0) {
|
|
|
|
/* child process */
|
2006-10-14 07:53:43 +05:30
|
|
|
close(fd_pipe[0]); /* We don't wan't to read from the parent */
|
|
|
|
// FIXME: error check?
|
|
|
|
transformer(src_fd, fd_pipe[1]);
|
|
|
|
close(fd_pipe[1]); /* Send EOF */
|
2003-11-19 03:01:19 +05:30
|
|
|
close(src_fd);
|
2006-10-14 07:53:43 +05:30
|
|
|
exit(0);
|
|
|
|
/* notreached */
|
2003-11-16 04:49:05 +05:30
|
|
|
}
|
2003-11-19 03:01:19 +05:30
|
|
|
|
2003-11-16 04:49:05 +05:30
|
|
|
/* parent process */
|
2003-11-19 03:01:19 +05:30
|
|
|
close(fd_pipe[1]); /* Don't want to write to the child */
|
2003-11-16 04:49:05 +05:30
|
|
|
|
2006-10-01 21:25:11 +05:30
|
|
|
return fd_pipe[0];
|
2003-11-16 04:49:05 +05:30
|
|
|
}
|