1 //===- llvm/Support/FileUtilities.h - File System Utilities -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a family of utility functions which are useful for doing
11 // various things with files.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_SUPPORT_FILEUTILITIES_H
16 #define LLVM_SUPPORT_FILEUTILITIES_H
18 #include "llvm/System/Path.h"
22 /// DiffFiles - Compare the two files specified, returning true if they are
23 /// different or if there is a file error. If you specify a string to fill in
24 /// for the error option, it will set the string to an error message if an error
25 /// occurs, allowing the caller to distinguish between a failed diff and a file
28 bool DiffFiles(const std::string &FileA, const std::string &FileB,
29 std::string *Error = 0);
31 /// DiffFilesWithTolerance - Compare the two files specified, returning 0 if the
32 /// files match, 1 if they are different, and 2 if there is a file error. This
33 /// function differs from DiffFiles in that you can specify an absolete and
34 /// relative FP error that is allowed to exist. If you specify a string to fill
35 /// in for the error option, it will set the string to an error message if an
36 /// error occurs, allowing the caller to distinguish between a failed diff and a
37 /// file system error.
39 int DiffFilesWithTolerance(const std::string &FileA, const std::string &FileB,
40 double AbsTol, double RelTol,
41 std::string *Error = 0);
44 /// MoveFileOverIfUpdated - If the file specified by New is different than Old,
45 /// or if Old does not exist, move the New file over the Old file. Otherwise,
46 /// remove the New file.
48 void MoveFileOverIfUpdated(const std::string &New, const std::string &Old);
50 /// FileRemover - This class is a simple object meant to be stack allocated.
51 /// If an exception is thrown from a region, the object removes the filename
52 /// specified (if deleteIt is true).
58 FileRemover(const sys::Path &filename, bool deleteIt = true)
59 : Filename(filename), DeleteIt(deleteIt) {}
64 Filename.destroyFile();
65 } catch (...) {} // Ignore problems deleting the file.
68 /// releaseFile - Take ownership of the file away from the FileRemover so it
69 /// will not be removed when the object is destroyed.
70 void releaseFile() { DeleteIt = false; }
72 } // End llvm namespace