summaryrefslogtreecommitdiff
path: root/lib/OutPipe.cc
blob: 456a5bd66d94b25f93d599002f01f955b29f693c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "OutPipe.h"
#include "Input.h"

OutPipe::OutPipe() : Handle(pipe(p, 1)), hooked(0) { }

OutPipe::~OutPipe() {
    if (hooked) {
	::close(0);
	dup(Stdin.GetHandle());
    }
}

void OutPipe::Hook() {
    if (!hooked) {
	hooked = 1;
	::close(0);
	dup(p[0]);
    }
}

bool OutPipe::CanWrite() {
    return false;
}

bool OutPipe::CanRead() {
    return true;
}

String OutPipe::GetName() {
    return (String("Input pipe from stdout (") + (hooked ? "" : "not ") + "hooked)");
}