- // 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)
+ ErrorOr<std::unique_ptr<MemoryBuffer>> F2OrErr = MemoryBuffer::getFile(NameB);
+ if (std::error_code EC = F2OrErr.getError()) {
+ if (Error)
+ *Error = EC.message();
+ return 2;
+ }
+ MemoryBuffer &F2 = *F2OrErr.get();
+
+ // Okay, now that we opened the files, scan them for the first difference.
+ const char *File1Start = F1.getBufferStart();
+ const char *File2Start = F2.getBufferStart();
+ const char *File1End = F1.getBufferEnd();
+ const char *File2End = F2.getBufferEnd();
+ const char *F1P = File1Start;
+ const char *F2P = File2Start;
+ uint64_t A_size = F1.getBufferSize();
+ uint64_t B_size = F2.getBufferSize();
+
+ // Are the buffers identical? Common case: Handle this efficiently.
+ if (A_size == B_size &&
+ std::memcmp(File1Start, File2Start, A_size) == 0)