summaryrefslogtreecommitdiff
path: root/lib/OutPipe.cc
blob: c8d979c50e6e2d700a19adf83485b0866cc72306 (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
32
33
34
35
36
37
38
39
40
41
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "OutPipe.h"
#include "Input.h"
#include "gettext.h"

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

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

OutPipe::OutPipe(const OutPipe & o) : Handle(o), hooked(o.hooked) {
    p[0] = dup(o.p[0]);
    p[1] = GetHandle();
}

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

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

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

String OutPipe::GetName() {
    return (String(_("Output pipe to stdin (")) + (hooked ? "" : _("not ")) + _("hooked)"));
}