16 typedef union wait wait_arg
;
21 #include "../stdio/loc_incl.h"
25 int _dup2(int oldd
, int newd
); /* not present in System 5 */
26 int _execl(const char *name
, const char *_arg
, ... );
28 int _pipe(int fildes
[2]);
29 pid_t
_wait(wait_arg
*status
);
30 void _exit(int status
);
33 static int pids
[OPEN_MAX
];
41 int Xtype
= *type
== 'r' ? 0 : *type
== 'w' ? 1 : 2;
46 (pid
= _fork()) < 0) return 0;
52 for (p
= pids
; p
< &pids
[OPEN_MAX
]; p
++) {
53 if (*p
) _close((int)(p
- pids
));
56 _dup2(piped
[!Xtype
], !Xtype
);
57 _close(piped
[!Xtype
]);
58 _execl("/bin/sh", "sh", "-c", command
, (char *) 0);
59 _exit(127); /* like system() ??? */
62 pids
[piped
[Xtype
]] = pid
;
63 _close(piped
[!Xtype
]);
64 return fdopen(piped
[Xtype
], type
);
68 #define ret_val status.w_status
70 #define ret_val status
77 int fd
= fileno(stream
);
82 void (*intsave
)(int) = signal(SIGINT
, SIG_IGN
);
83 void (*quitsave
)(int) = signal(SIGQUIT
, SIG_IGN
);
85 void (*intsave
)() = signal(SIGINT
, SIG_IGN
);
86 void (*quitsave
)() = signal(SIGQUIT
, SIG_IGN
);
89 while ((wret
= _wait(&status
)) != -1) {
90 if (wret
== pids
[fd
]) break;
92 if (wret
== -1) ret_val
= -1;
93 signal(SIGINT
, intsave
);
94 signal(SIGQUIT
, quitsave
);
100 int _dup(int fildes
);
109 /* ignore the error on the close() */
110 tmp
= errno
; (void) _close(newd
); errno
= tmp
;
111 while ((fd
= _dup(oldd
)) != newd
) {