}
GetFromBuffer(&c, 1);
-
+
m_stream->m_lastcount = 1;
return c;
}
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.
return wxInvalidOffset;
pos += GetIntPosition();
-
+
if (m_mode == read && m_flushable)
pos -= GetLastAccess();
-
+
return pos;
}
/* Why is this done? RR. */
if (m_buffer_end == m_buffer_pos && m_flushable)
FillBuffer();
-
+
return m_buffer_end-m_buffer_pos;
}
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 */
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;
}
char *ptrback = AllocSpaceWBack(bufsize);
if (!ptrback)
return 0;
-
+
memcpy(ptrback, buf, bufsize);
return bufsize;
}
char *buf = (char *)buffer;
size_t retsize = GetWBack(buf, size);
- if (retsize == size)
+ if (retsize == size)
{
m_lastcount = size;
m_lasterror = wxStream_NOERROR;
{
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();
{
/* 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;
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;
}
// --------------------
m_currentPos = m_lastcount + pos;
else
m_currentPos += pos;
-
+
if (m_currentPos > m_lastcount) m_lastcount = m_currentPos;
-
+
return m_currentPos;
}
{
return m_currentPos;
}
-
+
// ----------------------------------------------------------------------------
// wxFilterInputStream
// ----------------------------------------------------------------------------
retsize = GetWBack(buf, size);
m_lastcount = retsize;
- if (retsize == size)
+ if (retsize == size)
{
m_lasterror = wxStream_NOERROR;
return *this;