--- libelwix/src/pio.c 2013/12/05 15:04:20 1.1.2.2 +++ libelwix/src/pio.c 2013/12/05 15:13:58 1.1.2.3 @@ -26,6 +26,9 @@ e_popen(const char *command, const char *type, pid_t * int pdes[2], pid, twoway, cloexec; char *argv[4]; + if (!command || !type) + return NULL; + cloexec = strchr(type, 'e') != NULL; /* * Lite2 introduced two-way popen() pipes using _socketpair(). @@ -140,6 +143,9 @@ e_pclose(FILE *iop) int pstat; pid_t pid; + if (!iop) + return -1; + /* * Find the appropriate file pointer and remove it from the list. */ @@ -168,4 +174,27 @@ e_pclose(FILE *iop) e_free(cur); return (pid == -1 ? -1 : pstat); +} + +/* + * pio_pgetpid() - Get tagPIOPID structure from file handle + * + * @iop = popen handle + * return: NULL error or !=NULL tagPIOPID structure + */ +struct tagPIOPID * +pio_pgetpid(FILE * __restrict iop) +{ + struct tagPIOPID *p; + + if (!iop) + return NULL; + + THREAD_LOCK(); + SLIST_FOREACH(p, &pio_pidlist, next) + if (p->fp == iop) + break; + THREAD_UNLOCK(); + + return p; }