1 //===- 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 SUPPORT_FILEUTILITIES_H
16 #define SUPPORT_FILEUTILITIES_H
20 /// CheckMagic - Returns true IFF the file named FN begins with Magic. FN must
21 /// name a readable file.
23 bool CheckMagic (const std::string &FN, const std::string &Magic);
25 /// IsArchive - Returns true IFF the file named FN appears to be a "ar" library
26 /// archive. The file named FN must exist.
28 bool IsArchive (const std::string &FN);
30 /// IsBytecode - Returns true IFF the file named FN appears to be an LLVM
31 /// bytecode file. The file named FN must exist.
33 bool IsBytecode (const std::string &FN);
35 /// FileOpenable - Returns true IFF Filename names an existing regular file
36 /// which we can successfully open.
38 bool FileOpenable (const std::string &Filename);
40 /// DiffFiles - Compare the two files specified, returning true if they are
41 /// different or if there is a file error. If you specify a string to fill in
42 /// for the error option, it will set the string to an error message if an error
43 /// occurs, allowing the caller to distinguish between a failed diff and a file
46 bool DiffFiles(const std::string &FileA, const std::string &FileB,
47 std::string *Error = 0);
50 /// MoveFileOverIfUpdated - If the file specified by New is different than Old,
51 /// or if Old does not exist, move the New file over the Old file. Otherwise,
52 /// remove the New file.
54 void MoveFileOverIfUpdated(const std::string &New, const std::string &Old);
56 /// removeFile - Delete the specified file
58 void removeFile(const std::string &Filename);
60 /// getUniqueFilename - Return a filename with the specified prefix. If the
61 /// file does not exist yet, return it, otherwise add a suffix to make it
64 std::string getUniqueFilename(const std::string &FilenameBase);
67 /// Method: MakeFileExecutable()
70 /// This method turns on whatever access attributes are needed to make the
71 /// specified file executable.
74 /// True - The operation succeeded.
75 /// False - The operation failed.
78 /// In case of failure, the file's access attributes are unspecified.
80 bool MakeFileExecutable (const std::string & Filename);
83 /// Method: MakeFileReadable()
86 /// This method turns on whatever access attributes are needed to make the
87 /// specified file readable.
90 /// True - The operation succeeded.
91 /// False - The operation failed.
94 /// In case of failure, the file's access attributes are unspecified.
96 bool MakeFileReadable (const std::string & Filename);