summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-10-10 20:31:41 -0700
committerPixel <pixel@nobis-crew.org>2011-10-10 20:31:41 -0700
commit8ae349b49e16064e4d84b6cfd256e3ca7fb0cd60 (patch)
tree8b01b3ab2097d838771d43c79b92920661ffd37c /src
parent965148b43b5b859934b7af2e8447ba1026a43a19 (diff)
Adding the 'stats' call to Input.
Also fixing a bug with the Printer - va_args are vicious.
Diffstat (limited to 'src')
-rw-r--r--src/Handle.cc2
-rw-r--r--src/Input.cc39
2 files changed, 39 insertions, 2 deletions
diff --git a/src/Handle.cc b/src/Handle.cc
index c9e3f57..dc4e257 100644
--- a/src/Handle.cc
+++ b/src/Handle.cc
@@ -51,6 +51,7 @@ bool Balau::Handle::canSeek() { return false; }
bool Balau::Handle::canRead() { return false; }
bool Balau::Handle::canWrite() { return false; }
off_t Balau::Handle::getSize() { return -1; }
+time_t Balau::Handle::getMTime() { return -1; }
ssize_t Balau::Handle::read(void * buf, size_t count) throw (GeneralException) {
if (canRead())
@@ -149,3 +150,4 @@ off_t Balau::SeekableHandle::wtell() throw (GeneralException) {
if (!canWrite())
return rtell();
}
+
diff --git a/src/Input.cc b/src/Input.cc
index 633a1a7..ea078dc 100644
--- a/src/Input.cc
+++ b/src/Input.cc
@@ -16,11 +16,28 @@ static int eioDone(eio_req * req) {
cbResults->result = req->result;
cbResults->errorno = req->errorno;
cbResults->evt.doSignal();
+ return 0;
}
-Balau::Input::Input(const char * fname) throw (GeneralException) : m_fd(-1) {
- cbResults_t cbResults;
+struct cbStatsResults_t {
+ Balau::Events::Custom evt;
+ int result, errorno;
+ EIO_STRUCT_STAT statdata;
+};
+
+static int eioStatsDone(eio_req * req) {
+ cbStatsResults_t * cbStatsResults = (cbStatsResults_t *) req->data;
+ cbStatsResults->result = req->result;
+ cbStatsResults->errorno = req->errorno;
+ cbStatsResults->statdata = *(EIO_STRUCT_STAT *) req->ptr2;
+ cbStatsResults->evt.doSignal();
+ return 0;
+}
+
+Balau::Input::Input(const char * fname) throw (GeneralException) : m_fd(-1), m_size(-1), m_mtime(-1) {
m_name.set("Input(%s)", fname);
+
+ cbResults_t cbResults;
eio_req * r = eio_open(fname, O_RDONLY, 0, 0, eioDone, &cbResults);
Assert(r != 0);
Task::yield(&cbResults.evt);
@@ -31,6 +48,16 @@ Balau::Input::Input(const char * fname) throw (GeneralException) : m_fd(-1) {
} else {
m_fd = cbResults.result;
}
+
+ cbStatsResults_t cbStatsResults;
+ r = eio_fstat(m_fd, 0, eioStatsDone, &cbStatsResults);
+ Assert(r != 0);
+ Task::yield(&cbStatsResults.evt);
+ Assert(cbStatsResults.evt.gotSignal());
+ if (cbStatsResults.result == 0) {
+ m_size = cbStatsResults.statdata.st_size;
+ m_mtime = cbStatsResults.statdata.st_mtime;
+ }
}
void Balau::Input::close() throw (GeneralException) {
@@ -58,3 +85,11 @@ bool Balau::Input::isClosed() {
const char * Balau::Input::getName() {
return m_name.to_charp();
}
+
+off_t Balau::Input::getSize() {
+ return m_size;
+}
+
+time_t Balau::Input::getMTime() {
+ return m_mtime;
+}