X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/926c550dc5347b149be7a5f02dd452865a8a524d..7482b22003c03f7aa3335aec271b5fcb48e2693d:/src/common/stream.cpp diff --git a/src/common/stream.cpp b/src/common/stream.cpp index fcd0e85e00..728d50b5cf 100644 --- a/src/common/stream.cpp +++ b/src/common/stream.cpp @@ -36,14 +36,16 @@ wxStreamBuffer::wxStreamBuffer(wxStreamBase& stream, BufMode mode) : m_buffer_start(NULL), m_buffer_end(NULL), m_buffer_pos(NULL), - m_buffer_size(0), m_fixed(TRUE), m_flushable(TRUE), m_stream(&stream), + m_buffer_size(0), m_wback(NULL), m_wbacksize(0), m_wbackcur(0), + m_fixed(TRUE), m_flushable(TRUE), m_stream(&stream), m_mode(mode), m_destroybuf(FALSE), m_destroystream(FALSE) { } wxStreamBuffer::wxStreamBuffer(BufMode mode) : m_buffer_start(NULL), m_buffer_end(NULL), m_buffer_pos(NULL), - m_buffer_size(0), m_fixed(TRUE), m_flushable(FALSE), m_stream(NULL), + m_buffer_size(0), m_wback(NULL), m_wbacksize(0), m_wbackcur(0), + m_fixed(TRUE), m_flushable(FALSE), m_stream(NULL), m_mode(mode), m_destroybuf(FALSE), m_destroystream(TRUE) { m_stream = new wxStreamBase(); @@ -61,10 +63,15 @@ wxStreamBuffer::wxStreamBuffer(const wxStreamBuffer& buffer) m_mode = buffer.m_mode; m_destroybuf = FALSE; m_destroystream = FALSE; + m_wback = NULL; + m_wbacksize = 0; + m_wbackcur = 0; } wxStreamBuffer::~wxStreamBuffer() { + if (m_wback) + free(m_wback); if (m_destroybuf) wxDELETEA(m_buffer_start); if (m_destroystream) @@ -129,6 +136,7 @@ void wxStreamBuffer::SetBufferIO(size_t bufsize) void wxStreamBuffer::ResetBuffer() { + m_stream->m_lasterror = wxStream_NOERROR; if (m_mode == read) m_buffer_pos = m_buffer_end; else @@ -148,7 +156,9 @@ char *wxStreamBuffer::AllocSpaceWBack(size_t needed_size) if (!temp_b) return NULL; - return (char *)((size_t)m_wback+(m_wbacksize-needed_size)); + m_wback = temp_b; + + return (char *)(m_wback+(m_wbacksize-needed_size)); } size_t wxStreamBuffer::GetWBack(char *buf, size_t bsize) @@ -275,6 +285,7 @@ size_t wxStreamBuffer::Read(void *buffer, size_t size) // Buffering disabled // ------------------ + m_stream->m_lasterror = wxStream_NOERROR; m_stream->m_lastcount = GetWBack((char *)buffer, size); size -= m_stream->m_lastcount; if (size == 0) @@ -335,6 +346,7 @@ size_t wxStreamBuffer::Write(const void *buffer, size_t size) // Buffering disabled // ------------------ + m_stream->m_lasterror = wxStream_NOERROR; if (!m_buffer_size) return (m_stream->m_lastcount = m_stream->OnSysWrite(buffer, size)); @@ -374,15 +386,13 @@ size_t wxStreamBuffer::Write(const void *buffer, size_t size) size_t wxStreamBuffer::Write(wxStreamBuffer *sbuf) { char buf[BUF_TEMP_SIZE]; - size_t s = 0, bytes_count = BUF_TEMP_SIZE; - size_t s_size; + size_t s = 0, bytes_count = BUF_TEMP_SIZE, b_count2; while (bytes_count == BUF_TEMP_SIZE) { - s_size = (sbuf->GetDataLeft() < GetDataLeft()) ? sbuf->GetDataLeft() : GetDataLeft(); - if (s_size < bytes_count) - bytes_count = s_size; - bytes_count = sbuf->Read(buf, bytes_count); - bytes_count = Write(buf, bytes_count); + b_count2 = sbuf->Read(buf, bytes_count); + bytes_count = Write(buf, b_count2); + if (b_count2 > bytes_count) + sbuf->WriteBack(buf+bytes_count, b_count2-bytes_count); s += bytes_count; } return s;