diff options
-rw-r--r-- | backends/PalmOS/Src/missing/_stdio.cpp | 2 | ||||
-rw-r--r-- | common/savefile.cpp | 48 | ||||
-rw-r--r-- | common/savefile.h | 5 | ||||
-rw-r--r-- | simon/saveload.cpp | 26 | ||||
-rw-r--r-- | sound/softsynth/mt32/synth.cpp | 5 |
5 files changed, 45 insertions, 41 deletions
diff --git a/backends/PalmOS/Src/missing/_stdio.cpp b/backends/PalmOS/Src/missing/_stdio.cpp index 8857ee6db5..f2ee63ac51 100644 --- a/backends/PalmOS/Src/missing/_stdio.cpp +++ b/backends/PalmOS/Src/missing/_stdio.cpp @@ -29,8 +29,6 @@ static UInt16 gStdioVolRefNum = sysInvalidRefNum; static void dummy(Boolean){}; -// TODO : implement "errno" - void StdioInit(UInt16 volRefNum, const Char *output, LedProc ledProc) { gStdioVolRefNum = volRefNum; diff --git a/common/savefile.cpp b/common/savefile.cpp index b6d4cf47b9..96c6ed07d2 100644 --- a/common/savefile.cpp +++ b/common/savefile.cpp @@ -65,17 +65,24 @@ class StdioSaveFile : public SaveFile { private: FILE *fh; public: - StdioSaveFile(const char *filename, bool saveOrLoad) - { fh = ::fopen(filename, (saveOrLoad? "wb" : "rb")); } - ~StdioSaveFile() - { if(fh) ::fclose(fh); } + StdioSaveFile(const char *filename, bool saveOrLoad) { + fh = ::fopen(filename, (saveOrLoad? "wb" : "rb")); + } + ~StdioSaveFile() { + if(fh) + ::fclose(fh); + } + bool readingFailed() const { return ferror(fh); } + bool writingFailed() const { return ferror(fh); } bool isOpen() const { return fh != 0; } - uint32 read(void *buf, uint32 cnt) - { return ::fread(buf, 1, cnt, fh); } - uint32 write(const void *buf, uint32 cnt) - { return ::fwrite(buf, 1, cnt, fh); } + uint32 read(void *buf, uint32 cnt) { + return ::fread(buf, 1, cnt, fh); + } + uint32 write(const void *buf, uint32 cnt) { + return ::fwrite(buf, 1, cnt, fh); + } }; @@ -83,16 +90,26 @@ public: class GzipSaveFile : public SaveFile { private: gzFile fh; + bool _ioError; public: - GzipSaveFile(const char *filename, bool saveOrLoad) - { fh = ::gzopen(filename, (saveOrLoad? "wb" : "rb")); } - ~GzipSaveFile() - { if(fh) ::gzclose(fh); } + GzipSaveFile(const char *filename, bool saveOrLoad) { + _ioError = false; + fh = ::gzopen(filename, (saveOrLoad? "wb" : "rb")); + } + ~GzipSaveFile() { + if(fh) + ::gzclose(fh); + } + bool readingFailed() const { return _ioError; } + bool writingFailed() const { return _ioError; } bool isOpen() const { return fh != 0; } uint32 read(void *buf, uint32 cnt) { - return ::gzread(fh, buf, cnt); + int ret = ::gzread(fh, buf, cnt); + if (ret <= -1) + _ioError = true; + return ret; } uint32 write(const void *buf, uint32 cnt) { // Due to a "bug" in the zlib headers (or maybe I should say, @@ -102,7 +119,10 @@ public: // which you might think is the same as "const void *" but it // is not - rather it is equal to "void const *" which is the // same as "void *". Hrmpf - return ::gzwrite(fh, const_cast<void *>(buf), cnt); + int ret = ::gzwrite(fh, const_cast<void *>(buf), cnt); + if (ret <= 0) + _ioError = true; + return ret; } }; #endif diff --git a/common/savefile.h b/common/savefile.h index 4b4771daa9..2431dba53a 100644 --- a/common/savefile.h +++ b/common/savefile.h @@ -40,6 +40,9 @@ class InSaveFile : public Common::ReadStream { public: virtual ~InSaveFile() {} + + virtual bool readingFailed() const { return false; } + //bool eof() const; }; /** @@ -52,6 +55,8 @@ public: class OutSaveFile : public Common::WriteStream { public: virtual ~OutSaveFile() {} + + virtual bool writingFailed() const { return false; } }; /** diff --git a/simon/saveload.cpp b/simon/saveload.cpp index cebc5add06..7892da4f46 100644 --- a/simon/saveload.cpp +++ b/simon/saveload.cpp @@ -21,13 +21,6 @@ #include "stdafx.h" -#ifndef _WIN32_WCE -// FIXME TODO FIXME: Using errno is not really portable! -// We should get rid of this, possibly by adding (clear)ioFailed methods -// to the SaveFile class. -#include <errno.h> -#endif - #include "gui/about.h" #include "gui/message.h" @@ -413,11 +406,6 @@ bool SimonEngine::save_game(uint slot, char *caption) { _lock_word |= 0x100; -#ifndef _WIN32_WCE - errno = 0; -#endif - - f = _saveFileMan->openForSaving(gen_savename(slot)); if (f == NULL) { _lock_word &= ~0x100; @@ -514,11 +502,6 @@ bool SimonEngine::load_game(uint slot) { _lock_word |= 0x100; -#ifndef _WIN32_WCE - errno = 0; -#endif - - f = _saveFileMan->openForLoading(gen_savename(slot)); if (f == NULL) { _lock_word &= ~0x100; @@ -606,6 +589,10 @@ bool SimonEngine::load_game(uint slot) { // Write the bits in array 1 & 2 for (i = 0; i != 32; i++) _bit_array[i] = f->readUint16BE(); + + if (f->readingFailed()) { + error("load failed"); + } delete f; @@ -613,11 +600,6 @@ bool SimonEngine::load_game(uint slot) { _lock_word &= ~0x100; -#ifndef _WIN32_WCE - if (errno != 0) - error("load failed"); -#endif - return true; } diff --git a/sound/softsynth/mt32/synth.cpp b/sound/softsynth/mt32/synth.cpp index 289db62553..892258b7a4 100644 --- a/sound/softsynth/mt32/synth.cpp +++ b/sound/softsynth/mt32/synth.cpp @@ -22,7 +22,6 @@ #include <math.h> #include <string.h> #include <stdlib.h> -#include <errno.h> #include "mt32emu.h" @@ -395,7 +394,7 @@ bool Synth::open(SynthProperties &useProp) { if (!loadControlROM("CM32L_CONTROL.ROM")) { if (!loadControlROM("MT32_CONTROL.ROM")) { printDebug("Init Error - Missing or invalid MT32_CONTROL.ROM"); - report(ReportType_errorControlROM, &errno); + report(ReportType_errorControlROM, NULL); return false; } } @@ -410,7 +409,7 @@ bool Synth::open(SynthProperties &useProp) { if (!loadPCMROM("CM32L_PCM.ROM")) { if (!loadPCMROM("MT32_PCM.ROM")) { printDebug("Init Error - Missing MT32_PCM.ROM"); - report(ReportType_errorPCMROM, &errno); + report(ReportType_errorPCMROM, NULL); return false; } } |