From a2b28e922bd4037e60c1a29bb7648eeb38402d8c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 29 Apr 2000 18:07:33 +0000 Subject: [PATCH] don't use wxFile::Eof() (for the reasons explained in the docs now :-) in wxTextFile - this allows it to be used with FIFOs git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7317 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/file.tex | 5 ++++- src/common/textfile.cpp | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/latex/wx/file.tex b/docs/latex/wx/file.tex index a00d7d09d9..c348256d25 100644 --- a/docs/latex/wx/file.tex +++ b/docs/latex/wx/file.tex @@ -160,7 +160,10 @@ in the file. Note also that this function doesn't work on unseekable file descriptors (examples include pipes, terminals and sockets under Unix) and an attempt to -use it will result in an error message in such case. +use it will result in an error message in such case. So, to read the entire +file into memory, you should write a loop which uses +\helpref{Read}{wxfileread} repeatedly and tests its return condition instead +of using Eof() as this will not work for special files under Unix. \membersection{wxFile::Exists}\label{wxfileexists} diff --git a/src/common/textfile.cpp b/src/common/textfile.cpp index 0b07d15b5b..fc3c622d64 100644 --- a/src/common/textfile.cpp +++ b/src/common/textfile.cpp @@ -282,7 +282,7 @@ bool wxTextFile::Read() char ch, chLast = '\0'; char buf[1024]; int n, nRead; - while ( !m_file.Eof() ) { + do { nRead = m_file.Read(buf, WXSIZEOF(buf)); if ( nRead == wxInvalidOffset ) { // read error (error message already given in wxFile::Read) @@ -325,7 +325,7 @@ bool wxTextFile::Read() } } } - } + } while ( nRead == WXSIZEOF(buf) ); // anything in the last line? if ( !str.IsEmpty() ) {