FreeBSD/contrib/blacklist/port/popenve.c
/*
 * pclose --
 *	Pclose returns -1 if stream is not associated with a `popened' command,
 *	if already `pclosed', or waitpid returns an error.
 */
pclose
Pclose returns -1 if stream is not associated with a `popened' command,
if already `pclosed', or waitpid returns an error.
pclose Pclose returns - 1 if stream is not associated with a ` popened ' command if already ` pclosed ' or waitpid returns an error .
int
pcloseve(FILE *iop)
{
	struct pid *cur, *last;
	int pstat;
	pid_t pid;
#ifdef _REENTRANT
	rwlock_wrlock(&pidlist_lock);
#endif
	for (last = NULL, cur = pidlist; cur; last = cur, cur = cur->next)
		if (cur->fp == iop)
			break;
	if (cur == NULL) {
#ifdef _REENTRANT
		(void)rwlock_unlock(&pidlist_lock);
#endif
		errno = ESRCH;
		return -1;
	}
	(void)fclose(iop);
	if (last == NULL)
		pidlist = cur->next;
	else
		last->next = cur->next;
#ifdef _REENTRANT
	(void)rwlock_unlock(&pidlist_lock);
#endif
	do {
		pid = waitpid(cur->pid, &pstat, 0);
	} while (pid == -1 && errno == EINTR);
	free(cur);
	return pid == -1 ? -1 : pstat;
}
int pcloseve ( FILE * iop ) { struct pid * cur , * last ; int pstat ; pid_t pid ; #ifdef _REENTRANT rwlock_wrlock ( & pidlist_lock ) ; #endif for ( last = NULL , cur = pidlist ; cur ; last = cur , cur = cur -> next ) if ( cur -> fp == iop ) break ; if ( cur == NULL ) { #ifdef _REENTRANT ( void ) rwlock_unlock ( & pidlist_lock ) ; #endif errno = ESRCH ; return -1 ; } ( void ) fclose ( iop ) ; if ( last == NULL ) pidlist = cur -> next ; else last -> next = cur -> next ; #ifdef _REENTRANT ( void ) rwlock_unlock ( & pidlist_lock ) ; #endif do { pid = waitpid ( cur -> pid , & pstat , 0 ) ; } while ( pid == -1 && errno == EINTR ) ; free ( cur ) ; return pid == -1 ? -1 : pstat ; }
pclose
      Pclose returns -1 if stream is not associated with a `popened' command,
      if already `pclosed', or waitpid returns an error.
pclose Pclose returns - 1 if stream is not associated with a ` popened ' command if already ` pclosed ' or waitpid returns an error .
/* Find the appropriate file pointer. */ /* Remove the entry from the linked list. */