X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/51566b0bc96dc1b15a11cc7878504789bd7cf16e..1978421a6d8b81c1f8a961da4b8ddf544fec7b1b:/src/stc/stc.cpp.in diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in index 8952840b6c..60360d977e 100644 --- a/src/stc/stc.cpp.in +++ b/src/stc/stc.cpp.in @@ -325,23 +325,29 @@ bool wxStyledTextCtrl::SaveFile(const wxString& filename) bool wxStyledTextCtrl::LoadFile(const wxString& filename) { + bool success = false; wxFile file(filename, wxFile::read); - if (!file.IsOpened()) - return FALSE; - - wxString contents; - off_t len = file.Length(); - - wxChar *buf = contents.GetWriteBuf(len); - bool success = (file.Read(buf, len) == len); - contents.UngetWriteBuf(); - - if (success) + if (file.IsOpened()) { - SetText(contents); - EmptyUndoBuffer(); - SetSavePoint(); + wxString contents; + off_t len = file.Length(); + + if (len > 0) + { + wxChar *buf = contents.GetWriteBuf(len); + success = (file.Read(buf, len) == len); + contents.UngetWriteBuf(); + } + else + success = true; // empty file is ok + + if (success) + { + SetText(contents); + EmptyUndoBuffer(); + SetSavePoint(); + } } return success;