aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJohannes Schickel2013-01-28 08:43:52 -0800
committerJohannes Schickel2013-01-28 08:43:52 -0800
commit2f73d64e803c3be97d20bdbd1c4c482e783eb3d6 (patch)
tree63b6956a644460392ca9eeb1225f43433f3f4082 /common
parent5bfd2f675620f69e23cefbaf8553cb341a9f992c (diff)
parentedfcd768ba394150df34d59f08765c3e061e6c72 (diff)
downloadscummvm-rg350-2f73d64e803c3be97d20bdbd1c4c482e783eb3d6.tar.gz
scummvm-rg350-2f73d64e803c3be97d20bdbd1c4c482e783eb3d6.tar.bz2
scummvm-rg350-2f73d64e803c3be97d20bdbd1c4c482e783eb3d6.zip
Merge pull request #305 from giucam/bufferedseekable
Make BufferedSeekableReadStream use the buffer with SEEK_SET and SEEK_END
Diffstat (limited to 'common')
-rw-r--r--common/stream.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/common/stream.cpp b/common/stream.cpp
index 2851b3a320..f49603c882 100644
--- a/common/stream.cpp
+++ b/common/stream.cpp
@@ -379,12 +379,25 @@ BufferedSeekableReadStream::BufferedSeekableReadStream(SeekableReadStream *paren
bool BufferedSeekableReadStream::seek(int32 offset, int whence) {
// If it is a "local" seek, we may get away with "seeking" around
// in the buffer only.
- // Note: We could try to handle SEEK_END and SEEK_SET, too, but
- // since they are rarely used, it seems not worth the effort.
_eos = false; // seeking always cancels EOS
- if (whence == SEEK_CUR && (int)_pos + offset >= 0 && _pos + offset <= _bufSize) {
- _pos += offset;
+ int relOffset = 0;
+ switch (whence) {
+ case SEEK_SET:
+ relOffset = offset - pos();
+ break;
+ case SEEK_CUR:
+ relOffset = offset;
+ break;
+ case SEEK_END:
+ relOffset = (size() + offset) - pos();
+ break;
+ default:
+ break;
+ }
+
+ if ((int)_pos + relOffset >= 0 && _pos + relOffset <= _bufSize) {
+ _pos += relOffset;
// Note: we do not need to reset parent's eos flag here. It is
// sufficient that it is reset when actually seeking in the parent.