summaryrefslogtreecommitdiff
path: root/lib/Handle.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Handle.cc')
-rw-r--r--lib/Handle.cc36
1 files changed, 28 insertions, 8 deletions
diff --git a/lib/Handle.cc b/lib/Handle.cc
index 684001d..4722e94 100644
--- a/lib/Handle.cc
+++ b/lib/Handle.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: Handle.cc,v 1.75 2005-02-17 08:33:50 pixel Exp $ */
+/* $Id: Handle.cc,v 1.76 2006-01-31 17:02:39 pixel Exp $ */
#include <stdio.h>
#include <string.h>
@@ -62,7 +62,7 @@ enum {
INFLATE
};
-Handle::Handle(const Handle & nh) : itell(0), hFile(0), h(nh.h >= 0 ? dup(nh.h) : nh.h), closed(nh.closed), nonblock(nh.closed), zfile(0), z(0), hMapObject(0), mapped(0)
+Handle::Handle(const Handle & nh) : itell(0), hFile(0), h(nh.h >= 0 ? nh.ndup() : nh.h), closed(nh.closed), nonblock(nh.closed), zfile(0), z(0), hMapObject(0), mapped(0)
{
#ifdef DEBUG
printm(M_INFO, String(_("Duplication of handle ")) + nh.h + _(" to ") + h + "\n");
@@ -79,7 +79,7 @@ Handle::~Handle() {
close();
}
-Handle::Handle(int nh) : h(nh), closed(false), nonblock(false), zfile(0), z(0), hMapObject(0), mapped(0)
+Handle::Handle(int nh) : itell(0), h(nh), closed(false), nonblock(false), zfile(0), z(0), hMapObject(0), mapped(0)
{
#ifdef DEBUG
printm(M_INFO, String(_("Initialising handle ")) + h + "\n");
@@ -210,7 +210,7 @@ Handle & operator<<(Handle & h, const String & s) {
const char * p;
p = s.to_charp();
- h.write(p, strlen(p));
+ h.write(p, s.strlen());
return h;
}
@@ -259,7 +259,7 @@ void Handle::close() throw (GeneralException) {
throw GeneralException(String(_("Error during inflateEnd: ")) + zstrm.msg);
}
}
- err = ::close(h);
+ err = nclose();
if (err) {
throw GeneralException(String(_("Error during (zstream) close: ")) + strerror(errno));
}
@@ -279,12 +279,16 @@ void Handle::close() throw (GeneralException) {
}
}
} else {
+#ifndef NO_HFILE
if (!hFile) {
- int err = ::close(h);
+#endif
+ int err = nclose();
if (err) {
throw GeneralException(String(_("Error during close: ")) + strerror(errno));
}
+#ifndef NO_HFILE
}
+#endif
}
#if defined (_WIN32) && !defined (NO_HFILE)
if (hFile) {
@@ -408,7 +412,7 @@ ssize_t Handle::uwrite(const void * buf, size_t count) throw (GeneralException)
itell += err;
return err;
} else {
- itell += count = ::write(h, buf, count);
+ itell += count = nwrite(buf, count);
return count;
}
}
@@ -440,7 +444,7 @@ ssize_t Handle::uread(void * buf, size_t count) {
itell += count = rcount;
} else
#endif
- itell += count = ::read(h, buf, count);
+ itell += count = nread(buf, count);
return count;
}
}
@@ -662,3 +666,19 @@ void Handle::munmap() throw (GeneralException) {
mappedarea = 0;
maplength = 0;
}
+
+ssize_t Handle::nwrite(const void * buf, size_t count) throw (GeneralException) {
+ return ::write(h, buf, count);
+}
+
+ssize_t Handle::nread(void * buf, size_t count) throw (GeneralException) {
+ return ::read(h, buf, count);
+}
+
+int Handle::ndup() const throw (GeneralException) {
+ return dup(h);
+}
+
+int Handle::nclose() throw (GeneralException) {
+ return ::close(h);
+}