diff options
author | Max Horn | 2005-04-13 18:36:55 +0000 |
---|---|---|
committer | Max Horn | 2005-04-13 18:36:55 +0000 |
commit | 839c8add38ba710654cbe304493521584e663dd7 (patch) | |
tree | b9e5975f1ec1911e14045e0c197fe13e5880464b /common | |
parent | a5993b21129b133bdbd570a3f540caf44c0c3958 (diff) | |
download | scummvm-rg350-839c8add38ba710654cbe304493521584e663dd7.tar.gz scummvm-rg350-839c8add38ba710654cbe304493521584e663dd7.tar.bz2 scummvm-rg350-839c8add38ba710654cbe304493521584e663dd7.zip |
Get rid of errno; add some (optional) error checking facilities to SaveFile classes (they are ugly, and to simple, but better than nothing)
svn-id: r17589
Diffstat (limited to 'common')
-rw-r--r-- | common/savefile.cpp | 48 | ||||
-rw-r--r-- | common/savefile.h | 5 |
2 files changed, 39 insertions, 14 deletions
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; } }; /** |