summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Buffer.cc14
-rw-r--r--lib/Input.cc11
-rw-r--r--lib/LuaHandle.cc32
-rw-r--r--lib/Output.cc11
4 files changed, 63 insertions, 5 deletions
diff --git a/lib/Buffer.cc b/lib/Buffer.cc
index 7def194..74e8cda 100644
--- a/lib/Buffer.cc
+++ b/lib/Buffer.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: Buffer.cc,v 1.29 2007-09-17 08:33:25 pixel Exp $ */
+/* $Id: Buffer.cc,v 1.30 2008-01-21 17:55:43 pixel Exp $ */
#include <string.h>
#ifdef HAVE_CONFIG_H
@@ -26,15 +26,25 @@
#include "Buffer.h"
#include "generic.h"
-Buffer::Buffer(bool _seekable) : Handle(-1), buffer(0), zero(0), realsiz(0), bufsiz(0), ptr(0), wptr(0), seekable(_seekable), got_eof(false) { }
+int Buffer::nb_buffer = 0;
+
+int Buffer::GetNbBuffer() {
+ return nb_buffer;
+}
+
+Buffer::Buffer(bool _seekable) : Handle(-1), buffer(0), zero(0), realsiz(0), bufsiz(0), ptr(0), wptr(0), seekable(_seekable), got_eof(false) {
+ nb_buffer++;
+}
Buffer::~Buffer() {
free(buffer);
+ nb_buffer--;
}
Buffer::Buffer(const Buffer & b) : Handle(-1), buffer(0), zero(b.zero), realsiz(b.realsiz), bufsiz(b.bufsiz), ptr(b.ptr), wptr(b.wptr), seekable(b.seekable), got_eof(b.got_eof) {
buffer = (Byte *) malloc(bufsiz);
memcpy(buffer, b.buffer, bufsiz);
+ nb_buffer++;
}
ssize_t Buffer::write(const void *buf, size_t count) throw (GeneralException) {
diff --git a/lib/Input.cc b/lib/Input.cc
index eab56e1..23bb55e 100644
--- a/lib/Input.cc
+++ b/lib/Input.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: Input.cc,v 1.53 2007-05-30 11:57:10 pixel Exp $ */
+/* $Id: Input.cc,v 1.54 2008-01-21 17:55:43 pixel Exp $ */
#include <stdio.h>
#include <string.h>
@@ -86,6 +86,12 @@ those 4 bytes.
static Input::openresults_t gresults;
+int Input::nb_input = 0;
+
+int Input::GetNbInput() {
+ return nb_input;
+}
+
Input::Input(const String & no) throw (GeneralException) :
Handle(no.strlen() ? wrapopen(no, &gresults) : dup(0)),
n(no) {
@@ -101,6 +107,8 @@ Input::Input(const String & no) throw (GeneralException) :
throw IOGeneral(String(_("Error opening file ")) + no + _(" for reading: ") + strerror(errno));
}
+ nb_input++;
+
results = gresults;
UNLOCK
@@ -140,6 +148,7 @@ Input::Input(const String & no) throw (GeneralException) :
}
Input::Input(const Input & i) : Handle(i), n(i.n), size(i.size), date_modif(i.date_modif) {
+ nb_input++;
}
bool Input::CanWrite() const {
diff --git a/lib/LuaHandle.cc b/lib/LuaHandle.cc
index a1e5ccb..7ff7143 100644
--- a/lib/LuaHandle.cc
+++ b/lib/LuaHandle.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: LuaHandle.cc,v 1.23 2008-01-21 17:19:07 pixel Exp $ */
+/* $Id: LuaHandle.cc,v 1.24 2008-01-21 17:55:43 pixel Exp $ */
#include "LuaHandle.h"
@@ -64,6 +64,9 @@ class sLuaHandle : public Base {
static int btell(lua_State * L);
static int exists(lua_State * L);
static int get_nb_handles(lua_State * L);
+ static int get_nb_input(lua_State * L);
+ static int get_nb_output(lua_State * L);
+ static int get_nb_buffer(lua_State * L);
private:
static int read(lua_State * L, int);
static int write(lua_State * L, int);
@@ -489,6 +492,30 @@ int sLuaHandle::get_nb_handles(lua_State * __L) {
return 1;
}
+int sLuaHandle::get_nb_input(lua_State * __L) {
+ Lua * L = Lua::find(__L);
+
+ L->push((lua_Number) Input::GetNbInput());
+
+ return 1;
+}
+
+int sLuaHandle::get_nb_output(lua_State * __L) {
+ Lua * L = Lua::find(__L);
+
+ L->push((lua_Number) Output::GetNbOutput());
+
+ return 1;
+}
+
+int sLuaHandle::get_nb_buffer(lua_State * __L) {
+ Lua * L = Lua::find(__L);
+
+ L->push((lua_Number) Buffer::GetNbBuffer());
+
+ return 1;
+}
+
int sLuaHandle::seek(lua_State * __L) {
Lua * L = Lua::find(__L);
int n = L->gettop();
@@ -702,4 +729,7 @@ void LuaHandle::pushconstruct(Lua * L) {
L->settable(LUA_GLOBALSINDEX);
L->declarefunc("get_nb_handles", sLuaHandle::get_nb_handles);
+ L->declarefunc("get_nb_input", sLuaHandle::get_nb_input);
+ L->declarefunc("get_nb_output", sLuaHandle::get_nb_output);
+ L->declarefunc("get_nb_buffer", sLuaHandle::get_nb_buffer);
}
diff --git a/lib/Output.cc b/lib/Output.cc
index d1a00c5..82649e8 100644
--- a/lib/Output.cc
+++ b/lib/Output.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: Output.cc,v 1.26 2007-05-30 11:57:10 pixel Exp $ */
+/* $Id: Output.cc,v 1.27 2008-01-21 17:55:43 pixel Exp $ */
#include <stdio.h>
#include <string.h>
@@ -41,12 +41,20 @@
#define S_ISREG(x) 1
#endif
+int Output::nb_output = 0;
+
+int Output::GetNbOutput() {
+ return nb_output;
+}
+
Output::Output(String no, int create, int trunc) throw (GeneralException) :
Handle(no.strlen() ? wrapopen(no.to_charp(), create, trunc) : dup(1)),
n(no) {
if (GetHandle() < 0) {
throw IOGeneral(String(_("Error opening file ")) + no + _(" for writing: ") + strerror(errno));
}
+
+ nb_output++;
size = lseek(GetHandle(), 0, SEEK_END);
if (trunc)
@@ -101,6 +109,7 @@ int Output::wrapopen(const String & n, int create, int trunc) {
}
Output::Output(const Output & o) : Handle(o), n(o.n) {
+ nb_output++;
}
bool Output::CanWrite() const {