+size_t wxInputStream::Ungetch(const void *buf, size_t bufsize)
+{
+ if ( m_lasterror != wxSTREAM_NO_ERROR && m_lasterror != wxSTREAM_EOF )
+ {
+ // can't operate on this stream until the error is cleared
+ return 0;
+ }
+
+ char *ptrback = AllocSpaceWBack(bufsize);
+ if (!ptrback)
+ return 0;
+
+ // Eof() shouldn't return true any longer
+ if ( m_lasterror == wxSTREAM_EOF )
+ m_lasterror = wxSTREAM_NO_ERROR;
+
+ memcpy(ptrback, buf, bufsize);
+ return bufsize;
+}
+
+bool wxInputStream::Ungetch(char c)
+{
+ return Ungetch(&c, sizeof(c)) != 0;
+}
+
+char wxInputStream::GetC()
+{
+ char c;
+ Read(&c, sizeof(c));
+ return c;
+}
+
+wxInputStream& wxInputStream::Read(void *buf, size_t size)
+{
+ char *p = (char *)buf;
+ m_lastcount = 0;
+
+ size_t read = GetWBack(buf, size);
+ for ( ;; )
+ {
+ size -= read;
+ m_lastcount += read;
+ p += read;
+
+ if ( !size )
+ {
+ // we read the requested amount of data
+ break;
+ }
+
+ if ( p != buf && !CanRead() )
+ {
+ // we have already read something and we would block in OnSysRead()
+ // now: don't do it but return immediately
+ break;
+ }
+
+ read = OnSysRead(p, size);
+ if ( !read )
+ {
+ // no more data available
+ break;
+ }
+ }
+
+ return *this;
+}
+
+char wxInputStream::Peek()
+{
+ char c;
+ Read(&c, sizeof(c));
+ if (m_lasterror == wxSTREAM_NO_ERROR)
+ {
+ Ungetch(c);
+ return c;
+ }
+
+ return 0;
+}