char *wxInputStream::AllocSpaceWBack(size_t needed_size)
{
char *temp_b;
- size_t old_size;
+ size_t toget;
- old_size = m_wbacksize;
- m_wbacksize += needed_size;
+ /* get number of bytes left from previous wback buffer */
+ toget = m_wbacksize - m_wbackcur;
- if (!m_wback)
- temp_b = (char *)malloc(m_wbacksize);
- else
- temp_b = (char *)realloc(m_wback, m_wbacksize);
+ /* allocate a buffer large enough to hold prev + new data */
+ temp_b = (char *) malloc(needed_size + toget);
if (!temp_b)
- return (char*)NULL;
+ return NULL;
+
+ /* copy previous data (and free old buffer) if needed */
+ if (m_wback)
+ {
+ memmove(temp_b + needed_size, m_wback + m_wbackcur, toget);
+ free(m_wback);
+ }
+
+ /* done */
m_wback = temp_b;
+ m_wbackcur = 0;
+ m_wbacksize = needed_size + toget;
- memmove(m_wback+needed_size, m_wback, old_size);
-
- return (char *)(m_wback);
+ return (char *) m_wback;
}
size_t wxInputStream::GetWBack(char *buf, size_t bsize)
m_lasterror = wxStream_NOERROR;
return *this;
}
- size -= retsize;
- buf += retsize;
+ size -= retsize;
+ buf += retsize;
- m_lastcount = OnSysRead(buf, size);
+ m_lastcount = OnSysRead(buf, size) + retsize;
return *this;
}
{
}
+void wxOutputStream::PutC(char c)
+{
+ Write((void *) &c, 1);
+}
+
wxOutputStream& wxOutputStream::Write(const void *buffer, size_t size)
{
m_lastcount = OnSysWrite(buffer, size);
wxBufferedInputStream::~wxBufferedInputStream()
{
+ off_t unused_bytes=m_i_streambuf->GetBufferPos()-m_i_streambuf->GetBufferEnd();
+ m_parent_i_stream->SeekI(unused_bytes,wxFromCurrent);
+
delete m_i_streambuf;
}