X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/4d1801f1a888fc5687ae103fb76935ef0d24cbaf..d6b771c345a389742bfcd73ff13dac1d4f016c88:/lib/subpipe.c diff --git a/lib/subpipe.c b/lib/subpipe.c index cfc94262..646aa8ec 100644 --- a/lib/subpipe.c +++ b/lib/subpipe.c @@ -1,6 +1,6 @@ /* Subprocesses with pipes. - Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,7 +19,7 @@ /* Written by Paul Eggert and Florian Krohm . */ -#if HAVE_CONFIG_H +#ifdef HAVE_CONFIG_H # include #endif @@ -44,9 +44,7 @@ # define STDOUT_FILENO 1 #endif #if ! HAVE_DUP2 && ! defined dup2 -# if HAVE_FCNTL_H -# include -# endif +# include # define dup2(f, t) (close (t), fcntl (f, F_DUPFD, t)) #endif @@ -73,6 +71,18 @@ #include "gettext.h" #define _(Msgid) gettext (Msgid) +#ifndef __attribute__ +/* This feature is available in gcc versions 2.5 and later. */ +# if ! defined __GNUC__ || __GNUC__ < 2 || \ +(__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ +# define __attribute__(Spec) /* empty */ +# endif +#endif + +#ifndef ATTRIBUTE_UNUSED +# define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +#endif + /* Initialize this module. */ @@ -100,40 +110,32 @@ 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) - error (EXIT_FAILURE, errno, "pipe"); - - /* Save the local variables in the parent now, in case vfork - clobbers them. */ - fd[0] = to_out_fd; - fd[1] = from_in_fd; - pipe_fd[0] = to_in_fd; - pipe_fd[1] = from_out_fd; + || (fd[1] = fd_safer (pipe_fd[0])) < 0 + || (child_fd[1] = fd_safer (pipe_fd[1])) < 0) + error (EXIT_FAILURE, errno, + "pipe"); pid = vfork (); if (pid < 0) - error (EXIT_FAILURE, errno, "fork"); + error (EXIT_FAILURE, errno, + "fork"); 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 @@ -144,8 +146,8 @@ create_subpipe (char const * const *argv, int fd[2]) } /* Parent. */ - close (pipe_fd[0]); - close (pipe_fd[1]); + close (child_fd[0]); + close (child_fd[1]); return pid; } @@ -158,7 +160,8 @@ 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; @@ -175,3 +178,9 @@ reap_subpipe (pid_t pid, char const *program) } #endif } + +void +end_of_output_subpipe (pid_t pid ATTRIBUTE_UNUSED, + int fd[2] ATTRIBUTE_UNUSED) +{ +}