summaryrefslogtreecommitdiff
path: root/generic/Output.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'generic/Output.cpp')
-rw-r--r--generic/Output.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/generic/Output.cpp b/generic/Output.cpp
new file mode 100644
index 0000000..dbc1892
--- /dev/null
+++ b/generic/Output.cpp
@@ -0,0 +1,68 @@
+#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"
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#else
+#define _(x) x
+#endif
+
+Output::Output(String no, int trunc) throw (GeneralException) :
+ Handle(no.strlen() ? open(no.to_charp(), O_WRONLY | O_CREAT | (trunc ? O_TRUNC : O_APPEND), 00666) : dup(1)),
+ n(no) {
+ if (GetHandle() < 0) {
+ throw IOGeneral(String(_("Error opening file ")) + no + _(" for writing: ") + strerror(errno));
+ }
+}
+
+Output::Output(const Output & o) : Handle(o), n(o.n) {
+}
+
+bool Output::CanWrite() {
+ return 1;
+}
+
+bool Output::CanRead() {
+ return 0;
+}
+
+String Output::GetName() {
+ return n;
+}
+
+Stdout_t::Stdout_t() : Handle(dup(1)) {}
+
+bool Stdout_t::CanWrite() {
+ return 1;
+}
+
+bool Stdout_t::CanRead() {
+ return 0;
+}
+
+String Stdout_t::GetName() {
+ return "Stdout";
+}
+
+Stderr_t::Stderr_t() : Handle(dup(2)) {}
+
+bool Stderr_t::CanWrite() {
+ return 1;
+}
+
+bool Stderr_t::CanRead() {
+ return 0;
+}
+
+String Stderr_t::GetName() {
+ return "Stderr";
+}
+
+Stdout_t Stdout;
+Stderr_t Stderr;