From 68d620ccab1be965c8b0f7373cb1280e11244139 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 5 Jul 2010 19:10:20 +0000 Subject: DS: Fix warnings, make some vars static, cleanup svn-id: r50701 --- backends/fs/ds/ds-fs.cpp | 16 +++++----------- backends/fs/ds/ds-fs.h | 4 +++- 2 files changed, 8 insertions(+), 12 deletions(-) (limited to 'backends/fs') diff --git a/backends/fs/ds/ds-fs.cpp b/backends/fs/ds/ds-fs.cpp index fafdc8502e..43203eed54 100644 --- a/backends/fs/ds/ds-fs.cpp +++ b/backends/fs/ds/ds-fs.cpp @@ -416,18 +416,12 @@ bool DSFileStream::eos() const { } int32 DSFileStream::pos() const { - if (_writeBufferPos > 0) { - // Discard constness. Bad, but I can't see another way. - ((DSFileStream *) (this))->flush(); - } + assert(_writeBufferPos == 0); // This method may only be called when reading! return std_ftell((FILE *)_handle); } int32 DSFileStream::size() const { - if (_writeBufferPos > 0) { - // Discard constness. Bad, but I can't see another way. - ((DSFileStream *) (this))->flush(); - } + assert(_writeBufferPos == 0); // This method may only be called when reading! int32 oldPos = std_ftell((FILE *)_handle); std_fseek((FILE *)_handle, 0, SEEK_END); int32 length = std_ftell((FILE *)_handle); @@ -659,10 +653,10 @@ size_t std_fread(void *ptr, size_t size, size_t numItems, FILE *handle) { return bytes / size; } - if ((int)(handle->pos + size * numItems) > handle->size) { + if (handle->pos > handle->size) + numItems = 0; + else if ((int)(handle->pos + size * numItems) > handle->size) numItems = (handle->size - handle->pos) / size; - if (numItems < 0) numItems = 0; - } // consolePrintf("read %d ", size * numItems); diff --git a/backends/fs/ds/ds-fs.h b/backends/fs/ds/ds-fs.h index ee4afe60f3..fadfb8a40d 100644 --- a/backends/fs/ds/ds-fs.h +++ b/backends/fs/ds/ds-fs.h @@ -173,7 +173,9 @@ struct fileHandle { class DSFileStream : public Common::SeekableReadStream, public Common::WriteStream, public Common::NonCopyable { protected: - static const int WRITE_BUFFER_SIZE = 512; + enum { + WRITE_BUFFER_SIZE = 512 + }; /** File handle to the actual file. */ void *_handle; -- cgit v1.2.3