-bool llvm::MakeFileReadable(const std::string &Filename) {
- return AddPermissionsBits(Filename, 0444);
-}
-
-/// getFileSize - Return the size of the specified file in bytes, or -1 if the
-/// file cannot be read or does not exist.
-long long llvm::getFileSize(const std::string &Filename) {
- struct stat StatBuf;
- if (stat(Filename.c_str(), &StatBuf) == -1)
- return -1;
- return StatBuf.st_size;
-}
-
-/// getFileTimestamp - Get the last modified time for the specified file in an
-/// unspecified format. This is useful to allow checking to see if a file was
-/// updated since that last time the timestampt was aquired. If the file does
-/// not exist or there is an error getting the time-stamp, zero is returned.
-unsigned long long llvm::getFileTimestamp(const std::string &Filename) {
- struct stat StatBuf;
- if (stat(Filename.c_str(), &StatBuf) == -1)
- return 0;
- return StatBuf.st_mtime;
-}
-
-/// ReadFileIntoAddressSpace - Attempt to map the specific file into the
-/// address space of the current process for reading. If this succeeds,
-/// return the address of the buffer and the length of the file mapped. On
-/// failure, return null.
-void *llvm::ReadFileIntoAddressSpace(const std::string &Filename,
- unsigned &Length) {
-#if defined(HAVE_MMAP_FILE) && !defined(_MSC_VER)
- Length = (unsigned)getFileSize(Filename);
- if ((int)Length == -1) return 0;
-
- FDHandle FD(open(Filename.c_str(), O_RDONLY));
- if (FD == -1) return 0;
-
- // If the file has a length of zero, mmap might return a null pointer. In
- // this case, allocate a single byte of memory and return it instead.
- if (Length == 0)
- return malloc(1);
-
- // mmap in the file all at once...
- void *Buffer = (void*)mmap(0, Length, PROT_READ, MAP_PRIVATE, FD, 0);
+int llvm::DiffFilesWithTolerance(StringRef NameA,
+ StringRef NameB,
+ double AbsTol, double RelTol,
+ std::string *Error) {
+ // 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;
+ }
+ std::unique_ptr<MemoryBuffer> F1 = std::move(F1OrErr.get());