X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6319afe332dd1b386cf05902af86d3b5df6692f7..6842d18650b487249b4ae29d0d7e17231b24cde8:/src/common/stream.cpp?ds=inline diff --git a/src/common/stream.cpp b/src/common/stream.cpp index 5c7ba37d3f..ed5190b1dc 100644 --- a/src/common/stream.cpp +++ b/src/common/stream.cpp @@ -27,9 +27,9 @@ #if wxUSE_STREAMS #include -#include -#include -#include +#include "wx/stream.h" +#include "wx/datstrm.h" +#include "wx/objstrm.h" #define BUF_TEMP_SIZE 10000 @@ -165,10 +165,17 @@ void wxStreamBuffer::PutToBuffer(const void *buffer, size_t size) size_t s_toput = m_buffer_end-m_buffer_pos; if (s_toput < size && !m_fixed) { - m_buffer_start = (char *)realloc(m_buffer_start, m_buffer_size+size); - // I round a bit - m_buffer_size += size; - m_buffer_end = m_buffer_start+m_buffer_size; + if (!m_buffer_start) + SetBufferIO(size); + else { + size_t delta = m_buffer_pos-m_buffer_start; + + m_buffer_start = (char *)realloc(m_buffer_start, m_buffer_size+size); + m_buffer_pos = m_buffer_start + delta; + // I round a bit + m_buffer_size += size; + m_buffer_end = m_buffer_start+m_buffer_size; + } s_toput = size; } if (s_toput > size) @@ -306,7 +313,7 @@ size_t wxStreamBuffer::Write(const void *buffer, size_t size) // ------------------ m_stream->m_lasterror = wxStream_NOERROR; - if (!m_buffer_size) + if (!m_buffer_size && m_fixed) return (m_stream->m_lastcount = m_stream->OnSysWrite(buffer, size)); // ------------------ @@ -320,7 +327,9 @@ size_t wxStreamBuffer::Write(const void *buffer, size_t size) // First case: the buffer to write is larger than the stream buffer, // we split it - if (size > buf_left) { + // NB: If stream buffer isn't fixed (as for wxMemoryOutputStream), + // we always go to the second case. + if (size > buf_left && m_fixed) { PutToBuffer(buffer, buf_left); size -= buf_left; buffer = (char *)buffer + buf_left; // ANSI C++ violation. @@ -480,7 +489,9 @@ wxInputStream::~wxInputStream() char *wxInputStream::AllocSpaceWBack(size_t needed_size) { char *temp_b; + size_t old_size; + old_size = m_wbacksize; m_wbacksize += needed_size; if (!m_wback) @@ -491,8 +502,10 @@ char *wxInputStream::AllocSpaceWBack(size_t needed_size) if (!temp_b) return NULL; m_wback = temp_b; + + memmove(m_wback+needed_size, m_wback, old_size); - return (char *)(m_wback+(m_wbacksize-needed_size)); + return (char *)(m_wback); } size_t wxInputStream::GetWBack(char *buf, size_t bsize) @@ -593,6 +606,10 @@ wxInputStream& wxInputStream::Read(wxOutputStream& stream_out) off_t wxInputStream::SeekI(off_t pos, wxSeekMode mode) { + //should be check and improve, just to remove a slight bug ! + // I don't know whether it should be put as well in wxFileInputStream::OnSysSeek ? + if (m_lasterror==wxSTREAM_EOF) m_lasterror=wxSTREAM_NOERROR; + return OnSysSeek(pos, mode); } @@ -677,7 +694,7 @@ size_t wxCountingOutputStream::GetSize() const return m_lastcount; } -size_t wxCountingOutputStream::OnSysWrite(const void *buffer, size_t size) +size_t wxCountingOutputStream::OnSysWrite(const void *WXUNUSED(buffer), size_t size) { m_currentPos += size; if (m_currentPos > m_lastcount) m_lastcount = m_currentPos;