- if (childpid == 0) {
- close(2);
- /* send stdio to the pipes */
- if (dup2(sendpipe[0], 0) < 0)
- fprintf(stderr, "ERROR dup2()\n");
- if (dup2(recvpipe[1], 1) < 0)
- fprintf(stderr, "ERROR dup2()\n");
- close(sendpipe[1]); /* Close the ends we're not using */
- close(recvpipe[0]);
- if (!strcasecmp(encoding, "base64"))
- execlp("./base64", "base64", "-d", NULL);
- else if (!strcasecmp(encoding, "quoted-printable"))
- execlp("./qpdecode", "qpdecode", NULL);
- fprintf(stderr, "ERROR: cannot exec decoder for %s\n", encoding);
- exit(1);
- }
- close(sendpipe[0]); /* Close the ends we're not using */
- close(recvpipe[1]);
-
- while ((bytes_sent < length) && (write_error == 0)) {
- /* Empty the input pipe FIRST */
- while (fstat(recvpipe[0], &statbuf), (statbuf.st_size > 0)) {
- blocksize = read(recvpipe[0], &decoded[bytes_recv],
- statbuf.st_size);
- if (blocksize < 0)
- fprintf(stderr, "ERROR: cannot read from pipe\n");
- else
- bytes_recv = bytes_recv + blocksize;
- }
- /* Then put some data into the output pipe */
- blocksize = length - bytes_sent;
- if (blocksize > 2048)
- blocksize = 2048;
- if (write(sendpipe[1], &part_start[bytes_sent], blocksize) < 0) {
- fprintf(stderr, "ERROR: cannot write to pipe: %s\n",
- strerror(errno));
- write_error = 1;
- }
- bytes_sent = bytes_sent + blocksize;
- }
- close(sendpipe[1]);
- /* Empty the input pipe */
- while ((blocksize = read(recvpipe[0], &decoded[bytes_recv], 1)),
- (blocksize > 0)) {
- bytes_recv = bytes_recv + blocksize;