- wxASSERT( m_file.IsOpened() &&
- (m_file.GetKind() != wxFILE_KIND_DISK || m_file.Tell() == 0) );
-
- static const size_t BUF_SIZE = 1024;
-#if wxUSE_UNICODE
- static const size_t NUL_SIZE = 4;
-#else
- static const size_t NUL_SIZE = 1;
-#endif
-
- char buf[BUF_SIZE + NUL_SIZE];
- wxChar chLast = '\0';
- wxString str;
-
- for ( ;; )
+ wxASSERT( m_file.IsOpened() && m_file.Tell() == 0 );
+
+ // read the entire file in memory: this is not the most efficient thing to
+ // do but there is no good way to avoid it in Unicode build because if we
+ // read the file block by block we can't convert each block to Unicode
+ // separately (the last multibyte char in the block might be only partially
+ // read and so the conversion would fail) and, as the file contents is kept
+ // in memory by wxTextFile anyhow, it shouldn't be a big problem to read
+ // the file entirely
+ const size_t bufSize = (size_t)(m_file.Length() + 4 /* for trailing NULs */ );
+ size_t bufPos = 0;
+ wxCharBuffer buf(bufSize - 1 /* it adds 1 internally */);
+
+ char block[1024];
+ for ( bool eof = false; !eof; )