diff options
author | Max Horn | 2010-11-18 17:30:00 +0000 |
---|---|---|
committer | Max Horn | 2010-11-18 17:30:00 +0000 |
commit | b8995eadfcc1fe4de1ce3e586db0c52ba2570f75 (patch) | |
tree | 75138f9eb6f716c4475847cfbb646197865ef95d /backends/fs/ds | |
parent | b593b15c5091843724fbc8d9059c8132719919a2 (diff) | |
download | scummvm-rg350-b8995eadfcc1fe4de1ce3e586db0c52ba2570f75.tar.gz scummvm-rg350-b8995eadfcc1fe4de1ce3e586db0c52ba2570f75.tar.bz2 scummvm-rg350-b8995eadfcc1fe4de1ce3e586db0c52ba2570f75.zip |
DS: Remove write buffering in DSFileStream, use wrapBufferedWriteStream instead
svn-id: r54331
Diffstat (limited to 'backends/fs/ds')
-rw-r--r-- | backends/fs/ds/ds-fs.cpp | 46 | ||||
-rw-r--r-- | backends/fs/ds/ds-fs.h | 6 |
2 files changed, 12 insertions, 40 deletions
diff --git a/backends/fs/ds/ds-fs.cpp b/backends/fs/ds/ds-fs.cpp index f52bf6f501..fc4e5f5376 100644 --- a/backends/fs/ds/ds-fs.cpp +++ b/backends/fs/ds/ds-fs.cpp @@ -40,9 +40,13 @@ namespace DS { // DSFileSystemNode - Flash ROM file system using Zip files // ////////////////////////////////////////////////////////////// -ZipFile* DSFileSystemNode::_zipFile = NULL; -char currentDir[128]; -bool readPastEndOfFile = false; +ZipFile* DSFileSystemNode::_zipFile = NULL; // FIXME: Avoid non-const global vars +char currentDir[128]; // FIXME: Avoid non-const global vars +bool readPastEndOfFile = false; // FIXME: Avoid non-const global vars + +enum { + WRITE_BUFFER_SIZE = 512 +}; DSFileSystemNode::DSFileSystemNode() { _displayName = "ds:/"; @@ -205,7 +209,8 @@ Common::SeekableReadStream *DSFileSystemNode::createReadStream() { } Common::WriteStream *DSFileSystemNode::createWriteStream() { - return DSFileStream::makeFromPath(getPath(), true); + Common::WriteStream *stream = DSFileStream::makeFromPath(getPath(), true); + return Common::wrapBufferedWriteStream(stream, WRITE_BUFFER_SIZE, DisposeAfterUse::YES); } ////////////////////////////////////////////////////////////////////////// @@ -386,21 +391,17 @@ Common::SeekableReadStream *GBAMPFileSystemNode::createReadStream() { } Common::WriteStream *GBAMPFileSystemNode::createWriteStream() { - return DSFileStream::makeFromPath(getPath(), true); + Common::WriteStream *stream = DSFileStream::makeFromPath(getPath(), true); + return Common::wrapBufferedWriteStream(stream, WRITE_BUFFER_SIZE, DisposeAfterUse::YES); } - DSFileStream::DSFileStream(void *handle) : _handle(handle) { assert(handle); - _writeBufferPos = 0; } DSFileStream::~DSFileStream() { - if (_writeBufferPos > 0) { - flush(); - } std_fclose((FILE *)_handle); } @@ -417,12 +418,10 @@ bool DSFileStream::eos() const { } int32 DSFileStream::pos() const { - assert(_writeBufferPos == 0); // This method may only be called when reading! return std_ftell((FILE *)_handle); } int32 DSFileStream::size() const { - assert(_writeBufferPos == 0); // This method may only be called when reading! int32 oldPos = std_ftell((FILE *)_handle); std_fseek((FILE *)_handle, 0, SEEK_END); int32 length = std_ftell((FILE *)_handle); @@ -432,39 +431,18 @@ int32 DSFileStream::size() const { } bool DSFileStream::seek(int32 offs, int whence) { - if (_writeBufferPos > 0) { - flush(); - } return std_fseek((FILE *)_handle, offs, whence) == 0; } uint32 DSFileStream::read(void *ptr, uint32 len) { - if (_writeBufferPos > 0) { - flush(); - } return std_fread(ptr, 1, len, (FILE *)_handle); } uint32 DSFileStream::write(const void *ptr, uint32 len) { - if (_writeBufferPos + len < WRITE_BUFFER_SIZE) { - memcpy(_writeBuffer + _writeBufferPos, ptr, len); - _writeBufferPos += len; - return len; - } else { - if (_writeBufferPos > 0) { - flush(); - } - return std_fwrite(ptr, 1, len, (FILE *)_handle); - } + return std_fwrite(ptr, 1, len, (FILE *)_handle); } bool DSFileStream::flush() { - - if (_writeBufferPos > 0) { - std_fwrite(_writeBuffer, 1, _writeBufferPos, (FILE *) _handle); - _writeBufferPos = 0; - } - return std_fflush((FILE *)_handle) == 0; } diff --git a/backends/fs/ds/ds-fs.h b/backends/fs/ds/ds-fs.h index 0a9ba1e48b..c891dac8f9 100644 --- a/backends/fs/ds/ds-fs.h +++ b/backends/fs/ds/ds-fs.h @@ -171,16 +171,10 @@ struct fileHandle { class DSFileStream : public Common::SeekableReadStream, public Common::WriteStream, public Common::NonCopyable { protected: - enum { - WRITE_BUFFER_SIZE = 512 - }; /** File handle to the actual file. */ void *_handle; - char _writeBuffer[WRITE_BUFFER_SIZE]; - int _writeBufferPos; - public: /** * Given a path, invokes fopen on that path and wrap the result in a |