mirror of
https://github.com/samsonjs/lake.git
synced 2026-04-27 14:57:43 +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 <unistd.h>
|
||||||
#include "laketest.h"
|
#include "laketest.h"
|
||||||
|
|
||||||
|
static int captured = 0;
|
||||||
|
|
||||||
static void capture_output(void)
|
static void capture_output(void)
|
||||||
{
|
{
|
||||||
|
if (captured) return;
|
||||||
|
captured = 1;
|
||||||
|
|
||||||
int fd = open("./tmp", O_WRONLY);
|
int fd = open("./tmp", O_WRONLY);
|
||||||
close(2);
|
close(2);
|
||||||
int newfd = dup(fd);
|
int newfd = dup(fd);
|
||||||
|
|
@ -29,6 +34,9 @@ static void capture_output(void)
|
||||||
|
|
||||||
void restore_output(void)
|
void restore_output(void)
|
||||||
{
|
{
|
||||||
|
if (!captured) return;
|
||||||
|
captured = 0;
|
||||||
|
|
||||||
freopen("/dev/tty", "a", stdout);
|
freopen("/dev/tty", "a", stdout);
|
||||||
freopen("/dev/tty", "a", stderr);
|
freopen("/dev/tty", "a", stderr);
|
||||||
unlink("./tmp");
|
unlink("./tmp");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue