X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/c66dfaddf449920bea03c0aa3b55467e2f21c98e..89eb3c76532c0c5f9f3207474c55c300a239fce8:/lib/subpipe.c diff --git a/lib/subpipe.c b/lib/subpipe.c index 36e66600..b9702d2b 100644 --- a/lib/subpipe.c +++ b/lib/subpipe.c @@ -19,9 +19,7 @@ /* Written by Paul Eggert and Florian Krohm . */ -#if HAVE_CONFIG_H -# include -#endif +#include #include "subpipe.h" @@ -34,9 +32,7 @@ #include -#if HAVE_UNISTD_H -# include -#endif +#include #ifndef STDIN_FILENO # define STDIN_FILENO 0 #endif @@ -73,7 +69,7 @@ #ifndef __attribute__ /* This feature is available in gcc versions 2.5 and later. */ -# if !defined (__GNUC__) || __GNUC__ < 2 || \ +# if ! defined __GNUC__ || __GNUC__ < 2 || \ (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ # define __attribute__(Spec) /* empty */ # endif @@ -113,19 +109,15 @@ create_subpipe (char const * const *argv, int fd[2]) int child_fd[2]; pid_t pid; - 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 - || (fd[1] = fd_safer (pipe_fd[0])) < 0 - || (child_fd[1] = fd_safer (pipe_fd[1])) < 0) - error (EXIT_FAILURE, errno, - "pipe"); + if (pipe_safer (child_fd) != 0 || pipe_safer (pipe_fd) != 0) + error (EXIT_FAILURE, errno, "pipe"); + fd[0] = child_fd[1]; + fd[1] = pipe_fd[0]; + child_fd[1] = pipe_fd[1]; pid = vfork (); if (pid < 0) - error (EXIT_FAILURE, errno, - "fork"); + error (EXIT_FAILURE, errno, "fork"); if (! pid) { @@ -160,8 +152,7 @@ reap_subpipe (pid_t pid, char const *program) #if HAVE_WAITPID || defined waitpid int wstatus; if (waitpid (pid, &wstatus, 0) < 0) - error (EXIT_FAILURE, errno, - "waitpid"); + error (EXIT_FAILURE, errno, "waitpid"); else { int status = WIFEXITED (wstatus) ? WEXITSTATUS (wstatus) : -1;