summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--generic/Handle.cpp1
-rw-r--r--generic/Input.cpp24
-rw-r--r--generic/Output.cpp29
-rw-r--r--includes/Handle.h2
-rw-r--r--includes/Input.h5
-rw-r--r--includes/Output.h10
6 files changed, 52 insertions, 19 deletions
diff --git a/generic/Handle.cpp b/generic/Handle.cpp
index d46fc22..6390a6d 100644
--- a/generic/Handle.cpp
+++ b/generic/Handle.cpp
@@ -247,6 +247,7 @@ ssize_t Handle::uwrite(const void * buf, size_t count) throw (GeneralException)
return err;
} else {
itell += count = ::write(h, buf, count);
+ return count;
}
}
diff --git a/generic/Input.cpp b/generic/Input.cpp
index 7106c8d..ffef9f0 100644
--- a/generic/Input.cpp
+++ b/generic/Input.cpp
@@ -41,6 +41,14 @@ bool Input::CanRead() {
return 1;
}
+bool Input::CanSeek() {
+ struct stat s;
+
+ fstat(GetHandle(), &s);
+
+ return S_ISREG(s.st_mode);
+}
+
String Input::GetName() {
return n;
}
@@ -53,14 +61,18 @@ time_t Input::GetModif() {
return date_modif;
}
-Stdin_t::Stdin_t() : Handle(dup(0)) { }
-
-bool Stdin_t::CanWrite() {
- return 0;
+off_t Input::seek(off_t offset, int whence) {
+ itell = lseek(GetHandle(), offset, whence);
+#ifdef PARANOID_SEEK
+ if (itell != lseek(GetHandle(), 0, SEEK_CUR)) {
+ }
+#endif
}
-bool Stdin_t::CanRead() {
- return 1;
+Stdin_t::Stdin_t() { }
+
+bool Stdin_t::CanSeek() {
+ return 0;
}
String Stdin_t::GetName() {
diff --git a/generic/Output.cpp b/generic/Output.cpp
index dbc1892..aace79c 100644
--- a/generic/Output.cpp
+++ b/generic/Output.cpp
@@ -19,6 +19,15 @@ Output::Output(String no, int trunc) throw (GeneralException) :
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) {
@@ -32,17 +41,21 @@ bool Output::CanRead() {
return 0;
}
+bool Output::CanSeek() {
+ struct stat s;
+
+ fstat(GetHandle(), &s);
+
+ return S_ISREG(s.st_mode);
+}
+
String Output::GetName() {
return n;
}
-Stdout_t::Stdout_t() : Handle(dup(1)) {}
-
-bool Stdout_t::CanWrite() {
- return 1;
-}
+Stdout_t::Stdout_t() {}
-bool Stdout_t::CanRead() {
+bool Stdout_t::CanSeek() {
return 0;
}
@@ -60,6 +73,10 @@ bool Stderr_t::CanRead() {
return 0;
}
+bool Stderr_t::CanSeek() {
+ return 0;
+}
+
String Stderr_t::GetName() {
return "Stderr";
}
diff --git a/includes/Handle.h b/includes/Handle.h
index fdaea2c..967e221 100644
--- a/includes/Handle.h
+++ b/includes/Handle.h
@@ -35,6 +35,7 @@ class Handle : public Base {
virtual void SetZ(int) throw (GeneralException);
protected:
Handle(int h);
+ off_t itell;
private:
ssize_t uwrite(const void *, size_t) throw (GeneralException);
ssize_t uread(void *, size_t);
@@ -42,7 +43,6 @@ class Handle : public Base {
bool closed, nonblock;
gzFile zfile;
int z;
- off_t itell;
};
Handle & operator<<(Handle &, const String &);
diff --git a/includes/Input.h b/includes/Input.h
index f8cf9be..8741ebc 100644
--- a/includes/Input.h
+++ b/includes/Input.h
@@ -27,12 +27,11 @@ class Input : public Handle {
time_t date_modif;
};
-class Stdin_t : public Handle {
+class Stdin_t : public Input {
public:
Stdin_t();
virtual ~Stdin_t() {}
- virtual bool CanWrite();
- virtual bool CanRead();
+ virtual bool CanSeek();
virtual String GetName();
};
diff --git a/includes/Output.h b/includes/Output.h
index ef6806c..b7c8fb8 100644
--- a/includes/Output.h
+++ b/includes/Output.h
@@ -2,6 +2,8 @@
#define __OUTPUT_H__
#ifdef __cplusplus
+#include <sys/types.h>
+#include <time.h>
#include <String.h>
#include <Handle.h>
@@ -19,14 +21,15 @@ class Output : public Handle {
protected:
String n;
+ off_t size;
+ time_t date_modif;
};
-class Stdout_t : public Handle {
+class Stdout_t : public Output {
public:
Stdout_t();
virtual ~Stdout_t() {}
- virtual bool CanWrite();
- virtual bool CanRead();
+ virtual bool CanSeek();
virtual String GetName();
};
@@ -36,6 +39,7 @@ class Stderr_t : public Handle {
virtual ~Stderr_t() {}
virtual bool CanWrite();
virtual bool CanRead();
+ virtual bool CanSeek();
virtual String GetName();
};