X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/3ea5f0ec817fe9d8a7384334f7d537dce66af0f4..26a69b31fa0e2c84cbc0a38f198fb456a42e0424:/lib/subpipe.c?ds=sidebyside diff --git a/lib/subpipe.c b/lib/subpipe.c index f2090717..10b62f2c 100644 --- a/lib/subpipe.c +++ b/lib/subpipe.c @@ -100,18 +100,15 @@ pid_t create_subpipe (char const * const *argv, int fd[2]) { int pipe_fd[2]; - int from_in_fd; - int from_out_fd; - int to_in_fd; - int to_out_fd; + int child_fd[2]; pid_t pid; - if (pipe (pipe_fd) != 0 - || (to_in_fd = fd_safer (pipe_fd[0])) < 0 - || (to_out_fd = fd_safer (pipe_fd[1])) < 0 + if (pipe (child_fd) != 0 + || (child_fd[0] = fd_safer (child_fd[0])) < 0 + || (fd[0] = fd_safer (child_fd[1])) < 0 || pipe (pipe_fd) != 0 - || (from_in_fd = fd_safer (pipe_fd[0])) < 0 - || (from_out_fd = fd_safer (pipe_fd[1])) < 0) + || (fd[1] = fd_safer (pipe_fd[0])) < 0 + || (child_fd[1] = fd_safer (pipe_fd[1])) < 0) error (EXIT_FAILURE, errno, "pipe"); pid = vfork (); @@ -121,12 +118,12 @@ create_subpipe (char const * const *argv, int fd[2]) if (! pid) { /* Child. */ - close (to_out_fd); - close (from_in_fd); - dup2 (to_in_fd, STDIN_FILENO); - close (to_in_fd); - dup2 (from_out_fd, STDOUT_FILENO); - close (from_out_fd); + close (fd[0]); + close (fd[1]); + dup2 (child_fd[0], STDIN_FILENO); + close (child_fd[0]); + dup2 (child_fd[1], STDOUT_FILENO); + close (child_fd[1]); /* The cast to (char **) rather than (char * const *) is needed for portability to older hosts with a nonstandard prototype @@ -137,10 +134,8 @@ create_subpipe (char const * const *argv, int fd[2]) } /* Parent. */ - close (to_in_fd); - close (from_out_fd); - fd[0] = to_out_fd; - fd[1] = from_in_fd; + close (child_fd[0]); + close (child_fd[1]); return pid; }