summaryrefslogtreecommitdiff
path: root/lib/Output.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Output.cc')
-rw-r--r--lib/Output.cc66
1 files changed, 51 insertions, 15 deletions
diff --git a/lib/Output.cc b/lib/Output.cc
index e0a37ba..1ebf6db 100644
--- a/lib/Output.cc
+++ b/lib/Output.cc
@@ -5,58 +5,94 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
#include "Output.h"
#include "Exceptions.h"
-#include "config.h"
+#include "gettext.h"
-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)),
+Output::Output(String no, int create, int trunc) throw (GeneralException) :
+ Handle(no.strlen() ? open(no.to_charp(), O_WRONLY | (O_CREAT * (create ? 1 : 0)) | (O_TRUNC * (trunc ? 1 : 0))
+#if defined __linux__ || defined __CYGWIN32__
+, 00666
+#endif
+) : dup(1)),
n(no) {
if (GetHandle() < 0) {
throw IOGeneral(String(_("Error opening file ")) + no + _(" for writing: ") + strerror(errno));
}
+
+ size = lseek(GetHandle(), 0, SEEK_END);
+ lseek(GetHandle(), 0, SEEK_SET);
+
+ struct stat s;
+
+ fstat(GetHandle(), &s);
+
+ date_modif = s.st_mtime;
}
Output::Output(const Output & o) : Handle(o), n(o.n) {
}
-bool Output::CanWrite() {
+bool Output::CanWrite() const {
return 1;
}
-bool Output::CanRead() {
+bool Output::CanRead() const {
return 0;
}
-String Output::GetName() {
- return n;
+bool Output::CanSeek() const {
+ struct stat s;
+
+ fstat(GetHandle(), &s);
+
+ return S_ISREG(s.st_mode);
}
-Stdout_t::Stdout_t() : Handle(dup(1)) {}
+off_t Output::seek(off_t offset, int whence) throw (GeneralException) {
+ if ((itell = lseek(GetHandle(), offset, whence)) < 0) {
+ throw IOGeneral(String(_("Error seeking file ")) + n + _(": ") + strerror(errno));
+ }
+#ifdef PARANOID_SEEK
+ if (itell != lseek(GetHandle(), 0, SEEK_CUR)) {
+ throw IOGeneral(String(_("Error seeking file ")) + n + _(": the position does not match"));
+ }
+#endif
+ return itell;
+}
-bool Stdout_t::CanWrite() {
- return 1;
+String Output::GetName() const {
+ return n;
}
-bool Stdout_t::CanRead() {
+Stdout_t::Stdout_t() {}
+
+bool Stdout_t::CanSeek() const {
return 0;
}
-String Stdout_t::GetName() {
+String Stdout_t::GetName() const {
return "Stdout";
}
Stderr_t::Stderr_t() : Handle(dup(2)) {}
-bool Stderr_t::CanWrite() {
+bool Stderr_t::CanWrite() const {
return 1;
}
-bool Stderr_t::CanRead() {
+bool Stderr_t::CanRead() const {
+ return 0;
+}
+
+bool Stderr_t::CanSeek() const {
return 0;
}
-String Stderr_t::GetName() {
+String Stderr_t::GetName() const {
return "Stderr";
}