X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/5b2d69cc5b852ab2e884fdf76f78d2ee6ff3ff7f..31d3e510949227d55ed7e87c793b3ec571dffec3:/lib/subpipe.c?ds=inline diff --git a/lib/subpipe.c b/lib/subpipe.c index 7bb520a8..a0cfc811 100644 --- a/lib/subpipe.c +++ b/lib/subpipe.c @@ -1,11 +1,11 @@ /* Subprocesses with pipes. - Copyright (C) 2002 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 + 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 - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -13,44 +13,25 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + along with this program. If not, see . */ /* Written by Paul Eggert and Florian Krohm . */ -#if HAVE_CONFIG_H -# include -#endif +#include -#if HAVE_SYS_TYPES_H -# include -#endif +#include "subpipe.h" #include -#ifndef errno -extern int errno; -#endif #include #if ! defined SIGCHLD && defined SIGCLD # define SIGCHLD SIGCLD #endif -#if HAVE_STDLIB_H -# include -#endif -/* The following test is to work around the gross typo in - systems like Sony NEWS-OS Release 4.0C, whereby EXIT_FAILURE - is defined to 0, not 1. */ -#if ! EXIT_FAILURE -# undef EXIT_FAILURE -# define EXIT_FAILURE 1 -#endif +#include -#if HAVE_UNISTD_H -# include -#endif +#include #ifndef STDIN_FILENO # define STDIN_FILENO 0 #endif @@ -58,9 +39,7 @@ extern int errno; # 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 @@ -82,11 +61,22 @@ extern int errno; #endif #include "error.h" +#include "unistd-safer.h" #include "gettext.h" #define _(Msgid) gettext (Msgid) -#include "subpipe.h" +#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. */ @@ -115,21 +105,14 @@ 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) - error (EXIT_FAILURE, errno, "pipe"); - to_in_fd = pipe_fd[0]; - to_out_fd = pipe_fd[1]; - - if (pipe (pipe_fd) != 0) + if (pipe_safer (child_fd) != 0 || pipe_safer (pipe_fd) != 0) error (EXIT_FAILURE, errno, "pipe"); - from_in_fd = pipe_fd[0]; - from_out_fd = pipe_fd[1]; + fd[0] = child_fd[1]; + fd[1] = pipe_fd[0]; + child_fd[1] = pipe_fd[1]; pid = vfork (); if (pid < 0) @@ -138,33 +121,24 @@ create_subpipe (char const * const *argv, int fd[2]) if (! pid) { /* Child. */ - close (to_out_fd); - close (from_in_fd); - - if (to_in_fd != STDIN_FILENO) - { - dup2 (to_in_fd, STDIN_FILENO); - close (to_in_fd); - } - if (from_out_fd != STDOUT_FILENO) - { - 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 for execvp. */ execvp (argv[0], (char **) argv); - + _exit (errno == ENOENT ? 127 : 126); } /* 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; } @@ -194,3 +168,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) +{ +}