1 //===- llvm/Support/FileUtilities.h - File System Utilities -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // 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/Support/FileSystem.h"
19 #include "llvm/Support/Path.h"
23 /// DiffFilesWithTolerance - Compare the two files specified, returning 0 if
24 /// the files match, 1 if they are different, and 2 if there is a file error.
25 /// This function allows you to specify an absolute and relative FP error that
26 /// is allowed to exist. If you specify a string to fill in for the error
27 /// option, it will set the string to an error message if an error occurs, or
28 /// if the files are different.
30 int DiffFilesWithTolerance(const sys::PathWithStatus &FileA,
31 const sys::PathWithStatus &FileB,
32 double AbsTol, double RelTol,
33 std::string *Error = 0);
36 /// FileRemover - This class is a simple object meant to be stack allocated.
37 /// If an exception is thrown from a region, the object removes the filename
38 /// specified (if deleteIt is true).
41 SmallString<128> Filename;
44 FileRemover() : DeleteIt(false) {}
46 explicit FileRemover(const Twine& filename, bool deleteIt = true)
47 : DeleteIt(deleteIt) {
48 filename.toVector(Filename);
53 // Ignore problems deleting the file.
55 sys::fs::remove(Filename.str(), existed);
59 /// setFile - Give ownership of the file to the FileRemover so it will
60 /// be removed when the object is destroyed. If the FileRemover already
61 /// had ownership of a file, remove it first.
62 void setFile(const Twine& filename, bool deleteIt = true) {
64 // Ignore problems deleting the file.
66 sys::fs::remove(Filename.str(), existed);
70 filename.toVector(Filename);
74 /// releaseFile - Take ownership of the file away from the FileRemover so it
75 /// will not be removed when the object is destroyed.
76 void releaseFile() { DeleteIt = false; }
78 } // End llvm namespace