-void llvm::removeFile(const std::string &Filename) {
- std::remove(Filename.c_str());
-}
-
-/// getUniqueFilename - Return a filename with the specified prefix. If the
-/// file does not exist yet, return it, otherwise add a suffix to make it
-/// unique.
-///
-std::string llvm::getUniqueFilename(const std::string &FilenameBase) {
- if (!std::ifstream(FilenameBase.c_str()))
- return FilenameBase; // Couldn't open the file? Use it!
-
- // Create a pattern for mkstemp...
- char *FNBuffer = new char[FilenameBase.size()+8];
- strcpy(FNBuffer, FilenameBase.c_str());
- strcpy(FNBuffer+FilenameBase.size(), "-XXXXXX");
-
- // Agree on a temporary file name to use....
- int TempFD;
- if ((TempFD = mkstemp(FNBuffer)) == -1) {
- std::cerr << "bugpoint: ERROR: Cannot create temporary file in the current "
- << " directory!\n";
- exit(1);
- }
-
- // We don't need to hold the temp file descriptor... we will trust that no one
- // will overwrite/delete the file while we are working on it...
- close(TempFD);
- std::string Result(FNBuffer);
- delete[] FNBuffer;
- return Result;
-}
-
-static bool AddPermissionsBits (const std::string &Filename, mode_t bits) {
- // Get the umask value from the operating system. We want to use it
- // when changing the file's permissions. Since calling umask() sets
- // the umask and returns its old value, we must call it a second
- // time to reset it to the user's preference.
- mode_t mask = umask (0777); // The arg. to umask is arbitrary...
- umask (mask);
-
- // Get the file's current mode.
- struct stat st;
- if ((stat (Filename.c_str(), &st)) == -1)
- return false;
-
- // Change the file to have whichever permissions bits from 'bits'
- // that the umask would not disable.
- if ((chmod(Filename.c_str(), (st.st_mode | (bits & ~mask)))) == -1)
- return false;
-
- return true;
-}
-
-/// MakeFileExecutable - Make the file named Filename executable by
-/// setting whichever execute permissions bits the process's current
-/// umask would allow. Filename must name an existing file or
-/// directory. Returns true on success, false on error.
-///
-bool llvm::MakeFileExecutable(const std::string &Filename) {
- return AddPermissionsBits(Filename, 0111);
-}
-
-/// MakeFileReadable - Make the file named Filename readable by
-/// setting whichever read permissions bits the process's current
-/// umask would allow. Filename must name an existing file or
-/// directory. Returns true on success, false on error.
-///
-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)
+int llvm::DiffFilesWithTolerance(const sys::PathWithStatus &FileA,
+ const sys::PathWithStatus &FileB,
+ double AbsTol, double RelTol,
+ std::string *Error) {
+ const sys::FileStatus *FileAStat = FileA.getFileStatus(false, Error);
+ if (!FileAStat)
+ return 2;
+ const sys::FileStatus *FileBStat = FileB.getFileStatus(false, Error);
+ if (!FileBStat)
+ return 2;
+
+ // Check for zero length files because some systems croak when you try to
+ // mmap an empty file.
+ size_t A_size = FileAStat->getSize();
+ size_t B_size = FileBStat->getSize();
+
+ // If they are both zero sized then they're the same
+ if (A_size == 0 && B_size == 0)