summaryrefslogtreecommitdiff
path: root/lib/Support/FileUtilities.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2005-02-15 21:47:02 +0000
committerReid Spencer <rspencer@reidspencer.com>2005-02-15 21:47:02 +0000
commit45d55641fa3af536e48be446647ff51b15109992 (patch)
treecfd1346ac8fd35d3a19a496e5f1124f870404114 /lib/Support/FileUtilities.cpp
parentadf75775fafa55962274ef8704ceca3842e50c8a (diff)
downloadllvm-45d55641fa3af536e48be446647ff51b15109992.tar.gz
llvm-45d55641fa3af536e48be446647ff51b15109992.tar.bz2
llvm-45d55641fa3af536e48be446647ff51b15109992.tar.xz
Adjust DiffFilesWithTolerance to help poor cygwin's mmap facility by
handling zero length files a little more intelligently. If both files are zero length then we return 0 (true) indicating a match. If only one of the files is zero length then we return 1 (false) indicating that the files differ. If the files don't agree in length then they can't match so we skip the first loop that looks for a quick match. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20200 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/FileUtilities.cpp')
-rw-r--r--lib/Support/FileUtilities.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/lib/Support/FileUtilities.cpp b/lib/Support/FileUtilities.cpp
index 99db439d32..f8191c5121 100644
--- a/lib/Support/FileUtilities.cpp
+++ b/lib/Support/FileUtilities.cpp
@@ -119,7 +119,20 @@ int llvm::DiffFilesWithTolerance(const sys::Path &FileA,
double AbsTol, double RelTol,
std::string *Error) {
try {
- // Map in the files into memory.
+ // Check for zero length files becasue 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();
@@ -133,15 +146,18 @@ int llvm::DiffFilesWithTolerance(const sys::Path &FileA,
char *F1P = File1Start;
char *F2P = File2Start;
- // Scan for the end of file or first difference.
- while (F1P < File1End && F2P < File2End && *F1P == *F2P)
- ++F1P, ++F2P;
+ if (A_size == B_size) {
+ // Scan for the end of file or first difference.
+ while (F1P < File1End && F2P < File2End && *F1P == *F2P)
+ ++F1P, ++F2P;
- // Common case: identifical files.
- if (F1P == File1End && F2P == File2End) return 0;
+ // Common case: identifical files.
+ if (F1P == File1End && F2P == File2End)
+ return 0; // Scanned to end, files same
- if (AbsTol == 0 && RelTol == 0)
- return 1; // Files different!
+ if (AbsTol == 0 && RelTol == 0)
+ return 1; // Files different!
+ }
char *OrigFile1Start = File1Start;
char *OrigFile2Start = File2Start;