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 /// MoveFileOverIfUpdated - If the file specified by New is different than Old,
32 /// or if Old does not exist, move the New file over the Old file. Otherwise,
33 /// remove the New file.
35 void MoveFileOverIfUpdated(const std::string &New, const std::string &Old);
37 /// FileRemover - This class is a simple object meant to be stack allocated.
38 /// If an exception is thrown from a region, the object removes the filename
39 /// specified (if deleteIt is true).
45 FileRemover(const sys::Path &filename, bool deleteIt = true)
46 : Filename(filename), DeleteIt(deleteIt) {}
50 Filename.destroyFile();
53 /// releaseFile - Take ownership of the file away from the FileRemover so it
54 /// will not be removed when the object is destroyed.
55 void releaseFile() { DeleteIt = false; }
57 } // End llvm namespace