[cmake-commits] martink committed SystemTools.cxx 1.194 1.195
SystemTools.hxx.in 1.63 1.64
cmake-commits at cmake.org
cmake-commits at cmake.org
Thu Mar 1 14:30:44 EST 2007
Update of /cvsroot/CMake/CMake/Source/kwsys
In directory public:/mounts/ram/cvs-serv23424
Modified Files:
SystemTools.cxx SystemTools.hxx.in
Log Message:
ENH: added a limit to the getline method
Index: SystemTools.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/kwsys/SystemTools.cxx,v
retrieving revision 1.194
retrieving revision 1.195
diff -u -d -r1.194 -r1.195
--- SystemTools.cxx 22 Feb 2007 20:27:56 -0000 1.194
+++ SystemTools.cxx 1 Mar 2007 19:30:41 -0000 1.195
@@ -3542,7 +3542,8 @@
// 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 @@
// 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 @@
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.
Index: SystemTools.hxx.in
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/kwsys/SystemTools.hxx.in,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -d -r1.63 -r1.64
--- SystemTools.hxx.in 17 Aug 2006 16:02:18 -0000 1.63
+++ SystemTools.hxx.in 1 Mar 2007 19:30:42 -0000 1.64
@@ -434,7 +434,8 @@
*/
static bool GetLineFromStream(kwsys_ios::istream& istr,
kwsys_stl::string& line,
- bool* has_newline=0);
+ bool* has_newline=0,
+ long sizeLimit=-1);
/**
* Get the parent directory of the directory or file
More information about the Cmake-commits
mailing list