From 655ce26b3f09628d9408a4d82efe3a26116999fe Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 13 Sep 2008 16:51:46 +0000 Subject: Big patch changing the signature of various Stream methods (some ports may need to be slightly tweaked to fix overloading errors/warnings) svn-id: r34514 --- backends/fs/stdiostream.cpp | 30 +++++-------- backends/fs/stdiostream.h | 8 ++-- backends/fs/symbian/symbianstream.cpp | 59 ++++++++++++-------------- backends/fs/symbian/symbianstream.h | 8 ++-- backends/platform/dc/vmsave.cpp | 14 +++--- backends/platform/ds/arm9/source/gbampsave.cpp | 10 ++--- backends/platform/ds/arm9/source/gbampsave.h | 8 ++-- backends/platform/ds/arm9/source/ramsave.cpp | 10 +++-- backends/platform/ds/arm9/source/ramsave.h | 8 ++-- backends/platform/ps2/savefile.cpp | 23 +++++----- backends/platform/ps2/savefile.h | 20 ++++----- backends/saves/compressed/compressed-saves.cpp | 10 +++-- 12 files changed, 100 insertions(+), 108 deletions(-) (limited to 'backends') diff --git a/backends/fs/stdiostream.cpp b/backends/fs/stdiostream.cpp index f3f20eacb5..fafcca989b 100644 --- a/backends/fs/stdiostream.cpp +++ b/backends/fs/stdiostream.cpp @@ -126,43 +126,33 @@ bool StdioStream::eos() const { return feof((FILE *)_handle) != 0; } -uint32 StdioStream::pos() const { - // FIXME: ftell can return -1 to indicate an error (in which case errno gets set) - // Maybe we should support that, too? +int32 StdioStream::pos() const { return ftell((FILE *)_handle); } -uint32 StdioStream::size() const { - uint32 oldPos = ftell((FILE *)_handle); +int32 StdioStream::size() const { + int32 oldPos = ftell((FILE *)_handle); fseek((FILE *)_handle, 0, SEEK_END); - uint32 length = ftell((FILE *)_handle); + int32 length = ftell((FILE *)_handle); fseek((FILE *)_handle, oldPos, SEEK_SET); return length; } -void StdioStream::seek(int32 offs, int whence) { - assert(_handle); - - if (fseek((FILE *)_handle, offs, whence) != 0) - clearerr((FILE *)_handle); // FIXME: why do we call clearerr here? - - // FIXME: fseek has a return value to indicate errors; - // Maybe we should support that, too? +bool StdioStream::seek(int32 offs, int whence) { + return fseek((FILE *)_handle, offs, whence) == 0; } uint32 StdioStream::read(void *ptr, uint32 len) { - return (uint32)fread((byte *)ptr, 1, len, (FILE *)_handle); + return fread((byte *)ptr, 1, len, (FILE *)_handle); } uint32 StdioStream::write(const void *ptr, uint32 len) { - return (uint32)fwrite(ptr, 1, len, (FILE *)_handle); + return fwrite(ptr, 1, len, (FILE *)_handle); } -void StdioStream::flush() { - // TODO: Should check the return value of fflush, and if it is non-zero, - // check errno and set an error flag. - fflush((FILE *)_handle); +bool StdioStream::flush() { + return fflush((FILE *)_handle) == 0; } StdioStream *StdioStream::makeFromPath(const Common::String &path, bool writeMode) { diff --git a/backends/fs/stdiostream.h b/backends/fs/stdiostream.h index 02e5463f63..f40ddd9867 100644 --- a/backends/fs/stdiostream.h +++ b/backends/fs/stdiostream.h @@ -51,11 +51,11 @@ public: bool eos() const; virtual uint32 write(const void *dataPtr, uint32 dataSize); - virtual void flush(); + virtual bool flush(); - virtual uint32 pos() const; - virtual uint32 size() const; - void seek(int32 offs, int whence = SEEK_SET); + virtual int32 pos() const; + virtual int32 size() const; + bool seek(int32 offs, int whence = SEEK_SET); uint32 read(void *dataPtr, uint32 dataSize); }; diff --git a/backends/fs/symbian/symbianstream.cpp b/backends/fs/symbian/symbianstream.cpp index 61fc5a04fb..4d2ec11ab3 100644 --- a/backends/fs/symbian/symbianstream.cpp +++ b/backends/fs/symbian/symbianstream.cpp @@ -104,10 +104,9 @@ size_t ReadData(const void* ptr, size_t size, size_t numItems, TSymbianFileEntry TPtr8 pointer ( (unsigned char*) ptr, totsize); // Nothing cached and we want to load at least KInputBufferLength bytes - if(totsize >= KInputBufferLength) { + if (totsize >= KInputBufferLength) { TUint32 totLength = 0; - if(entry->_inputPos != KErrNotFound) - { + if (entry->_inputPos != KErrNotFound) { TPtr8 cacheBuffer( (unsigned char*) entry->_inputBuffer+entry->_inputPos, entry->_inputBufferLen - entry->_inputPos, KInputBufferLength); pointer.Append(cacheBuffer); entry->_inputPos = KErrNotFound; @@ -121,44 +120,39 @@ size_t ReadData(const void* ptr, size_t size, size_t numItems, TSymbianFileEntry pointer.Set((unsigned char*) ptr, totLength, totsize); - } - else { + } else { // Nothing in buffer - if(entry->_inputPos == KErrNotFound) { + if (entry->_inputPos == KErrNotFound) { TPtr8 cacheBuffer( (unsigned char*) entry->_inputBuffer, KInputBufferLength); entry->_lastError = entry->_fileHandle.Read(cacheBuffer); - if(cacheBuffer.Length() >= totsize) { + if (cacheBuffer.Length() >= totsize) { pointer.Copy(cacheBuffer.Left(totsize)); entry->_inputPos = totsize; entry->_inputBufferLen = cacheBuffer.Length(); - } - else { + } else { pointer.Copy(cacheBuffer); entry->_inputPos = KErrNotFound; } - } - else { + } else { TPtr8 cacheBuffer( (unsigned char*) entry->_inputBuffer, entry->_inputBufferLen, KInputBufferLength); - if(entry->_inputPos+totsize < entry->_inputBufferLen) { + if (entry->_inputPos+totsize < entry->_inputBufferLen) { pointer.Copy(cacheBuffer.Mid(entry->_inputPos, totsize)); entry->_inputPos+=totsize; - } - else { + } else { pointer.Copy(cacheBuffer.Mid(entry->_inputPos, entry->_inputBufferLen-entry->_inputPos)); cacheBuffer.SetLength(0); entry->_lastError = entry->_fileHandle.Read(cacheBuffer); - if(cacheBuffer.Length() >= totsize-pointer.Length()) { + if (cacheBuffer.Length() >= totsize-pointer.Length()) { TUint32 restSize = totsize-pointer.Length(); pointer.Append(cacheBuffer.Left(restSize)); entry->_inputPos = restSize; entry->_inputBufferLen = cacheBuffer.Length(); - } - else { + } else { pointer.Append(cacheBuffer); entry->_inputPos = KErrNotFound; } @@ -166,7 +160,7 @@ size_t ReadData(const void* ptr, size_t size, size_t numItems, TSymbianFileEntry } } - if((numItems * size) != pointer.Length() && entry->_lastError == KErrNone) { + if((numItems * size) != pointer.Length() && entry->_lastError == KErrNone) { entry->_eofReached = ETrue; } @@ -197,20 +191,19 @@ bool SymbianStdioStream::eos() const { return entry->_eofReached != 0; } -uint32 SymbianStdioStream::pos() const { +int32 SymbianStdioStream::pos() const { TInt pos = 0; TSymbianFileEntry* entry = ((TSymbianFileEntry*)(_handle)); entry->_lastError = entry->_fileHandle.Seek(ESeekCurrent, pos); - if(entry->_lastError == KErrNone && entry->_inputPos != KErrNotFound) - { - pos+=(entry->_inputPos - entry->_inputBufferLen); - } + if (entry->_lastError == KErrNone && entry->_inputPos != KErrNotFound) { + pos += (entry->_inputPos - entry->_inputBufferLen); + } return pos; } -uint32 SymbianStdioStream::size() const { +int32 SymbianStdioStream::size() const { TInt length = 0; ((TSymbianFileEntry*)(_handle))->_fileHandle.Size(length); @@ -218,21 +211,21 @@ uint32 SymbianStdioStream::size() const { return length; } -void SymbianStdioStream::seek(int32 offs, int whence) { +bool SymbianStdioStream::seek(int32 offs, int whence) { assert(_handle); TSeek seekMode = ESeekStart; TInt pos = offs; TSymbianFileEntry* entry = ((TSymbianFileEntry*)(_handle)); - switch(whence) { + switch (whence) { case SEEK_SET: seekMode = ESeekStart; break; case SEEK_CUR: seekMode = ESeekCurrent; - if(entry->_inputPos != KErrNotFound) { - pos+=(entry->_inputPos - entry->_inputBufferLen); + if (entry->_inputPos != KErrNotFound) { + pos += (entry->_inputPos - entry->_inputBufferLen); } break; case SEEK_END: @@ -243,10 +236,9 @@ void SymbianStdioStream::seek(int32 offs, int whence) { entry->_inputPos = KErrNotFound; entry->_eofReached = EFalse; - if (entry->_fileHandle.Seek(seekMode, pos) != 0) - { - ((TSymbianFileEntry *)(_handle))->_lastError = 0; // FIXME: why do we call clearerr here? - } + entry->_fileHandle.Seek(seekMode, pos); + + return true; // FIXME: Probably should return a value based on what _fileHandle.Seek returns } uint32 SymbianStdioStream::read(void *ptr, uint32 len) { @@ -267,8 +259,9 @@ uint32 SymbianStdioStream::write(const void *ptr, uint32 len) { return 0; } -void SymbianStdioStream::flush() { +bool SymbianStdioStream::flush() { ((TSymbianFileEntry*)(_handle))->_fileHandle.Flush(); + return true; } SymbianStdioStream *SymbianStdioStream::makeFromPath(const Common::String &path, bool writeMode) { diff --git a/backends/fs/symbian/symbianstream.h b/backends/fs/symbian/symbianstream.h index 776446c5f5..180e6bffcb 100644 --- a/backends/fs/symbian/symbianstream.h +++ b/backends/fs/symbian/symbianstream.h @@ -51,11 +51,11 @@ public: bool eos() const; virtual uint32 write(const void *dataPtr, uint32 dataSize); - virtual void flush(); + virtual bool flush(); - virtual uint32 pos() const; - virtual uint32 size() const; - void seek(int32 offs, int whence = SEEK_SET); + virtual int32 pos() const; + virtual int32 size() const; + bool seek(int32 offs, int whence = SEEK_SET); uint32 read(void *dataPtr, uint32 dataSize); }; diff --git a/backends/platform/dc/vmsave.cpp b/backends/platform/dc/vmsave.cpp index 6ab8fc4558..5fe532e1f1 100644 --- a/backends/platform/dc/vmsave.cpp +++ b/backends/platform/dc/vmsave.cpp @@ -271,8 +271,8 @@ private: int _pos, _size; uint32 read(void *buf, uint32 cnt); - void skip(uint32 offset); - void seek(int32 offs, int whence); + bool skip(uint32 offset); + bool seek(int32 offs, int whence); public: InVMSave() @@ -286,8 +286,8 @@ public: } bool eos() const { return _pos >= _size; } - uint32 pos() const { return _pos; } - uint32 size() const { return _size; } + int32 pos() const { return _pos; } + int32 size() const { return _size; } bool readSaveGame(const char *filename) { return ::readSaveGame(buffer, _size, filename); } @@ -378,15 +378,16 @@ uint32 InVMSave::read(void *buf, uint32 cnt) return cnt; } -void InVMSave::skip(uint32 offset) +bool InVMSave::skip(uint32 offset) { int nbyt = offset; if (_pos + nbyt > _size) nbyt = (_size - _pos); _pos += nbyt; + return true; } -void InVMSave::seek(int32 offs, int whence) +bool InVMSave::seek(int32 offs, int whence) { switch(whence) { case SEEK_SET: @@ -403,6 +404,7 @@ void InVMSave::seek(int32 offs, int whence) _pos = 0; else if (_pos > _size) _pos = _size; + return true; } uint32 OutVMSave::write(const void *buf, uint32 cnt) diff --git a/backends/platform/ds/arm9/source/gbampsave.cpp b/backends/platform/ds/arm9/source/gbampsave.cpp index 9c8af81a6e..8209b783fa 100644 --- a/backends/platform/ds/arm9/source/gbampsave.cpp +++ b/backends/platform/ds/arm9/source/gbampsave.cpp @@ -54,8 +54,8 @@ bool GBAMPSaveFile::eos() const { return DS::std_feof(handle); } -void GBAMPSaveFile::skip(uint32 bytes) { - DS::std_fseek(handle, bytes, SEEK_CUR); +bool GBAMPSaveFile::skip(uint32 bytes) { + return DS::std_fseek(handle, bytes, SEEK_CUR) == 0; } void GBAMPSaveFile::flushSaveBuffer() { @@ -67,11 +67,11 @@ void GBAMPSaveFile::flushSaveBuffer() { } } -uint32 GBAMPSaveFile::pos() const { +int32 GBAMPSaveFile::pos() const { return DS::std_ftell(handle); } -uint32 GBAMPSaveFile::size() const { +int32 GBAMPSaveFile::size() const { int position = pos(); DS::std_fseek(handle, 0, SEEK_END); int size = DS::std_ftell(handle); @@ -80,7 +80,7 @@ uint32 GBAMPSaveFile::size() const { } void GBAMPSaveFile::seek(int32 pos, int whence) { - DS::std_fseek(handle, pos, whence); + return DS::std_fseek(handle, pos, whence) == 0; } diff --git a/backends/platform/ds/arm9/source/gbampsave.h b/backends/platform/ds/arm9/source/gbampsave.h index d0cbc68bfd..6ddc4fd964 100644 --- a/backends/platform/ds/arm9/source/gbampsave.h +++ b/backends/platform/ds/arm9/source/gbampsave.h @@ -43,11 +43,11 @@ public: virtual uint32 write(const void *buf, uint32 size); virtual bool eos() const; - virtual void skip(uint32 bytes); + virtual bool skip(uint32 bytes); - virtual uint32 pos() const; - virtual uint32 size() const; - virtual void seek(int32 pos, int whence); + virtual int32 pos() const; + virtual int32 size() const; + virtual bool seek(int32 pos, int whence); void flushSaveBuffer(); diff --git a/backends/platform/ds/arm9/source/ramsave.cpp b/backends/platform/ds/arm9/source/ramsave.cpp index be355ce76f..8442fd6b88 100644 --- a/backends/platform/ds/arm9/source/ramsave.cpp +++ b/backends/platform/ds/arm9/source/ramsave.cpp @@ -181,15 +181,15 @@ uint32 DSSaveFile::read(void *buf, uint32 size) { return size; } -uint32 DSSaveFile::pos() const { +int32 DSSaveFile::pos() const { return ptr; } -uint32 DSSaveFile::size() const { +int32 DSSaveFile::size() const { return save.size; } -void DSSaveFile::seek(int32 pos, int whence) { +bool DSSaveFile::seek(int32 pos, int whence) { switch (whence) { case SEEK_SET: { ptr = pos; @@ -204,15 +204,17 @@ void DSSaveFile::seek(int32 pos, int whence) { break; } } + return true; } bool DSSaveFile::eos() const { return ptr >= (int) save.size; } -void DSSaveFile::skip(uint32 bytes) { +bool DSSaveFile::skip(uint32 bytes) { ptr = ptr + bytes; if (ptr > (int) save.size) ptr = save.size; + return true; } uint32 DSSaveFile::write(const void *buf, uint32 size) { diff --git a/backends/platform/ds/arm9/source/ramsave.h b/backends/platform/ds/arm9/source/ramsave.h index f919da18db..e276775b66 100644 --- a/backends/platform/ds/arm9/source/ramsave.h +++ b/backends/platform/ds/arm9/source/ramsave.h @@ -62,11 +62,11 @@ public: bool isOpen() const { return isOpenFlag; } virtual bool eos() const; - virtual void skip(uint32 size); + virtual bool skip(uint32 size); - virtual uint32 pos() const; - virtual uint32 size() const; - virtual void seek(int32 pos, int whence); + virtual int32 pos() const; + virtual int32 size() const; + virtual bool seek(int32 pos, int whence); uint32 read(void *buf, uint32 size); uint32 write(const void *buf, uint32 size); diff --git a/backends/platform/ps2/savefile.cpp b/backends/platform/ps2/savefile.cpp index 5ee724cd3f..7d45aabda7 100644 --- a/backends/platform/ps2/savefile.cpp +++ b/backends/platform/ps2/savefile.cpp @@ -112,24 +112,26 @@ bool UclInSaveFile::eos(void) const { return bufTell() == bufSize(); } -uint32 UclInSaveFile::pos(void) const { +int32 UclInSaveFile::pos(void) const { return bufTell(); } -uint32 UclInSaveFile::size(void) const { +int32 UclInSaveFile::size(void) const { return bufSize(); } -void UclInSaveFile::seek(int pos, int whence) { +bool UclInSaveFile::seek(int pos, int whence) { bufSeek(pos, whence); + return true; } uint32 UclInSaveFile::read(void *ptr, uint32 size) { return (uint32)bufRead(ptr, (int)size); } -void UclInSaveFile::skip(uint32 offset) { +bool UclInSaveFile::skip(uint32 offset) { bufSeek(offset, SEEK_CUR); + return true;s } UclOutSaveFile::UclOutSaveFile(const char *filename, OSystem_PS2 *system, Gs2dScreen *screen, McAccess *mc) : RawWriteFile(mc) { @@ -168,12 +170,12 @@ void UclOutSaveFile::clearIOFailed(void) { _ioFailed = false; } -void UclOutSaveFile::flush(void) { +bool UclOutSaveFile::flush(void) { if (_pos != 0) { if (_wasFlushed) { printf("Multiple calls to UclOutSaveFile::flush!\n"); _ioFailed = true; - return; + return false; } uint32 compSize = _pos * 2; uint8 *compBuf = (uint8*)memalign(64, compSize + 8); @@ -193,6 +195,7 @@ void UclOutSaveFile::flush(void) { } _wasFlushed = true; } + return true; } /* ----------------------------------------- Glue Classes for POSIX Memory Card Access ----------------------------------------- */ @@ -216,11 +219,11 @@ uint32 Ps2McReadFile::write(const void *src, uint32 len) { return 0; } -uint32 Ps2McReadFile::tell(void) { +int32 Ps2McReadFile::tell(void) { return bufTell(); } -uint32 Ps2McReadFile::size(void) { +int32 Ps2McReadFile::size(void) { return bufSize(); } @@ -253,11 +256,11 @@ uint32 Ps2McWriteFile::write(const void *src, uint32 len) { return len; } -uint32 Ps2McWriteFile::tell(void) { +int32 Ps2McWriteFile::tell(void) { return bufTell(); } -uint32 Ps2McWriteFile::size(void) { +int32 Ps2McWriteFile::size(void) { return bufTell(); } diff --git a/backends/platform/ps2/savefile.h b/backends/platform/ps2/savefile.h index 4832b8c3fe..fd09c823d0 100644 --- a/backends/platform/ps2/savefile.h +++ b/backends/platform/ps2/savefile.h @@ -41,7 +41,7 @@ public: UclOutSaveFile(const char *filename, OSystem_PS2 *system, Gs2dScreen *screen, McAccess *mc); virtual ~UclOutSaveFile(void); virtual uint32 write(const void *ptr, uint32 size); - virtual void flush(void); + virtual bool flush(void); virtual bool ioFailed(void) const; virtual void clearIOFailed(void); private: @@ -60,11 +60,11 @@ public: virtual uint32 read(void *ptr, uint32 size); virtual bool ioFailed(void) const; virtual void clearIOFailed(void); - virtual void skip(uint32 offset); + virtual bool skip(uint32 offset); - virtual uint32 pos(void) const; - virtual uint32 size(void) const; - virtual void seek(int pos, int whence = SEEK_SET); + virtual int32 pos(void) const; + virtual int32 size(void) const; + virtual bool seek(int pos, int whence = SEEK_SET); private: Gs2dScreen *_screen; bool _ioFailed; @@ -75,7 +75,7 @@ public: AutoSaveFile(Ps2SaveFileManager *saveMan, const char *filename); ~AutoSaveFile(void); virtual uint32 write(const void *ptr, uint32 size); - virtual void flush(void) {} + virtual bool flush(void) {} virtual bool ioFailed(void) { return false; }; virtual void clearIOFailed(void) {} private: @@ -95,8 +95,8 @@ public: virtual bool open(const char *name); virtual uint32 read(void *dest, uint32 len); virtual uint32 write(const void *src, uint32 len); - virtual uint32 tell(void); - virtual uint32 size(void); + virtual int32 tell(void); + virtual int32 size(void); virtual int seek(int32 offset, int origin); virtual bool eof(void); }; @@ -108,8 +108,8 @@ public: virtual bool open(const char *name); virtual uint32 read(void *dest, uint32 len); virtual uint32 write(const void *src, uint32 len); - virtual uint32 tell(void); - virtual uint32 size(void); + virtual int32 tell(void); + virtual int32 size(void); virtual int seek(int32 offset, int origin); virtual bool eof(void); }; diff --git a/backends/saves/compressed/compressed-saves.cpp b/backends/saves/compressed/compressed-saves.cpp index 0c4fec0e24..27b8749911 100644 --- a/backends/saves/compressed/compressed-saves.cpp +++ b/backends/saves/compressed/compressed-saves.cpp @@ -125,13 +125,13 @@ public: return (_zlibErr == Z_STREAM_END); //return _pos == _origSize; } - uint32 pos() const { + int32 pos() const { return _pos; } - uint32 size() const { + int32 size() const { return _origSize; } - void seek(int32 offset, int whence = SEEK_SET) { + bool seek(int32 offset, int whence = SEEK_SET) { int32 newPos = 0; assert(whence != SEEK_END); // SEEK_END not supported switch(whence) { @@ -155,7 +155,7 @@ public: _wrapped->seek(0, SEEK_SET); _zlibErr = inflateReset(&_stream); if (_zlibErr != Z_OK) - return; + return false; // FIXME: STREAM REWRITE _stream.next_in = _buf; _stream.avail_in = 0; } @@ -169,6 +169,8 @@ public: while (!ioFailed() && offset > 0) { offset -= read(tmpBuf, MIN((int32)sizeof(tmpBuf), offset)); } + + return true; // FIXME: STREAM REWRITE } }; -- cgit v1.2.3