diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/config-file.cpp | 6 | ||||
-rw-r--r-- | common/config-manager.cpp | 2 | ||||
-rw-r--r-- | common/file.cpp | 14 | ||||
-rw-r--r-- | common/file.h | 25 | ||||
-rw-r--r-- | common/stream.h | 17 | ||||
-rw-r--r-- | common/unzip.cpp | 26 |
6 files changed, 41 insertions, 49 deletions
diff --git a/common/config-file.cpp b/common/config-file.cpp index 61437a60ab..9b69452b2e 100644 --- a/common/config-file.cpp +++ b/common/config-file.cpp @@ -87,7 +87,7 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) { // TODO: Detect if a section occurs multiple times (or likewise, if // a key occurs multiple times inside one section). - while (!stream.eos() && !stream.ioFailed()) { + while (!stream.eos() && !stream.err()) { lineno++; // Read a line @@ -179,7 +179,7 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) { if (!section.name.empty()) _sections.push_back(section); - return (!stream.ioFailed() || stream.eos()); + return (!stream.err() || stream.eos()); } bool ConfigFile::saveToFile(const String &filename) { @@ -232,7 +232,7 @@ bool ConfigFile::saveToStream(WriteStream &stream) { } stream.flush(); - return !stream.ioFailed(); + return !stream.err(); } diff --git a/common/config-manager.cpp b/common/config-manager.cpp index f001c1821a..268fac5d2e 100644 --- a/common/config-manager.cpp +++ b/common/config-manager.cpp @@ -114,7 +114,7 @@ void ConfigManager::loadFromStream(SeekableReadStream &stream) { // TODO: Detect if a domain occurs multiple times (or likewise, if // a key occurs multiple times inside one domain). - while (!stream.eos() && !stream.ioFailed()) { + while (!stream.eos() && !stream.err()) { lineno++; // Read a line diff --git a/common/file.cpp b/common/file.cpp index ee741a8990..7836a7d4a8 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -58,10 +58,8 @@ bool File::open(const String &filename, Archive &archive) { assert(!filename.empty()); assert(!_handle); - clearIOFailed(); - SeekableReadStream *stream = 0; - + if ((stream = archive.createReadStreamForMember(filename))) { debug(3, "Opening hashed: %s", filename.c_str()); } else if ((stream = archive.createReadStreamForMember(filename + "."))) { @@ -90,7 +88,6 @@ bool File::open(const FSNode &node) { bool File::open(SeekableReadStream *stream, const Common::String &name) { assert(!_handle); - clearIOFailed(); if (stream) { _handle = stream; @@ -124,13 +121,12 @@ bool File::isOpen() const { } bool File::ioFailed() const { - // TODO/FIXME: Just use ferror() here? - return !_handle || _handle->ioFailed(); + return !_handle || (eos() || err()); } void File::clearIOFailed() { if (_handle) - _handle->clearIOFailed(); + _handle->clearErr(); } bool File::err() const { @@ -211,12 +207,12 @@ bool DumpFile::isOpen() const { bool DumpFile::err() const { assert(_handle); - return _handle->ioFailed(); + return _handle->err(); } void DumpFile::clearErr() { assert(_handle); - _handle->clearIOFailed(); + _handle->clearErr(); } uint32 DumpFile::write(const void *ptr, uint32 len) { diff --git a/common/file.h b/common/file.h index 28c99e0e38..a98d23a96a 100644 --- a/common/file.h +++ b/common/file.h @@ -126,16 +126,27 @@ public: */ const char *getName() const { return _name.c_str(); } + /** + * DEPRECATED: Use err() or eos() instead. + * Returns true if any I/O failure occurred or the end of the + * stream was reached while reading. + */ bool ioFailed() const; + + /** + * DEPRECATED: Don't use this unless you are still using ioFailed(). + * Reset the I/O error status. + */ void clearIOFailed(); - bool err() const; - void clearErr(); - bool eos() const; - virtual int32 pos() const; - virtual int32 size() const; - bool seek(int32 offs, int whence = SEEK_SET); - uint32 read(void *dataPtr, uint32 dataSize); + bool err() const; // implement abstract Stream method + void clearErr(); // implement abstract Stream method + bool eos() const; // implement abstract SeekableReadStream method + + int32 pos() const; // implement abstract SeekableReadStream method + int32 size() const; // implement abstract SeekableReadStream method + bool seek(int32 offs, int whence = SEEK_SET); // implement abstract SeekableReadStream method + uint32 read(void *dataPtr, uint32 dataSize); // implement abstract SeekableReadStream method }; diff --git a/common/stream.h b/common/stream.h index b691567623..80e2978fb9 100644 --- a/common/stream.h +++ b/common/stream.h @@ -41,19 +41,6 @@ public: virtual ~Stream() {} /** - * DEPRECATED: Use err() or eos() instead. - * Returns true if any I/O failure occurred or the end of the - * stream was reached while reading. - */ - virtual bool ioFailed() const { return err(); } - - /** - * DEPRECATED: Don't use this unless you are still using ioFailed(). - * Reset the I/O error status. - */ - virtual void clearIOFailed() { clearErr(); } - - /** * Returns true if an I/O failure occurred. * This flag is never cleared automatically. In order to clear it, * client code has to call clearErr() explicitly. @@ -405,7 +392,7 @@ public: * Upon successful completion, return a string with the content * of the line, *without* the end of a line marker. This method * does not indicate whether an error occured. Callers must use - * ioFailed() or eos() to determine whether an exception occurred. + * err() or eos() to determine whether an exception occurred. */ virtual String readLine(); }; @@ -509,8 +496,6 @@ public: ~BufferedReadStream(); virtual bool eos() const { return (_pos == _bufSize) && _parentStream->eos(); } - virtual bool ioFailed() const { return _parentStream->ioFailed(); } - virtual void clearIOFailed() { _parentStream->clearIOFailed(); } virtual bool err() const { return _parentStream->err(); } virtual void clearErr() { _parentStream->clearErr(); } diff --git a/common/unzip.cpp b/common/unzip.cpp index 9d4ea9d26b..1b0a09deeb 100644 --- a/common/unzip.cpp +++ b/common/unzip.cpp @@ -372,7 +372,7 @@ typedef struct { *pi = (int)c; return UNZ_OK; } else { - if (fin.ioFailed()) + if (fin.err()) return UNZ_ERRNO; else return UNZ_EOF; @@ -385,12 +385,12 @@ typedef struct { */ static int unzlocal_getShort(Common::SeekableReadStream *fin, uLong *pX) { *pX = fin->readUint16LE(); - return fin->ioFailed() ? UNZ_ERRNO : UNZ_OK; + return (fin->err() || fin->eos()) ? UNZ_ERRNO : UNZ_OK; } static int unzlocal_getLong(Common::SeekableReadStream *fin, uLong *pX) { *pX = fin->readUint32LE(); - return fin->ioFailed() ? UNZ_ERRNO : UNZ_OK; + return (fin->err() || fin->eos()) ? UNZ_ERRNO : UNZ_OK; } @@ -433,7 +433,7 @@ static uLong unzlocal_SearchCentralDir(Common::SeekableReadStream &fin) { uLong uPosFound=0; uSizeFile = fin.size(); - if (fin.ioFailed()) + if (fin.err()) return 0; if (uMaxBack>uSizeFile) @@ -456,7 +456,7 @@ static uLong unzlocal_SearchCentralDir(Common::SeekableReadStream &fin) { uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); fin.seek(uReadPos, SEEK_SET); - if (fin.ioFailed()) + if (fin.err()) break; if (fin.read(buf,(uInt)uReadSize)!=uReadSize) @@ -510,7 +510,7 @@ unzFile unzOpen(Common::SeekableReadStream *stream) { err=UNZ_ERRNO; us->_stream->seek(central_pos, SEEK_SET); - if (us->_stream->ioFailed()) + if (us->_stream->err()) err=UNZ_ERRNO; /* the signature, already checked */ @@ -651,7 +651,7 @@ static int unzlocal_GetCurrentFileInfoInternal(unzFile file, return UNZ_PARAMERROR; s=(unz_s*)file; s->_stream->seek(s->pos_in_central_dir+s->byte_before_the_zipfile, SEEK_SET); - if (s->_stream->ioFailed()) + if (s->_stream->err()) err=UNZ_ERRNO; @@ -735,7 +735,7 @@ static int unzlocal_GetCurrentFileInfoInternal(unzFile file, if (lSeek!=0) { s->_stream->seek(lSeek, SEEK_CUR); - if (s->_stream->ioFailed()) + if (s->_stream->err()) lSeek=0; else err=UNZ_ERRNO; @@ -759,7 +759,7 @@ static int unzlocal_GetCurrentFileInfoInternal(unzFile file, if (lSeek!=0) { s->_stream->seek(lSeek, SEEK_CUR); - if (s->_stream->ioFailed()) + if (s->_stream->err()) lSeek=0; else err=UNZ_ERRNO; @@ -917,7 +917,7 @@ static int unzlocal_CheckCurrentFileCoherencyHeader(unz_s* s, uInt* piSizeVar, s->_stream->seek(s->cur_file_info_internal.offset_curfile + s->byte_before_the_zipfile, SEEK_SET); - if (s->_stream->ioFailed()) + if (s->_stream->err()) return UNZ_ERRNO; @@ -1121,7 +1121,7 @@ int unzReadCurrentFile(unzFile file, voidp buf, unsigned len) { return UNZ_EOF; pfile_in_zip_read_info->_stream->seek(pfile_in_zip_read_info->pos_in_zipfile + pfile_in_zip_read_info->byte_before_the_zipfile, SEEK_SET); - if (pfile_in_zip_read_info->_stream->ioFailed()) + if (pfile_in_zip_read_info->_stream->err()) return UNZ_ERRNO; if (pfile_in_zip_read_info->_stream->read(pfile_in_zip_read_info->read_buffer,uReadThis)!=uReadThis) return UNZ_ERRNO; @@ -1275,7 +1275,7 @@ int unzGetLocalExtrafield(unzFile file, voidp buf, unsigned len) { pfile_in_zip_read_info->_stream->seek(pfile_in_zip_read_info->offset_local_extrafield + pfile_in_zip_read_info->pos_local_extrafield,SEEK_SET); - if (pfile_in_zip_read_info->_stream->ioFailed()) + if (pfile_in_zip_read_info->_stream->err()) return UNZ_ERRNO; if (pfile_in_zip_read_info->_stream->read(buf,(uInt)size_to_read)!=size_to_read) @@ -1339,7 +1339,7 @@ int unzGetGlobalComment(unzFile file, char *szComment, uLong uSizeBuf) { uReadThis = s->gi.size_comment; s->_stream->seek(s->central_pos+22, SEEK_SET); - if (s->_stream->ioFailed()) + if (s->_stream->err()) return UNZ_ERRNO; if (uReadThis>0) { |