wxDELETEA(m_buffer_start);
if (!bufsize) {
- m_buffer_start = NULL;
- m_buffer_end = NULL;
- m_buffer_pos = NULL;
+ m_buffer_start = (char*)NULL;
+ m_buffer_end = (char*)NULL;
+ m_buffer_pos = (char*)NULL;
m_buffer_size = 0;
return;
}
last_access = GetLastAccess();
if (!m_flushable) {
- diff = pos + GetIntPosition();
+ switch (mode) {
+ case wxFromStart: diff = pos; break;
+ case wxFromCurrent: diff = pos + GetIntPosition(); break;
+ case wxFromEnd: diff = pos + last_access; break;
+ default: return wxInvalidOffset;
+ }
if (diff < 0 || diff > last_access)
return wxInvalidOffset;
SetIntPosition(diff);
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 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;
}
off_t wxInputStream::SeekI(off_t pos, wxSeekMode mode)
{
- //should be check and improve, just to remove a slight bug !
+ // 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) m_lasterror=wxSTREAM_NOERROR;
+ 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 SeeI() to one
+ // one position, unread some bytes there, SeekI() to another position
+ // and the data would be corrupted.
+ if (m_wback) {
+ free(m_wback);
+ m_wback = (char*) NULL;
+ m_wbacksize = 0;
+ m_wbackcur = 0;
+ }
return OnSysSeek(pos, mode);
}
{
}
+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;
}
wxBufferedOutputStream::~wxBufferedOutputStream()
{
+ Sync();
delete m_o_streambuf;
}
off_t wxBufferedOutputStream::SeekO(off_t pos, wxSeekMode mode)
{
+ Sync();
return m_o_streambuf->Seek(pos, mode);
}