X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/adc350786ef18378de54410646ef6c83ce985158..109c7768eb46ccbb45adc1c409fe8f6b7d799e2f:/src/common/stream.cpp diff --git a/src/common/stream.cpp b/src/common/stream.cpp index 88a8ccc790..957dd933fe 100644 --- a/src/common/stream.cpp +++ b/src/common/stream.cpp @@ -613,9 +613,21 @@ off_t wxStreamBuffer::Seek(off_t pos, wxSeekMode mode) off_t wxStreamBuffer::Tell() const { - off_t pos = m_stream->OnSysTell(); - if ( pos == wxInvalidOffset ) - return wxInvalidOffset; + off_t pos; + + // only ask the stream for position if we have a real stream and not a + // dummy one which we created ourselves, otherwise we'd call + // wxStream::OnSysTell() which would always return wxInvalidOffset + if ( !m_destroystream ) + { + pos = m_stream->OnSysTell(); + if ( pos == wxInvalidOffset ) + return wxInvalidOffset; + } + else // no associated stream + { + pos = 0; + } pos += GetIntPosition(); @@ -751,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()