From e2f68e24035245ec0f453c49b28207d32def4789 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 5 May 2019 09:58:14 +1000 Subject: COMMON: Fix seek return values, memory stream use in create_titanic --- common/file.cpp | 2 +- common/memstream.h | 23 ++++++++++++++++++++++- common/stream.cpp | 25 ------------------------- 3 files changed, 23 insertions(+), 27 deletions(-) (limited to 'common') diff --git a/common/file.cpp b/common/file.cpp index 9cf554646c..6320838e0b 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -221,7 +221,7 @@ int32 DumpFile::pos() const { return _handle->pos(); } bool DumpFile::seek(int32 offset, int whence) { SeekableWriteStream *ws = dynamic_cast(_handle); - return ws ? ws->seek(offset, whence) : -1; + return ws ? ws->seek(offset, whence) : false; } int32 DumpFile::size() const { diff --git a/common/memstream.h b/common/memstream.h index d7c59ffb99..991268ce10 100644 --- a/common/memstream.h +++ b/common/memstream.h @@ -210,7 +210,28 @@ public: byte *getData() { return _data; } - virtual bool seek(int32 offset, int whence = SEEK_SET) override; + virtual bool seek(int32 offs, int whence = SEEK_SET) override { + // Pre-Condition + assert(_pos <= _size); + switch (whence) { + case SEEK_END: + // SEEK_END works just like SEEK_SET, only 'reversed', i.e. from the end. + offs = _size + offs; + // Fall through + case SEEK_SET: + _ptr = _data + offs; + _pos = offs; + break; + + case SEEK_CUR: + _ptr += offs; + _pos += offs; + break; + } + + assert(_pos <= _size); + return true; + } }; /** diff --git a/common/stream.cpp b/common/stream.cpp index 5c9b571af4..9bd09386d9 100644 --- a/common/stream.cpp +++ b/common/stream.cpp @@ -102,31 +102,6 @@ bool MemoryReadStream::seek(int32 offs, int whence) { return true; // FIXME: STREAM REWRITE } -bool MemoryWriteStreamDynamic::seek(int32 offs, int whence) { - // Pre-Condition - assert(_pos <= _size); - switch (whence) { - case SEEK_END: - // SEEK_END works just like SEEK_SET, only 'reversed', - // i.e. from the end. - offs = _size + offs; - // Fall through - case SEEK_SET: - _ptr = _data + offs; - _pos = offs; - break; - - case SEEK_CUR: - _ptr += offs; - _pos += offs; - break; - } - // Post-Condition - assert(_pos <= _size); - - return true; // FIXME: STREAM REWRITE -} - #pragma mark - enum { -- cgit v1.2.3