diff options
-rw-r--r-- | include/Main.h | 2 | ||||
-rw-r--r-- | lib/Handle.cc | 30 | ||||
-rw-r--r-- | lib/Input.cc | 2 |
3 files changed, 30 insertions, 4 deletions
diff --git a/include/Main.h b/include/Main.h index 014fc6b..41ffd48 100644 --- a/include/Main.h +++ b/include/Main.h @@ -1,8 +1,8 @@ #ifndef __MAIN_H__ #define __MAIN_H__ -#include "gettext.h" #include "Exceptions.h" +#include "gettext.h" extern char ** environ; diff --git a/lib/Handle.cc b/lib/Handle.cc index d6fa0fb..c6f7a1a 100644 --- a/lib/Handle.cc +++ b/lib/Handle.cc @@ -74,6 +74,8 @@ ssize_t Handle::write(const void *cbuf, size_t count) throw (GeneralException) { bool done, full = false; const char * buf = (const char *)cbuf; + if (!count) + return 0; do { done = true; @@ -120,6 +122,9 @@ ssize_t Handle::write(const void *cbuf, size_t count) throw (GeneralException) { ssize_t Handle::read(void *buf, size_t count) throw (GeneralException) { ssize_t r; + if (!count) + return 0; + #ifdef FULLDEBUG printm(M_INFO, String(_("read: reading ")) + count + _(" bytes from handle ") + GetHandle() + "\n"); #endif @@ -451,7 +456,7 @@ void Handle::writeU32(Uint32 v) { #endif } -void copy(Handle * s, Handle * d, ssize_t size) { +void copyone(Handle * s, Handle * d, ssize_t size) { long i; unsigned char c; long r; @@ -465,6 +470,29 @@ void copy(Handle * s, Handle * d, ssize_t size) { } } +#define BSIZE 2048 + +void copy(Handle * s, Handle * d, ssize_t size) { + long i; + static unsigned char b[BSIZE]; + long r; + + while (size) { + if ((size > BSIZE) || (size < 0)) { + r = s->read(b, BSIZE); + if (r) + d->write(b, r); + } else { + r = s->read(b, size); + if (r) + d->write(b, r); + } + if (!r) + break; + size -= r; + } +} + void Handle::Flush() { if (h < 0) return; diff --git a/lib/Input.cc b/lib/Input.cc index d846acd..c77120c 100644 --- a/lib/Input.cc +++ b/lib/Input.cc @@ -5,8 +5,6 @@ #include <sys/stat.h> #include <fcntl.h> -#define DEBUG - #ifdef HAVE_CONFIG_H #include "config.h" #endif |