summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/SystemTools.cxx
diff options
context:
space:
mode:
authorKen Martin <ken.martin@kitware.com>2007-03-01 19:30:42 (GMT)
committerKen Martin <ken.martin@kitware.com>2007-03-01 19:30:42 (GMT)
commitae3ef643071099ae1fd76d0b7dfbf4459c100519 (patch)
tree7bd0fa83e647a3f853f2bdd8bb15a1ac69455b7b /Source/kwsys/SystemTools.cxx
parentc733ab2701a0915b3ec1728d341fae5bb850f7b5 (diff)
downloadCMake-ae3ef643071099ae1fd76d0b7dfbf4459c100519.zip
CMake-ae3ef643071099ae1fd76d0b7dfbf4459c100519.tar.gz
CMake-ae3ef643071099ae1fd76d0b7dfbf4459c100519.tar.bz2
ENH: added a limit to the getline method
Diffstat (limited to 'Source/kwsys/SystemTools.cxx')
-rw-r--r--Source/kwsys/SystemTools.cxx21
1 files changed, 20 insertions, 1 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index 3b12216..cbc1859 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -3542,7 +3542,8 @@ kwsys_stl::string SystemTools::MakeCindentifier(const char* s)
// if any data were read before the end-of-file was reached.
bool SystemTools::GetLineFromStream(kwsys_ios::istream& is,
kwsys_stl::string& line,
- bool* has_newline /* = 0 */)
+ bool* has_newline /* = 0 */,
+ long sizeLimit /* = -1 */)
{
const int bufferSize = 1024;
char buffer[bufferSize];
@@ -3552,9 +3553,12 @@ bool SystemTools::GetLineFromStream(kwsys_ios::istream& is,
// Start with an empty line.
line = "";
+ long leftToRead = sizeLimit;
+
// If no characters are read from the stream, the end of file has
// been reached. Clear the fail bit just before reading.
while(!haveNewline &&
+ leftToRead != 0 &&
(is.clear(is.rdstate() & ~kwsys_ios::ios::failbit),
is.getline(buffer, bufferSize), is.gcount() > 0))
{
@@ -3575,8 +3579,23 @@ bool SystemTools::GetLineFromStream(kwsys_ios::istream& is,
buffer[length-1] = 0;
}
+ // if we read too much then truncate the buffer
+ if (leftToRead > 0)
+ {
+ if (length > leftToRead)
+ {
+ buffer[leftToRead-1] = 0;
+ leftToRead = 0;
+ }
+ else
+ {
+ leftToRead -= length;
+ }
+ }
+
// Append the data read to the line.
line.append(buffer);
+ sizeLimit -= length;
}
// Return the results.