Deleted Added
full compact
38c38
< static char sccsid[] = "@(#)popen.c 8.1 (Berkeley) 6/4/93";
---
> static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 5/3/95";
42a43
> #include <sys/socket.h>
59,61c60,61
< popen(program, type)
< const char *program;
< const char *type;
---
> popen(command, type)
> const char *command, *type;
65c65
< int pdes[2], pid;
---
> int pdes[2], pid, twoway;
67c67,79
< if ( (*type != 'r' && *type != 'w') || type[1])
---
> /*
> * Lite2 introduced two-way popen() pipes using socketpair().
> * FreeBSD's pipe() is bidirectional, so we use that.
> */
> if (strchr(type, '+')) {
> twoway = 1;
> type = "r+";
> } else {
> twoway = 0;
> if (*type != 'r' && *type != 'w' || type[1])
> return (NULL);
> }
> if (pipe(pdes) < 0)
73,77d84
< if (pipe(pdes) < 0) {
< free(cur);
< return (NULL);
< }
<
89a97
> pdes[1] = STDOUT_FILENO;
91a100,101
> if (twoway && (pdes[1] != STDIN_FILENO))
> (void)dup2(pdes[1], STDIN_FILENO);
99c109
< execl(_PATH_BSHELL, "sh", "-c", program, NULL);
---
> execl(_PATH_BSHELL, "sh", "-c", command, NULL);
133c143
< union wait pstat;
---
> int pstat;
136,137d145
< (void)fclose(iop);
<
145,146c153,154
< /* Get the status of the process. */
< omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP));
---
> (void)fclose(iop);
>
148c156
< pid = waitpid(cur->pid, (int *) &pstat, 0);
---
> pid = waitpid(cur->pid, &pstat, 0);
150d157
< (void)sigsetmask(omask);
159c166
< return (pid == -1 ? -1 : pstat.w_status);
---
> return (pid == -1 ? -1 : pstat);