diff options
author | Pixel <Pixel> | 2001-11-26 23:11:40 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2001-11-26 23:11:40 +0000 |
commit | 3baa9d168c02a8734b95d1cc467601b6aaf2f6e4 (patch) | |
tree | 6c254e9d75dee5a1e305283788fea3d3fff2a445 /lib/Buffer.cc | |
parent | 3aa63fcbddbce8762ad0f3f54d90ad985c0f9c41 (diff) |
Big job here. Many bugs out. Hurray!!
Diffstat (limited to 'lib/Buffer.cc')
-rw-r--r-- | lib/Buffer.cc | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/Buffer.cc b/lib/Buffer.cc index b3cb10b..afbaa6f 100644 --- a/lib/Buffer.cc +++ b/lib/Buffer.cc @@ -10,6 +10,9 @@ Buffer::~Buffer() { } ssize_t Buffer::write(const void *buf, size_t count) { + if (!count) { + return 0; + } if (count + realsiz > bufsiz) { int numblocks = (count + realsiz) / realloc_threshold; int remains = (count + realsiz) % realloc_threshold; @@ -33,10 +36,10 @@ ssize_t Buffer::read(void *buf, size_t count) throw (GeneralException) { if (ptr >= realloc_threshold) { int numblocks = (bufsiz / realloc_threshold) - (ptr / realloc_threshold); - memmove(buffer, buffer + numblocks * realloc_threshold, numblocks * realloc_threshold); + memmove(buffer, buffer + (bufsiz - numblocks * realloc_threshold), numblocks * realloc_threshold); + ptr -= (bufsiz - numblocks * realloc_threshold); + realsiz -= (bufsiz - numblocks * realloc_threshold); buffer = (char *) realloc(buffer, bufsiz = (numblocks * realloc_threshold)); - ptr -= numblocks * realloc_threshold; - realsiz -= numblocks * realloc_threshold; } return count; |