From 7dbea04337d74ec8e6953b3ddf4619de01781d3b Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sun, 1 May 2011 19:16:18 -0700 Subject: [PATCH] make output capturing functions more robust --- test/laketest.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/laketest.c b/test/laketest.c index e44e268..9d109a7 100644 --- a/test/laketest.c +++ b/test/laketest.c @@ -14,8 +14,13 @@ #include #include "laketest.h" +static int captured = 0; + static void capture_output(void) { + if (captured) return; + captured = 1; + int fd = open("./tmp", O_WRONLY); close(2); int newfd = dup(fd); @@ -29,6 +34,9 @@ static void capture_output(void) void restore_output(void) { + if (!captured) return; + captured = 0; + freopen("/dev/tty", "a", stdout); freopen("/dev/tty", "a", stderr); unlink("./tmp");