#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: compress.c,v 1.85 2015/11/11 21:19:12 christos Exp $")
+FILE_RCSID("@(#)$File: compress.c,v 1.86 2015/11/11 22:22:19 christos Exp $")
#endif
#include "magic.h"
{
int status;
- closefd(fdp[0], 0);
+ closefd(fdp[STDIN_FILENO], 0);
/*
* fork again, to avoid blocking because both
* pipes filled
*/
switch (fork()) {
case 0: /* child */
- closefd(fdp[1], 0);
- if (swrite(fdp[0][1], old, n) != (ssize_t)n) {
+ closefd(fdp[STDOUT_FILENO], 0);
+ if (swrite(fdp[STDIN_FILENO][1], old, n) != (ssize_t)n) {
DPRINTF("Write failed (%s)\n", strerror(errno));
exit(1);
}
}
DPRINTF("Grandchild wait return %#x\n", status);
}
- closefd(fdp[0], 1);
+ closefd(fdp[STDIN_FILENO], 1);
}
static ssize_t
for (i = 0; i < __arraycount(fdp); i++)
fdp[i][0] = fdp[i][1] = -1;
- if ((fd == -1 && pipe(fdp[0]) == -1) ||
- pipe(fdp[1]) == -1 || pipe(fdp[2]) == -1) {
- closep(fdp[0]);
- closep(fdp[1]);
+ if ((fd == -1 && pipe(fdp[STDIN_FILENO]) == -1) ||
+ pipe(fdp[STDOUT_FILENO]) == -1 || pipe(fdp[STDERR_FILENO]) == -1) {
+ closep(fdp[STDIN_FILENO]);
+ closep(fdp[STDOUT_FILENO]);
return makeerror(newch, n, "Cannot create pipe, %s",
strerror(errno));
}
switch (fork()) {
case 0: /* child */
if (fd != -1) {
- fdp[0][0] = fd;
+ fdp[STDIN_FILENO][0] = fd;
(void) lseek(fd, (off_t)0, SEEK_SET);
}
goto err;
}
rv = OKDATA;
- if ((r = sread(fdp[1][0], *newch, HOWMANY, 0)) > 0)
+ if ((r = sread(fdp[STDOUT_FILENO][0], *newch, HOWMANY, 0)) > 0)
break;
- DPRINTF("Read stdout failed %d (%s)\n", fdp[1][0],
+ DPRINTF("Read stdout failed %d (%s)\n", fdp[STDOUT_FILENO][0],
r != -1 ? strerror(errno) : "no data");
rv = ERRDATA;
- if (r == 0 && (r = sread(fdp[2][0], *newch, HOWMANY, 0)) > 0) {
+ if (r == 0 &&
+ (r = sread(fdp[STDERR_FILENO][0], *newch, HOWMANY, 0)) > 0)
+ {
r = filter_error(*newch, r);
break;
}
(*newch)[*n] = '\0';
DPRINTF("got [[[%s]]]\n", *newch);
err:
- closefd(fdp[0], 1);
- closefd(fdp[1], 0);
- closefd(fdp[2], 0);
+ closefd(fdp[STDIN_FILENO], 1);
+ closefd(fdp[STDOUT_FILENO], 0);
+ closefd(fdp[STDERR_FILENO], 0);
if (wait(&status) == -1) {
free(*newch);
rv = makeerror(newch, n, "Wait failed, %s", strerror(errno));
DPRINTF("Child exited (0x%d)\n", WEXITSTATUS(status));
}
- closefd(fdp[0], 0);
+ closefd(fdp[STDIN_FILENO], 0);
DPRINTF("Returning %p n=%zu rv=%d\n", *newch, *n, rv);
return rv;