X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d984207cc37ad70649b2392314fb9e42719506c3..5ebdc86afc95a60fbeb0b2a71c38dd26c8a1b0b4:/src/common/stream.cpp diff --git a/src/common/stream.cpp b/src/common/stream.cpp index e18c411643..2c10591517 100644 --- a/src/common/stream.cpp +++ b/src/common/stream.cpp @@ -494,23 +494,30 @@ wxInputStream::~wxInputStream() char *wxInputStream::AllocSpaceWBack(size_t needed_size) { char *temp_b; - size_t old_size; + size_t toget; - old_size = m_wbacksize; - m_wbacksize += needed_size; + /* get number of bytes left from previous wback buffer */ + toget = m_wbacksize - m_wbackcur; - if (!m_wback) - temp_b = (char *)malloc(m_wbacksize); - else - temp_b = (char *)realloc(m_wback, m_wbacksize); + /* allocate a buffer large enough to hold prev + new data */ + temp_b = (char *) malloc(needed_size + toget); if (!temp_b) - return (char*)NULL; + return NULL; + + /* copy previous data (and free old buffer) if needed */ + if (m_wback) + { + memmove(temp_b + needed_size, m_wback + m_wbackcur, toget); + free(m_wback); + } + + /* done */ m_wback = temp_b; + m_wbackcur = 0; + m_wbacksize = needed_size + toget; - memmove(m_wback+needed_size, m_wback, old_size); - - return (char *)(m_wback); + return (char *) m_wback; } size_t wxInputStream::GetWBack(char *buf, size_t bsize) @@ -578,10 +585,10 @@ wxInputStream& wxInputStream::Read(void *buffer, size_t size) m_lasterror = wxStream_NOERROR; return *this; } - size -= retsize; - buf += retsize; + size -= retsize; + buf += retsize; - m_lastcount = OnSysRead(buf, size); + m_lastcount = OnSysRead(buf, size) + retsize; return *this; } @@ -661,6 +668,11 @@ wxOutputStream::~wxOutputStream() { } +void wxOutputStream::PutC(char c) +{ + Write((void *) &c, 1); +} + wxOutputStream& wxOutputStream::Write(const void *buffer, size_t size) { m_lastcount = OnSysWrite(buffer, size); @@ -791,6 +803,9 @@ wxBufferedInputStream::wxBufferedInputStream(wxInputStream& s) wxBufferedInputStream::~wxBufferedInputStream() { + off_t unused_bytes=m_i_streambuf->GetBufferPos()-m_i_streambuf->GetBufferEnd(); + m_parent_i_stream->SeekI(unused_bytes,wxFromCurrent); + delete m_i_streambuf; } @@ -856,6 +871,7 @@ wxBufferedOutputStream::wxBufferedOutputStream(wxOutputStream& s) wxBufferedOutputStream::~wxBufferedOutputStream() { + Sync(); delete m_o_streambuf; } @@ -868,6 +884,7 @@ wxOutputStream& wxBufferedOutputStream::Write(const void *buffer, size_t size) off_t wxBufferedOutputStream::SeekO(off_t pos, wxSeekMode mode) { + Sync(); return m_o_streambuf->Seek(pos, mode); }