diff options
author | Giulio Camuffo | 2013-01-26 19:00:22 +0100 |
---|---|---|
committer | Giulio Camuffo | 2013-01-26 19:12:26 +0100 |
commit | edfcd768ba394150df34d59f08765c3e061e6c72 (patch) | |
tree | 427fb9bde5334b84729d2355ddd61c6214e5ef56 | |
parent | 980dc4a456f55a8b6526d2bc6f7694a0b2d666b3 (diff) | |
download | scummvm-rg350-edfcd768ba394150df34d59f08765c3e061e6c72.tar.gz scummvm-rg350-edfcd768ba394150df34d59f08765c3e061e6c72.tar.bz2 scummvm-rg350-edfcd768ba394150df34d59f08765c3e061e6c72.zip |
COMMON: Make BufferedSeekableReadStream use the buffer with SEEK_SET and SEEK_END
-rw-r--r-- | common/stream.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/common/stream.cpp b/common/stream.cpp index 85647bfe3a..d3cfce4066 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. |