X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c7a9fa36e4544fd9b7647d59c1108b49f368f243..28be2e8a170979d476a5ea4f585505b8a2f5af27:/src/common/stream.cpp?ds=sidebyside diff --git a/src/common/stream.cpp b/src/common/stream.cpp index 16ab8391cb..310f1ee7e0 100644 --- a/src/common/stream.cpp +++ b/src/common/stream.cpp @@ -236,7 +236,7 @@ char wxStreamBuffer::GetChar() } GetFromBuffer(&c, 1); - + m_stream->m_lastcount = 1; return c; } @@ -262,7 +262,7 @@ size_t wxStreamBuffer::Read(void *buffer, size_t size) size_t buf_left, orig_size = size; while (size > 0) { - buf_left = GetDataLeft(); + buf_left = GetDataLeft(); // First case: the requested buffer is larger than the stream buffer, // we split it. @@ -428,10 +428,10 @@ off_t wxStreamBuffer::Tell() const return wxInvalidOffset; pos += GetIntPosition(); - + if (m_mode == read && m_flushable) pos -= GetLastAccess(); - + return pos; } @@ -440,7 +440,7 @@ size_t wxStreamBuffer::GetDataLeft() /* Why is this done? RR. */ if (m_buffer_end == m_buffer_pos && m_flushable) FillBuffer(); - + return m_buffer_end-m_buffer_pos; } @@ -494,6 +494,22 @@ wxInputStream::~wxInputStream() free(m_wback); } +bool wxInputStream::Eof() const +{ + wxInputStream *self = (wxInputStream *)this; // const_cast + + char c; + self->Read(&c, 1); + if ( GetLastError() == wxSTREAM_EOF ) + { + return TRUE; + } + + self->Ungetch(c); + + return FALSE; +} + char *wxInputStream::AllocSpaceWBack(size_t needed_size) { /* get number of bytes left from previous wback buffer */ @@ -533,14 +549,14 @@ size_t wxInputStream::GetWBack(char *buf, size_t bsize) memcpy(buf, (m_wback+m_wbackcur), s_toget); m_wbackcur += s_toget; - if (m_wbackcur == m_wbacksize) + if (m_wbackcur == m_wbacksize) { free(m_wback); m_wback = (char *)NULL; m_wbacksize = 0; m_wbackcur = 0; } - + return s_toget; } @@ -549,7 +565,7 @@ size_t wxInputStream::Ungetch(const void *buf, size_t bufsize) char *ptrback = AllocSpaceWBack(bufsize); if (!ptrback) return 0; - + memcpy(ptrback, buf, bufsize); return bufsize; } @@ -576,7 +592,7 @@ wxInputStream& wxInputStream::Read(void *buffer, size_t size) char *buf = (char *)buffer; size_t retsize = GetWBack(buf, size); - if (retsize == size) + if (retsize == size) { m_lastcount = size; m_lasterror = wxStream_NOERROR; @@ -593,21 +609,21 @@ char wxInputStream::Peek() { char c; Read(&c, 1); - if (m_lasterror == wxStream_NOERROR) + if (m_lasterror == wxStream_NOERROR) { Ungetch(c); return c; } - + return 0; } wxInputStream& wxInputStream::Read(wxOutputStream& stream_out) { - char buf[BUF_TEMP_SIZE]; + char buf[BUF_TEMP_SIZE]; size_t bytes_read = BUF_TEMP_SIZE; - while (bytes_read == BUF_TEMP_SIZE) + while (bytes_read == BUF_TEMP_SIZE) { bytes_read = Read(buf, bytes_read).LastRead(); bytes_read = stream_out.Write(buf, bytes_read).LastWrite(); @@ -619,14 +635,20 @@ off_t wxInputStream::SeekI(off_t pos, wxSeekMode mode) { /* Should be check and improve, just to remove a slight bug ! I don't know whether it should be put as well in wxFileInputStream::OnSysSeek ? */ - if (m_lasterror==wxSTREAM_EOF) + if (m_lasterror==wxSTREAM_EOF) m_lasterror=wxSTREAM_NOERROR; /* A call to SeekI() will automatically invalidate any previous call to Ungetch(), otherwise it would be possible to SeekI() to one one position, unread some bytes there, SeekI() to another position - and the data would be corrupted. */ - if (m_wback) + and the data would be corrupted. + + GRG: Could add code here to try to navigate within the wback + buffer if possible, but is it really needed? It would only work + when seeking in wxFromCurrent mode, else it would invalidate + anyway... + */ + if (m_wback) { free(m_wback); m_wback = (char*) NULL; @@ -639,7 +661,13 @@ off_t wxInputStream::SeekI(off_t pos, wxSeekMode mode) off_t wxInputStream::TellI() const { - return OnSysTell(); + /* GRG: Changed to make it compatible with the wback buffer */ + off_t pos = OnSysTell(); + + if (pos != wxInvalidOffset) + pos -= (m_wbacksize - m_wbackcur); + + return pos; } // -------------------- @@ -738,9 +766,9 @@ off_t wxCountingOutputStream::OnSysSeek(off_t pos, wxSeekMode mode) m_currentPos = m_lastcount + pos; else m_currentPos += pos; - + if (m_currentPos > m_lastcount) m_lastcount = m_currentPos; - + return m_currentPos; } @@ -748,7 +776,7 @@ off_t wxCountingOutputStream::OnSysTell() const { return m_currentPos; } - + // ---------------------------------------------------------------------------- // wxFilterInputStream // ---------------------------------------------------------------------------- @@ -816,7 +844,7 @@ wxInputStream& wxBufferedInputStream::Read(void *buffer, size_t size) retsize = GetWBack(buf, size); m_lastcount = retsize; - if (retsize == size) + if (retsize == size) { m_lasterror = wxStream_NOERROR; return *this;