From efdc3a13cdccf11fe33773e724ff40ffa8c733b0 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Tue, 22 Aug 2006 16:06:27 +0000 Subject: For PR797: Adjust users of MappedFile to its new non-throwing interface. Note that in most cases the lazy step of just throwing after a call to MappedFile was installed. This was done in the name of incremental changes. Getting rid of the new throw statements will take adjustment of interfaces and propagation of errors to higher levels. Those changes will come in subsequent patches. llvm-svn: 29817 --- llvm/lib/Support/FileUtilities.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'llvm/lib/Support/FileUtilities.cpp') diff --git a/llvm/lib/Support/FileUtilities.cpp b/llvm/lib/Support/FileUtilities.cpp index d4608ccb65b..313598942a7 100644 --- a/llvm/lib/Support/FileUtilities.cpp +++ b/llvm/lib/Support/FileUtilities.cpp @@ -147,9 +147,11 @@ int llvm::DiffFilesWithTolerance(const sys::Path &FileA, double AbsTol, double RelTol, std::string *Error) { sys::FileStatus FileAStat, FileBStat; - if (FileA.getFileStatus(FileAStat, Error) || - FileB.getFileStatus(FileBStat, Error)) + if (FileA.getFileStatus(FileAStat, Error)) return 2; + if (FileB.getFileStatus(FileBStat, Error)) + 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(); @@ -165,10 +167,16 @@ int llvm::DiffFilesWithTolerance(const sys::Path &FileA, try { // 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(); - F2.map(); + sys::MappedFile F1; + if (F1.open(FileA, sys::MappedFile::READ_ACCESS, Error)) + return 2; + sys::MappedFile F2; + if (F2.open(FileB, sys::MappedFile::READ_ACCESS, Error)) + return 2; + if (!F1.map(Error)) + return 2; + if (!F2.map(Error)) + return 2; // Okay, now that we opened the files, scan them for the first difference. char *File1Start = F1.charBase(); -- cgit v1.2.3