Make ReadEntireFileToString return a std::string.

Note: this makes the method unavailable for export from angle_util,
which is probably why it was designed the way it was in the first
place. However, we import the test utils source file as a static
lib into each test executable and test shared module, so it works.

Bug: angleproject:7404
Change-Id: Ia957268882c2b8529643660d7d4f34d142c0dc43
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3708602
Commit-Queue: Roman Lavrov <romanl@google.com>
Reviewed-by: Roman Lavrov <romanl@google.com>
This commit is contained in:
Jamie Madill
2022-06-16 11:33:14 -04:00
committed by Angle LUCI CQ
parent 5f1d0742fa
commit ca96cba9c5
5 changed files with 17 additions and 37 deletions

View File

@@ -37,7 +37,7 @@ bool GetFileSize(const char *filePath, uint32_t *sizeOut)
return true;
}
bool ReadEntireFileToString(const char *filePath, char *contentsOut, uint32_t maxLen)
bool ReadEntireFileToString(const char *filePath, std::string *contentsOut)
{
std::ifstream stream(filePath);
if (!stream)
@@ -45,15 +45,12 @@ bool ReadEntireFileToString(const char *filePath, char *contentsOut, uint32_t ma
return false;
}
std::string contents;
stream.seekg(0, std::ios::end);
contents.reserve(static_cast<unsigned int>(stream.tellg()));
contentsOut->reserve(static_cast<unsigned int>(stream.tellg()));
stream.seekg(0, std::ios::beg);
contents.assign((std::istreambuf_iterator<char>(stream)), std::istreambuf_iterator<char>());
contentsOut->assign((std::istreambuf_iterator<char>(stream)), std::istreambuf_iterator<char>());
strncpy(contentsOut, contents.c_str(), maxLen);
return true;
}