Merge branch 'autogen-empty-source-file-fix' into release-3.10

There is no corresponding merge request because this fix was
cherry-picked specifically for CMake 3.10.
This commit is contained in:
Brad King
2018-03-09 06:51:38 -05:00

View File

@@ -80,15 +80,21 @@ static bool ReadFile(std::string& content, std::string const& filename,
std::size_t const length = cmSystemTools::FileLength(filename);
cmsys::ifstream ifs(filename.c_str(), (std::ios::in | std::ios::binary));
if (ifs) {
content.resize(length);
ifs.read(&content.front(), content.size());
if (ifs) {
success = true;
} else {
content.clear();
if (error != nullptr) {
error->append("Reading from the file failed.");
if (length > 0) {
content.resize(length);
ifs.read(&content.front(), content.size());
if (ifs) {
success = true;
} else {
content.clear();
if (error != nullptr) {
error->append("Reading from the file failed.");
}
}
} else {
// Readable but empty file
content.clear();
success = true;
}
} else if (error != nullptr) {
error->append("Opening the file for reading failed.");