From 40b9d63a3c7264e715a37332515680ae3c2f844d Mon Sep 17 00:00:00 2001 From: brain Date: Sun, 29 May 2005 19:59:47 +0000 Subject: Fixed to allow any form of linefeed git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1559 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/inspircd_io.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/inspircd_io.cpp b/src/inspircd_io.cpp index c3f725c14..96a751d65 100644 --- a/src/inspircd_io.cpp +++ b/src/inspircd_io.cpp @@ -286,6 +286,20 @@ std::string ConfProcess(char* buffer, long linenumber, std::stringstream* errors return parsedata; } +int fgets_safe(char* buffer, size_t maxsize, FILE* &file) +{ + char c_read = '\0'; + unsigned int bufptr = 0; + while ((!feof(file)) && (c_read != '\n') && (c_read != '\r') && (bufptr < maxsize)) + { + c_read = fgetc(file); + if ((c_read != '\n') && (c_read != '\r')) + buffer[bufptr++] = c_read; + } + buffer[bufptr] = '\0'; + return bufptr; +} + bool LoadConf(const char* filename, std::stringstream *target, std::stringstream* errorstream) { target->str(""); @@ -315,7 +329,7 @@ bool LoadConf(const char* filename, std::stringstream *target, std::stringstream { while (!feof(conf)) { - if (fgets(buffer, MAXBUF, conf)) + if (fgets_safe(buffer, MAXBUF, conf)) { if ((!feof(conf)) && (buffer) && (strlen(buffer))) { -- cgit v1.2.3