| Index: base/file_util.cc
|
| ===================================================================
|
| --- base/file_util.cc (revision 19366)
|
| +++ base/file_util.cc (working copy)
|
| @@ -129,21 +129,60 @@
|
| file1.read(buffer1, BUFFER_SIZE);
|
| file2.read(buffer2, BUFFER_SIZE);
|
|
|
| - if ((file1.eof() && !file2.eof()) ||
|
| - (!file1.eof() && file2.eof()) ||
|
| + if ((file1.eof() != file2.eof()) ||
|
| (file1.gcount() != file2.gcount()) ||
|
| (memcmp(buffer1, buffer2, file1.gcount()))) {
|
| file1.close();
|
| file2.close();
|
| return false;
|
| }
|
| - } while (!file1.eof() && !file2.eof());
|
| + } while (!file1.eof() || !file2.eof());
|
|
|
| file1.close();
|
| file2.close();
|
| return true;
|
| }
|
|
|
| +bool TextContentsEqual(const FilePath& filename1, const FilePath& filename2) {
|
| + std::ifstream file1(filename1.value().c_str(), std::ios::in);
|
| + std::ifstream file2(filename2.value().c_str(), std::ios::in);
|
| +
|
| + // Even if both files aren't openable (and thus, in some sense, "equal"),
|
| + // any unusable file yields a result of "false".
|
| + if (!file1.is_open() || !file2.is_open())
|
| + return false;
|
| +
|
| + do {
|
| + std::string line1, line2;
|
| + getline(file1, line1);
|
| + getline(file2, line2);
|
| +
|
| + // Check for mismatched EOF states, or any error state.
|
| + if ((file1.eof() != file2.eof()) ||
|
| + file1.bad() || file2.bad()) {
|
| + return false;
|
| + }
|
| +
|
| + // Trim all '\r' and '\n' characters from the end of the line.
|
| + std::string::size_type end1 = line1.find_last_not_of("\r\n");
|
| + if (end1 == std::string::npos)
|
| + line1.clear();
|
| + else if (end1 + 1 < line1.length())
|
| + line1.erase(end1 + 1);
|
| +
|
| + std::string::size_type end2 = line2.find_last_not_of("\r\n");
|
| + if (end2 == std::string::npos)
|
| + line2.clear();
|
| + else if (end2 + 1 < line2.length())
|
| + line2.erase(end2 + 1);
|
| +
|
| + if (line1 != line2)
|
| + return false;
|
| + } while (!file1.eof() || !file2.eof());
|
| +
|
| + return true;
|
| +}
|
| +
|
| bool ReadFileToString(const FilePath& path, std::string* contents) {
|
| FILE* file = OpenFile(path, "rb");
|
| if (!file) {
|
|
|