- try {
- // Check for zero length files because some systems croak when you try to
- // mmap an empty file.
- size_t A_size = FileA.getSize();
- size_t B_size = FileB.getSize();
-
- // If they are both zero sized then they're the same
- if (A_size == 0 && B_size == 0)
- return 0;
- // If only one of them is zero sized then they can't be the same
- if ((A_size == 0 || B_size == 0))
- return 1;
-
- // Now its safe to mmap the files into memory becasue both files
- // have a non-zero size.
- sys::MappedFile F1(FileA);
- sys::MappedFile F2(FileB);
- F1.map();
- F2.map();
-
- // Okay, now that we opened the files, scan them for the first difference.
- char *File1Start = F1.charBase();
- char *File2Start = F2.charBase();
- char *File1End = File1Start+A_size;
- char *File2End = File2Start+B_size;
- char *F1P = File1Start;
- char *F2P = File2Start;
-
- if (A_size == B_size) {
- // Are the buffers identical?
- if (std::memcmp(File1Start, File2Start, A_size) == 0)
- return 0;
-
- if (AbsTol == 0 && RelTol == 0)
- return 1; // Files different!
- }
+ // Now its safe to mmap the files into memory because both files
+ // have a non-zero size.
+ ErrorOr<std::unique_ptr<MemoryBuffer>> F1OrErr = MemoryBuffer::getFile(NameA);
+ if (std::error_code EC = F1OrErr.getError()) {
+ if (Error)
+ *Error = EC.message();
+ return 2;
+ }
+ MemoryBuffer &F1 = *F1OrErr.get();