2 * fpopen.c --- unlike the libc popen, it directly executes the
3 * command instead of call out to the shell.
5 * Copyright Theodore Ts'o, 1996-1999.
7 * Permission to use this file is granted for any purposes, as long as
8 * this copyright statement is kept intact and the author is not held
9 * liable for any damages resulting from the use of this program.
11 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
12 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
13 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
14 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
15 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
16 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
17 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
18 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
19 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
21 * USE OF THIS SOFTWARE.
33 extern FILE *fpopen(const char *cmd, const char *mode);
35 FILE *fpopen(const char *cmd, const char *mode)
41 int do_stdin, do_stderr = 0;
67 * Create the argv vector....
69 buf = malloc(strlen(cmd)+1);
95 /* Fork and execute the correct program. */
96 if ((pid = fork()) < 0) {
99 } else if (pid == 0) {
109 (void) execvp(prog, argv);
113 return fdopen(do_stdin ? fds[1] : fds[0], mode);