summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPedro Martelletto <pedro@cvs.openbsd.org>2004-08-06 18:31:12 +0000
committerPedro Martelletto <pedro@cvs.openbsd.org>2004-08-06 18:31:12 +0000
commitc1b43a27911f6445ae60c9df4291c33241bb2dab (patch)
tree2ac3b3ccd75d292126d1270700a6d36e98720421 /lib
parent77a9f7d6be843590c1ab60e70ed6078a992b37f3 (diff)
in pclose(), only fclose() a stream if it has been opened by popen(), so
that applications doing: 'ok = (pclose(f) != -1) || (fclose(f) == 0)' can work safely and avoid a double-close of a stream. ok millert@
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/popen.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/libc/gen/popen.c b/lib/libc/gen/popen.c
index a7f848f8ac1..b2a825524ef 100644
--- a/lib/libc/gen/popen.c
+++ b/lib/libc/gen/popen.c
@@ -31,7 +31,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: popen.c,v 1.14 2004/05/18 02:05:52 jfb Exp $";
+static char rcsid[] = "$OpenBSD: popen.c,v 1.15 2004/08/06 18:31:11 pedro Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -145,15 +145,16 @@ pclose(FILE *iop)
int pstat;
pid_t pid;
- (void)fclose(iop);
-
/* Find the appropriate file pointer. */
for (last = NULL, cur = pidlist; cur; last = cur, cur = cur->next)
if (cur->fp == iop)
break;
+
if (cur == NULL)
return (-1);
+ (void)fclose(iop);
+
do {
pid = waitpid(cur->pid, &pstat, 0);
} while (pid == -1 && errno == EINTR);