diff options
author | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2010-03-26 22:21:44 +0100 |
---|---|---|
committer | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2010-03-26 22:21:44 +0100 |
commit | 7e0849253145833bc923d249238483da1a115169 (patch) | |
tree | 0a1356a24a7869e3842b5494e0b3c48f047a1701 | |
parent | 2ca829b9301b7caae80fa3b8192c1fc7a8f0d8eb (diff) |
Working around a few zlib issues.
-rw-r--r-- | lib/Handle.cc | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/Handle.cc b/lib/Handle.cc index e8ac1d5..457f2c9 100644 --- a/lib/Handle.cc +++ b/lib/Handle.cc @@ -463,6 +463,9 @@ ssize_t Handle::uread(void * buf, size_t count) { #ifdef DEBUG printm(M_BARE, String(_("Performing gzread of ")) + count + _(" byte(s) for handle ") + h + "\n"); #endif + ssize_t msize = GetSize(); + if ((msize >= 0) && ((count + itell) >= msize)) + count = msize - itell; int err = gzread(zfile, buf, count); if (err == -1) { throw GeneralException(String("Error reading zstream: ") + gzerror(zfile, &err)); @@ -503,7 +506,23 @@ bool Handle::CanSeek() const { off_t Handle::seek(off_t offset, int whence) throw(GeneralException) { if (z) { - return itell = gzseek(zfile, offset, whence); + ssize_t msize = GetSize(); + if (msize >= 0) { + switch (whence) { + case SEEK_CUR: + offset += itell; + break; + case SEEK_END: + offset += msize; + break; + } + return itell = gzseek(zfile, offset, SEEK_SET); + } else { + if (whence == SEEK_END) { + throw IOGeneral("zlib can't seek from the end on a stream."); + } + return itell = gzseek(zfile, offset, whence); + } } else { throw IOGeneral(_("Handle ") + GetName() + _(" can't seek")); } |