From 4f6d72fe49fa656899daeb06a4d347b033351e6d Mon Sep 17 00:00:00 2001 From: psychon Date: Tue, 31 Mar 2009 07:52:24 +0000 Subject: [PATCH] Minor cleanup to CFile::ReadLine(), no behavior changes (I hope) git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1459 726aef4b-f618-498e-8847-2d620e286838 --- FileUtils.cpp | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/FileUtils.cpp b/FileUtils.cpp index ffda3cf3..77e1aeea 100644 --- a/FileUtils.cpp +++ b/FileUtils.cpp @@ -299,14 +299,13 @@ int CFile::Read(char *pszBuffer, int iBytes) { bool CFile::ReadLine(CString& sData, const CString & sDelimiter) { char buff[4096]; + int iBytes; if (m_iFD == -1) { return false; } - bool bEOF = false; - - while (!bEOF) { + do { CString::size_type iFind = m_sBuffer.find(sDelimiter); if (iFind != CString::npos) { // We found a line, return it @@ -315,23 +314,12 @@ bool CFile::ReadLine(CString& sData, const CString & sDelimiter) { return true; } - int iBytes = read(m_iFD, buff, sizeof(buff)); + iBytes = read(m_iFD, buff, sizeof(buff)); - switch(iBytes) { - case -1: { - bEOF = true; - break; - } - case 0: { - bEOF = true; - break; - } - default: { - m_sBuffer.append(buff, iBytes); - break; - } + if (iBytes > 0) { + m_sBuffer.append(buff, iBytes); } - } + } while (iBytes > 0); // We are at the end of the file or an error happened