X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/915a955caffbbc0982cc4a1952113bcd09d6d009..1d7609197ed33bc76c8212705f305fe7cc33d62f:/src/common/stream.cpp diff --git a/src/common/stream.cpp b/src/common/stream.cpp index c3c66e9e50..a1d8cb04cc 100644 --- a/src/common/stream.cpp +++ b/src/common/stream.cpp @@ -763,22 +763,27 @@ size_t wxInputStream::GetWBack(void *buf, size_t bsize) size_t wxInputStream::Ungetch(const void *buf, size_t bufsize) { + if ( m_lasterror != wxSTREAM_NO_ERROR && m_lasterror != wxSTREAM_EOF ) + { + // can't operate on this stream until the error is cleared + return 0; + } + char *ptrback = AllocSpaceWBack(bufsize); if (!ptrback) return 0; + // Eof() shouldn't return TRUE any longer + if ( m_lasterror == wxSTREAM_EOF ) + m_lasterror = wxSTREAM_NO_ERROR; + memcpy(ptrback, buf, bufsize); return bufsize; } bool wxInputStream::Ungetch(char c) { - void *ptrback = AllocSpaceWBack(1); - if (!ptrback) - return FALSE; - - *(char *)ptrback = c; - return TRUE; + return Ungetch(&c, sizeof(char)) != 0; } char wxInputStream::GetC() @@ -790,17 +795,30 @@ char wxInputStream::GetC() wxInputStream& wxInputStream::Read(void *buf, size_t size) { - size_t retsize = GetWBack(buf, size); - if (retsize == size) + char *p = (char *)buf; + m_lastcount = 0; + + size_t read = GetWBack(buf, size); + for ( ;; ) { - m_lastcount = size; - m_lasterror = wxStream_NOERROR; - return *this; + size -= read; + m_lastcount += read; + p += read; + + if ( !size ) + { + // we read the requested amount of data + break; + } + + read = OnSysRead(buf, size); + if ( !read ) + { + // no more data available + break; + } } - size -= retsize; - buf = (char *)buf + retsize; - m_lastcount = OnSysRead(buf, size) + retsize; return *this; }