summaryrefslogtreecommitdiff
path: root/lib/Output.cc
blob: 75bb437b3464d09fe8ee973ec44266859d8efbb2 (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
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
		       
#include "Output.h"
#include "Exceptions.h"
#include "config.h"

Output::Output(String no, int trunc = 1) throw (IOGeneral) :
    Handle(no.strlen() ? open(no.to_charp(), O_WRONLY | O_CREAT | (trunc ? O_TRUNC : O_APPEND)) : 1),
    n(no) {
    if (GetHandle() < 0) {
	throw IOGeneral(String("Error opening file") + no + " for writing: " + strerror(errno));
    }
}

bool Output::CanWrite() {
    return 1;
}

bool Output::CanRead() {
    return 0;
}

String Output::GetName() {
    return n;
}