version 1.28, 2003/09/15 22:30:38 |
version 1.29, 2006/10/15 16:12:02 |
Line 79 static rwlock_t pidlist_lock = RWLOCK_IN |
|
Line 79 static rwlock_t pidlist_lock = RWLOCK_IN |
|
#endif |
#endif |
|
|
FILE * |
FILE * |
popen(command, type) |
popen(const char *command, const char *type) |
const char *command, *type; |
|
{ |
{ |
struct pid *cur, *old; |
struct pid *cur, *old; |
FILE *iop; |
FILE *iop; |
int pdes[2], pid, twoway, serrno; |
const char * volatile xtype = type; |
|
int pdes[2], pid, serrno; |
|
volatile int twoway; |
|
|
_DIAGASSERT(command != NULL); |
_DIAGASSERT(command != NULL); |
_DIAGASSERT(type != NULL); |
_DIAGASSERT(xtype != NULL); |
|
|
#ifdef __GNUC__ |
if (strchr(xtype, '+')) { |
/* This outrageous construct just to shut up a GCC warning. */ |
|
(void) &cur; (void) &twoway; (void) &type; |
|
#endif |
|
|
|
if (strchr(type, '+')) { |
|
twoway = 1; |
twoway = 1; |
type = "r+"; |
type = "r+"; |
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, pdes) < 0) |
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, pdes) < 0) |
return (NULL); |
return (NULL); |
} else { |
} else { |
twoway = 0; |
twoway = 0; |
if ((*type != 'r' && *type != 'w') || type[1] || |
if ((*xtype != 'r' && *xtype != 'w') || xtype[1] || |
(pipe(pdes) < 0)) { |
(pipe(pdes) < 0)) { |
errno = EINVAL; |
errno = EINVAL; |
return (NULL); |
return (NULL); |
Line 139 popen(command, type) |
|
Line 135 popen(command, type) |
|
close(fileno(old->fp)); /* don't allow a flush */ |
close(fileno(old->fp)); /* don't allow a flush */ |
#endif |
#endif |
|
|
if (*type == 'r') { |
if (*xtype == 'r') { |
(void)close(pdes[0]); |
(void)close(pdes[0]); |
if (pdes[1] != STDOUT_FILENO) { |
if (pdes[1] != STDOUT_FILENO) { |
(void)dup2(pdes[1], STDOUT_FILENO); |
(void)dup2(pdes[1], STDOUT_FILENO); |
Line 162 popen(command, type) |
|
Line 158 popen(command, type) |
|
rwlock_unlock(&__environ_lock); |
rwlock_unlock(&__environ_lock); |
|
|
/* Parent; assume fdopen can't fail. */ |
/* Parent; assume fdopen can't fail. */ |
if (*type == 'r') { |
if (*xtype == 'r') { |
iop = fdopen(pdes[0], type); |
iop = fdopen(pdes[0], xtype); |
#ifdef _REENTRANT |
#ifdef _REENTRANT |
cur->fd = pdes[0]; |
cur->fd = pdes[0]; |
#endif |
#endif |
(void)close(pdes[1]); |
(void)close(pdes[1]); |
} else { |
} else { |
iop = fdopen(pdes[1], type); |
iop = fdopen(pdes[1], xtype); |
#ifdef _REENTRANT |
#ifdef _REENTRANT |
cur->fd = pdes[1]; |
cur->fd = pdes[1]; |
#endif |
#endif |