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
22 /// CheckMagic - Returns true IFF the file named FN begins with Magic. FN must
23 /// name a readable file.
25 bool CheckMagic (const std::string &FN, const std::string &Magic);
27 /// IsArchive - Returns true IFF the file named FN appears to be a "ar" library
28 /// archive. The file named FN must exist.
30 bool IsArchive (const std::string &FN);
32 /// IsBytecode - Returns true IFF the file named FN appears to be an LLVM
33 /// bytecode file. The file named FN must exist.
35 bool IsBytecode (const std::string &FN);
37 /// FileOpenable - Returns true IFF Filename names an existing regular file
38 /// which we can successfully open.
40 bool FileOpenable (const std::string &Filename);
42 /// DiffFiles - Compare the two files specified, returning true if they are
43 /// different or if there is a file error. If you specify a string to fill in
44 /// for the error option, it will set the string to an error message if an error
45 /// occurs, allowing the caller to distinguish between a failed diff and a file
48 bool DiffFiles(const std::string &FileA, const std::string &FileB,
49 std::string *Error = 0);
52 /// MoveFileOverIfUpdated - If the file specified by New is different than Old,
53 /// or if Old does not exist, move the New file over the Old file. Otherwise,
54 /// remove the New file.
56 void MoveFileOverIfUpdated(const std::string &New, const std::string &Old);
58 /// removeFile - Delete the specified file
60 void removeFile(const std::string &Filename);
62 /// getUniqueFilename - Return a filename with the specified prefix. If the
63 /// file does not exist yet, return it, otherwise add a suffix to make it
66 std::string getUniqueFilename(const std::string &FilenameBase);
69 /// Method: MakeFileExecutable()
72 /// This method turns on whatever access attributes are needed to make the
73 /// specified file executable.
76 /// True - The operation succeeded.
77 /// False - The operation failed.
80 /// In case of failure, the file's access attributes are unspecified.
82 bool MakeFileExecutable (const std::string & Filename);
85 /// Method: MakeFileReadable()
88 /// This method turns on whatever access attributes are needed to make the
89 /// specified file readable.
92 /// True - The operation succeeded.
93 /// False - The operation failed.
96 /// In case of failure, the file's access attributes are unspecified.
98 bool MakeFileReadable (const std::string & Filename);
100 } // End llvm namespace