From: Vadim Zeitlin Date: Thu, 3 Mar 2005 13:46:42 +0000 (+0000) Subject: fixed bug in ReadAll(): it always returned error when reading files with DOS EOLs... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/f281f29f89a06dffd4a9357623e4d7a247419dc9?hp=dbbd41ae33856d6c9dfe6c2bf19151b1ac0a18eb fixed bug in ReadAll(): it always returned error when reading files with DOS EOLs in text mode git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32577 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/ffile.cpp b/src/common/ffile.cpp index 42a43f2cb4..78cf20c8c3 100644 --- a/src/common/ffile.cpp +++ b/src/common/ffile.cpp @@ -115,14 +115,20 @@ bool wxFFile::ReadAll(wxString *str, wxMBConv& conv) const size_t fileLen = Length(); wxCharBuffer buf(fileLen + 1); - if ( (fread(buf.data(), sizeof(char), fileLen, m_fp) < fileLen) || Error() ) + + // note that realLen may be less than fileLen for text files with DOS EOLs + // ('\r's get dropped by CRT when reading which means that we have + // realLen = fileLen - numOfLinesInTheFile) + size_t realLen = fread(buf.data(), sizeof(char), fileLen, m_fp); + + if ( Error() ) { wxLogSysError(_("Read error on file '%s'"), m_name.c_str()); return false; } - buf.data()[fileLen] = 0; + buf.data()[realLen] = 0; *str = wxString(buf, conv); return true;