mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Remove some code duplications and move functions into classes
This removes ReadFile(), WriteFile(), ReadLine(), Lower() and Upper() from Utils.h and adds CFile::ReadFile(). The biggest part of this patch fixes modules to use CFile and CString instead of these global functions. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1311 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
@@ -326,6 +326,30 @@ bool CFile::ReadLine(CString& sData, const CString & sDelimiter) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CFile::ReadFile(CString& sData, size_t iMaxSize) {
|
||||
char buff[4096];
|
||||
size_t iBytesRead = 0;
|
||||
|
||||
sData.clear();
|
||||
|
||||
while (iBytesRead < iMaxSize) {
|
||||
int iBytes = Read(buff, sizeof(buff));
|
||||
|
||||
if (iBytes < 0)
|
||||
// Error
|
||||
return false;
|
||||
|
||||
if (iBytes == 0)
|
||||
// EOF
|
||||
return true;
|
||||
|
||||
sData.append(buff, iBytes);
|
||||
}
|
||||
|
||||
// Buffer limit reached
|
||||
return false;
|
||||
}
|
||||
|
||||
int CFile::Write(const char *pszBuffer, u_int iBytes) {
|
||||
if (m_iFD == -1) {
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user