From: Christos Zoulas Date: Wed, 11 Nov 2015 22:26:30 +0000 (+0000) Subject: use symbolic names for 0, 1, 2 X-Git-Tag: FILE5_26~83 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e0cd87641811aa79e28094f9d0cde281566fb9ec;p=file use symbolic names for 0, 1, 2 --- diff --git a/src/compress.c b/src/compress.c index 196363e9..49581c10 100644 --- a/src/compress.c +++ b/src/compress.c @@ -35,7 +35,7 @@ #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" @@ -548,15 +548,15 @@ writechild(int fdp[3][2], const void *old, size_t n) { 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); } @@ -575,7 +575,7 @@ writechild(int fdp[3][2], const void *old, size_t n) } DPRINTF("Grandchild wait return %#x\n", status); } - closefd(fdp[0], 1); + closefd(fdp[STDIN_FILENO], 1); } static ssize_t @@ -639,17 +639,17 @@ uncompressbuf(int fd, size_t method, const unsigned char *old, 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); } @@ -681,13 +681,15 @@ uncompressbuf(int fd, size_t method, const unsigned char *old, 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; } @@ -705,9 +707,9 @@ uncompressbuf(int fd, size_t method, const unsigned char *old, (*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)); @@ -718,7 +720,7 @@ err: 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;