[Scummvm-cvs-logs] CVS: scummvm/common savefile.cpp,1.16,1.17 savefile.h,1.15,1.16
Max Horn
fingolfin at users.sourceforge.net
Wed Apr 13 11:39:08 CEST 2005
Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12854/common
Modified Files:
savefile.cpp savefile.h
Log Message:
Get rid of errno; add some (optional) error checking facilities to SaveFile classes (they are ugly, and to simple, but better than nothing)
Index: savefile.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/savefile.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- savefile.cpp 10 Apr 2005 15:13:36 -0000 1.16
+++ savefile.cpp 13 Apr 2005 18:36:54 -0000 1.17
@@ -65,17 +65,24 @@
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 @@
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 @@
// 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
Index: savefile.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/savefile.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- savefile.h 10 Apr 2005 15:13:37 -0000 1.15
+++ savefile.h 13 Apr 2005 18:36:54 -0000 1.16
@@ -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 @@
class OutSaveFile : public Common::WriteStream {
public:
virtual ~OutSaveFile() {}
+
+ virtual bool writingFailed() const { return false; }
};
/**
More information about the Scummvm-git-logs
mailing list