LLVM API Documentation
00001 //===- llvm/Support/FileUtilities.h - File System Utilities -----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines a family of utility functions which are useful for doing 00011 // various things with files. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_SUPPORT_FILEUTILITIES_H 00016 #define LLVM_SUPPORT_FILEUTILITIES_H 00017 00018 #include "llvm/System/Path.h" 00019 00020 namespace llvm { 00021 00022 /// DiffFilesWithTolerance - Compare the two files specified, returning 0 if 00023 /// the files match, 1 if they are different, and 2 if there is a file error. 00024 /// This function allows you to specify an absolete and relative FP error that 00025 /// is allowed to exist. If you specify a string to fill in for the error 00026 /// option, it will set the string to an error message if an error occurs, or 00027 /// if the files are different. 00028 /// 00029 int DiffFilesWithTolerance(const sys::Path &FileA, const sys::Path &FileB, 00030 double AbsTol, double RelTol, 00031 std::string *Error = 0); 00032 00033 00034 /// FileRemover - This class is a simple object meant to be stack allocated. 00035 /// If an exception is thrown from a region, the object removes the filename 00036 /// specified (if deleteIt is true). 00037 /// 00038 class FileRemover { 00039 sys::Path Filename; 00040 bool DeleteIt; 00041 public: 00042 FileRemover(const sys::Path &filename, bool deleteIt = true) 00043 : Filename(filename), DeleteIt(deleteIt) {} 00044 00045 ~FileRemover() { 00046 if (DeleteIt) 00047 try { 00048 Filename.eraseFromDisk(); 00049 } catch (...) {} // Ignore problems deleting the file. 00050 } 00051 00052 /// releaseFile - Take ownership of the file away from the FileRemover so it 00053 /// will not be removed when the object is destroyed. 00054 void releaseFile() { DeleteIt = false; } 00055 }; 00056 } // End llvm namespace 00057 00058 #endif