COMMON: Fix seek return values, memory stream use in create_titanic

This commit is contained in:
Paul Gilbert 2019-05-05 09:58:14 +10:00 committed by Filippos Karapetis
parent b821e8fce4
commit e2f68e2403
3 changed files with 23 additions and 27 deletions

View file

@ -221,7 +221,7 @@ int32 DumpFile::pos() const { return _handle->pos(); }
bool DumpFile::seek(int32 offset, int whence) {
SeekableWriteStream *ws = dynamic_cast<SeekableWriteStream *>(_handle);
return ws ? ws->seek(offset, whence) : -1;
return ws ? ws->seek(offset, whence) : false;
}
int32 DumpFile::size() const {

View file

@ -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;
}
};
/**

View file

@ -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 {