mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-14 23:48:49 +00:00
Make DiffFilesWithTolerance take sys::Path's instead of std::strings
Delete dead functions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19771 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
f61c001673
commit
cc1b90b0e7
@ -17,57 +17,8 @@
|
||||
#include "llvm/System/MappedFile.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
/// DiffFiles - Compare the two files specified, returning true if they are
|
||||
/// different or if there is a file error. If you specify a string to fill in
|
||||
/// for the error option, it will set the string to an error message if an error
|
||||
/// occurs, allowing the caller to distinguish between a failed diff and a file
|
||||
/// system error.
|
||||
///
|
||||
bool llvm::DiffFiles(const std::string &FileA, const std::string &FileB,
|
||||
std::string *Error) {
|
||||
std::ios::openmode io_mode = std::ios::in | std::ios::binary;
|
||||
std::ifstream FileAStream(FileA.c_str(), io_mode);
|
||||
if (!FileAStream) {
|
||||
if (Error) *Error = "Couldn't open file '" + FileA + "'";
|
||||
return true;
|
||||
}
|
||||
|
||||
std::ifstream FileBStream(FileB.c_str(), io_mode);
|
||||
if (!FileBStream) {
|
||||
if (Error) *Error = "Couldn't open file '" + FileB + "'";
|
||||
return true;
|
||||
}
|
||||
|
||||
// Compare the two files...
|
||||
int C1, C2;
|
||||
do {
|
||||
C1 = FileAStream.get();
|
||||
C2 = FileBStream.get();
|
||||
if (C1 != C2) return true;
|
||||
} while (C1 != EOF);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// MoveFileOverIfUpdated - If the file specified by New is different than Old,
|
||||
/// or if Old does not exist, move the New file over the Old file. Otherwise,
|
||||
/// remove the New file.
|
||||
///
|
||||
void llvm::MoveFileOverIfUpdated(const std::string &New,
|
||||
const std::string &Old) {
|
||||
if (DiffFiles(New, Old)) {
|
||||
if (std::rename(New.c_str(), Old.c_str()))
|
||||
std::cerr << "Error renaming '" << New << "' to '" << Old << "'!\n";
|
||||
} else {
|
||||
std::remove(New.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
static bool isNumberChar(char C) {
|
||||
switch (C) {
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
@ -162,14 +113,14 @@ static void PadFileIfNeeded(char *&FileStart, char *&FileEnd, char *&FP) {
|
||||
/// error occurs, allowing the caller to distinguish between a failed diff and a
|
||||
/// file system error.
|
||||
///
|
||||
int llvm::DiffFilesWithTolerance(const std::string &FileA,
|
||||
const std::string &FileB,
|
||||
int llvm::DiffFilesWithTolerance(const sys::Path &FileA,
|
||||
const sys::Path &FileB,
|
||||
double AbsTol, double RelTol,
|
||||
std::string *Error) {
|
||||
try {
|
||||
// Map in the files into memory.
|
||||
sys::MappedFile F1((sys::Path(FileA)));
|
||||
sys::MappedFile F2((sys::Path(FileB)));
|
||||
sys::MappedFile F1(FileA);
|
||||
sys::MappedFile F2(FileB);
|
||||
F1.map();
|
||||
F2.map();
|
||||
|
||||
@ -188,6 +139,9 @@ int llvm::DiffFilesWithTolerance(const std::string &FileA,
|
||||
// Common case: identifical files.
|
||||
if (F1P == File1End && F2P == File2End) return 0;
|
||||
|
||||
if (AbsTol == 0 && RelTol == 0)
|
||||
return 1; // Files different!
|
||||
|
||||
char *OrigFile1Start = File1Start;
|
||||
char *OrigFile2Start = File2Start;
|
||||
|
||||
@ -239,9 +193,9 @@ int llvm::DiffFilesWithTolerance(const std::string &FileA,
|
||||
}
|
||||
|
||||
if (OrigFile1Start != File1Start)
|
||||
delete[] File1Start-1; // Back up past null byte
|
||||
delete[] (File1Start-1); // Back up past null byte
|
||||
if (OrigFile2Start != File2Start)
|
||||
delete[] File2Start-1; // Back up past null byte
|
||||
delete[] (File2Start-1); // Back up past null byte
|
||||
return CompareFailed;
|
||||
} catch (const std::string &Msg) {
|
||||
if (Error) *Error = Msg;
|
||||
|
Loading…
Reference in New Issue
Block a user