// Modified by: VZ (23.11.00) to fix realloc()ing new[]ed memory,
// general code review
// Created: 11/07/98
-// RCS-ID: $Id$
// Copyright: (c) Guilhem Lavaux
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
{
char* buffer = static_cast<char*>(buffer_);
- m_lastcount = 0;
+ size_t totalCount = 0;
for ( ;; )
{
if ( !lastCount )
break;
- m_lastcount += lastCount;
+ totalCount += lastCount;
// ... Or if an error occurred on the stream.
if ( !IsOk() )
// "==" test, but be safe and avoid overflowing size even in case of
// bugs in LastRead()).
if ( lastCount >= size )
- return true;
+ {
+ size = 0;
+ break;
+ }
// Advance the buffer before trying to read the rest of data.
size -= lastCount;
buffer += lastCount;
}
- return false;
+ m_lastcount = totalCount;
+
+ return size == 0;
}
wxFileOffset wxInputStream::SeekI(wxFileOffset pos, wxSeekMode mode)
// This exactly mirrors ReadAll(), see there for more comments.
const char* buffer = static_cast<const char*>(buffer_);
- m_lastcount = 0;
+ size_t totalCount = 0;
for ( ;; )
{
if ( !lastCount )
break;
- m_lastcount += lastCount;
+ totalCount += lastCount;
if ( !IsOk() )
break;
if ( lastCount >= size )
- return true;
+ {
+ size = 0;
+ break;
+ }
size -= lastCount;
buffer += lastCount;
}
- return false;
+ m_lastcount = totalCount;
+ return size == 0;
}
wxFileOffset wxOutputStream::TellO() const
wxCountingOutputStream::wxCountingOutputStream ()
{
- m_currentPos = 0;
+ m_currentPos =
+ m_lastPos = 0;
}
wxFileOffset wxCountingOutputStream::GetLength() const
{
- return m_lastcount;
+ return m_lastPos;
}
size_t wxCountingOutputStream::OnSysWrite(const void *WXUNUSED(buffer),
size_t size)
{
m_currentPos += size;
- if (m_currentPos > m_lastcount)
- m_lastcount = m_currentPos;
+ if ( m_currentPos > m_lastPos )
+ m_lastPos = m_currentPos;
- return m_currentPos;
+ return size;
}
wxFileOffset wxCountingOutputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode)
break;
case wxFromEnd:
- new_pos = m_lastcount + new_pos;
- wxCHECK_MSG( (wxFileOffset)new_pos == (wxFileOffset)(m_lastcount + pos), wxInvalidOffset, wxT("huge position not supported") );
+ new_pos += m_lastPos;
+ wxCHECK_MSG( (wxFileOffset)new_pos == (wxFileOffset)(m_lastPos + pos), wxInvalidOffset, wxT("huge position not supported") );
break;
case wxFromCurrent:
- new_pos = m_currentPos + new_pos;
+ new_pos += m_currentPos;
wxCHECK_MSG( (wxFileOffset)new_pos == (wxFileOffset)(m_currentPos + pos), wxInvalidOffset, wxT("huge position not supported") );
break;
m_currentPos = new_pos;
- if (m_currentPos > m_lastcount)
- m_lastcount = m_currentPos;
+ if ( m_currentPos > m_lastPos )
+ m_lastPos = m_currentPos;
return m_currentPos;
}