mirror of
https://github.com/samsonjs/lake.git
synced 2026-03-25 08:55:49 +00:00
make output capturing functions more robust
This commit is contained in:
parent
81aba19868
commit
7dbea04337
1 changed files with 8 additions and 0 deletions
|
|
@ -14,8 +14,13 @@
|
|||
#include <unistd.h>
|
||||
#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");
|
||||
|
|
|
|||
Loading…
Reference in a new issue