diff options
Diffstat (limited to 'lib/Handle.cc')
-rw-r--r-- | lib/Handle.cc | 30 |
1 files changed, 29 insertions, 1 deletions
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; |