* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that this notice is preserved and that due credit is given
* to the University of California at Berkeley. The name of the University
* may not be used to endorse or promote products derived from this
* software without specific prior written permission. This software
* is provided ``as is'' without express or implied warranty.
static char sccsid
[] = "@(#)popen.c 5.8 (Berkeley) %G%";
#define tst(a,b) (*mode == 'r'? (b) : (a))
static int popen_pid
[20];
register int myside
, hisside
;
myside
= tst(p
[WTR
], p
[RDR
]);
hisside
= tst(p
[RDR
], p
[WTR
]);
if ((pid
= vfork()) == 0) {
/* myside and hisside reverse roles in child */
dup2(hisside
, tst(0, 1));
(void) getrawlist(cmd
, argv
, MAXARGC
);
fprintf(stderr
, "Cannot execute %s\n", argv
[0]);
return fdopen(myside
, mode
);
omask
= sigblock(sigmask(SIGINT
)|sigmask(SIGQUIT
)|sigmask(SIGHUP
));
while((r
= wait(&status
)) != popen_pid
[f
] && r
!= -1 && errno
!= EINTR
)
return (status
.w_status
);