X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2a040d3f0708e859f812cc10ed1b391d4ca89a07..1363811bb6338fb0dad6c16cfa47f46fb1eb3b99:/src/common/stream.cpp diff --git a/src/common/stream.cpp b/src/common/stream.cpp index 8754cc7c3a..305c8c5128 100644 --- a/src/common/stream.cpp +++ b/src/common/stream.cpp @@ -82,6 +82,9 @@ size_t wxStreamBuffer::WriteBack(const char *buf, size_t bufsize) { char *ptrback; + if (m_mode != read) + return 0; + ptrback = AllocSpaceWBack(bufsize); if (!ptrback) return 0; @@ -137,6 +140,7 @@ void wxStreamBuffer::SetBufferIO(size_t bufsize) void wxStreamBuffer::ResetBuffer() { m_stream->m_lasterror = wxStream_NOERROR; + m_stream->m_lastcount = 0; if (m_mode == read) m_buffer_pos = m_buffer_end; else @@ -157,7 +161,7 @@ char *wxStreamBuffer::AllocSpaceWBack(size_t needed_size) if (!temp_b) return NULL; m_wback = temp_b; - printf("Buffer(0x%x)->Write: 0x%x, %d\n", this, m_wback, m_wbacksize); + return (char *)(m_wback+(m_wbacksize-needed_size)); } @@ -165,7 +169,6 @@ size_t wxStreamBuffer::GetWBack(char *buf, size_t bsize) { size_t s_toget = m_wbacksize-m_wbackcur; - printf("Buffer(0x%x): 0x%x, %d\n", this, m_wback, m_wbacksize); if (bsize < s_toget) s_toget = bsize; @@ -248,8 +251,8 @@ void wxStreamBuffer::PutChar(char c) return; } - if (!GetDataLeft() && !FlushBuffer()) { - CHECK_ERROR(wxStream_READ_ERR); + if (GetDataLeft() == 0 && !FlushBuffer()) { + CHECK_ERROR(wxStream_WRITE_ERR); return; } @@ -282,6 +285,9 @@ size_t wxStreamBuffer::Read(void *buffer, size_t size) { wxASSERT(m_stream != NULL); + if (m_mode == write) + return 0; + // ------------------ // Buffering disabled // ------------------ @@ -331,6 +337,9 @@ size_t wxStreamBuffer::Read(wxStreamBuffer *s_buf) char buf[BUF_TEMP_SIZE]; size_t s = 0, bytes_read = BUF_TEMP_SIZE; + if (m_mode == write) + return 0; + while (bytes_read == BUF_TEMP_SIZE) { bytes_read = Read(buf, bytes_read); bytes_read = s_buf->Write(buf, bytes_read); @@ -343,6 +352,9 @@ size_t wxStreamBuffer::Write(const void *buffer, size_t size) { wxASSERT(m_stream != NULL); + if (m_mode == read) + return 0; + // ------------------ // Buffering disabled // ------------------ @@ -389,6 +401,9 @@ size_t wxStreamBuffer::Write(wxStreamBuffer *sbuf) char buf[BUF_TEMP_SIZE]; size_t s = 0, bytes_count = BUF_TEMP_SIZE, b_count2; + if (m_mode == read) + return 0; + while (bytes_count == BUF_TEMP_SIZE) { b_count2 = sbuf->Read(buf, bytes_count); bytes_count = Write(buf, b_count2);