+ wxCharBuffer tmp(len + 1);
+ if ( tmp )
+ {
+ m_input->Read(tmp.data(), len);
+ tmp.data()[len] = '\0';
+ ret = m_conv->cMB2WX(tmp.data());
+ }
+#else
+ wxStringBuffer buf(ret, len);
+ if ( buf )
+ m_input->Read(buf, len);
+#endif
+ }
+
+ return ret;
+}
+
+#if wxUSE_LONGLONG
+
+template <class T>
+static
+void DoReadLL(T *buffer, size_t size, wxInputStream *input, bool be_order)
+{
+ typedef T DataType;
+ unsigned char *pchBuffer = new unsigned char[size * 8];
+ // TODO: Check for overflow when size is of type uint and is > than 512m
+ input->Read(pchBuffer, size * 8);
+ size_t idx_base = 0;
+ if ( be_order )
+ {
+ for ( size_t uiIndex = 0; uiIndex != size; ++uiIndex )
+ {
+ buffer[uiIndex] = 0l;
+ for ( unsigned ui = 0; ui != 8; ++ui )
+ {
+ buffer[uiIndex] = buffer[uiIndex] * 256l +
+ DataType((unsigned long) pchBuffer[idx_base + ui]);
+ }
+
+ idx_base += 8;
+ }
+ }
+ else // little endian
+ {
+ for ( size_t uiIndex=0; uiIndex!=size; ++uiIndex )
+ {
+ buffer[uiIndex] = 0l;
+ for ( unsigned ui=0; ui!=8; ++ui )
+ buffer[uiIndex] = buffer[uiIndex] * 256l +
+ DataType((unsigned long) pchBuffer[idx_base + 7 - ui]);
+ idx_base += 8;
+ }
+ }
+ delete[] pchBuffer;
+}
+
+template <class T>
+static void DoWriteLL(const T *buffer, size_t size, wxOutputStream *output, bool be_order)
+{
+ typedef T DataType;
+ unsigned char *pchBuffer = new unsigned char[size * 8];
+ size_t idx_base = 0;
+ if ( be_order )
+ {
+ for ( size_t uiIndex = 0; uiIndex != size; ++uiIndex )
+ {
+ DataType i64 = buffer[uiIndex];
+ for ( unsigned ui = 0; ui != 8; ++ui )
+ {
+ pchBuffer[idx_base + 7 - ui] =
+ (unsigned char) (i64.GetLo() & 255l);
+ i64 >>= 8l;
+ }
+
+ idx_base += 8;
+ }
+ }
+ else // little endian
+ {
+ for ( size_t uiIndex=0; uiIndex != size; ++uiIndex )
+ {
+ DataType i64 = buffer[uiIndex];
+ for (unsigned ui=0; ui!=8; ++ui)
+ {
+ pchBuffer[idx_base + ui] =
+ (unsigned char) (i64.GetLo() & 255l);
+ i64 >>= 8l;
+ }
+
+ idx_base += 8;
+ }
+ }
+
+ // TODO: Check for overflow when size is of type uint and is > than 512m
+ output->Write(pchBuffer, size * 8);
+ delete[] pchBuffer;
+}
+
+#endif // wxUSE_LONGLONG
+
+#ifdef wxLongLong_t
+
+template <class T>
+static
+void DoReadI64(T *buffer, size_t size, wxInputStream *input, bool be_order)
+{
+ typedef T DataType;
+ unsigned char *pchBuffer = (unsigned char*) buffer;
+ // TODO: Check for overflow when size is of type uint and is > than 512m
+ input->Read(pchBuffer, size * 8);
+ if ( be_order )
+ {
+ for ( wxUint32 i = 0; i < size; i++ )
+ {
+ DataType v = wxUINT64_SWAP_ON_LE(*buffer);
+ *(buffer++) = v;
+ }
+ }
+ else // little endian
+ {
+ for ( wxUint32 i=0; i<size; i++ )
+ {
+ DataType v = wxUINT64_SWAP_ON_BE(*buffer);
+ *(buffer++) = v;
+ }
+ }
+}
+
+template <class T>
+static
+void DoWriteI64(const T *buffer, size_t size, wxOutputStream *output, bool be_order)
+{
+ typedef T DataType;
+ if ( be_order )
+ {
+ for ( size_t i = 0; i < size; i++ )
+ {
+ DataType i64 = wxUINT64_SWAP_ON_LE(*buffer);
+ buffer++;
+ output->Write(&i64, 8);
+ }
+ }
+ else // little endian
+ {
+ for ( size_t i=0; i < size; i++ )
+ {
+ DataType i64 = wxUINT64_SWAP_ON_BE(*buffer);
+ buffer++;
+ output->Write(&i64, 8);
+ }
+ }
+}
+
+#endif // wxLongLong_t
+
+
+#if wxHAS_INT64
+void wxDataInputStream::Read64(wxUint64 *buffer, size_t size)
+{
+#ifndef wxLongLong_t
+ DoReadLL(buffer, size, m_input, m_be_order);