d55ba52a98aba1516490a7ca985ed0231302b1a9
[oota-llvm.git] / include / llvm / Support / FileUtilities.h
1 //===- Support/FileUtilities.h - File System Utilities ----------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
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.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines a family of utility functions which are useful for doing
11 // various things with files.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef SUPPORT_FILEUTILITIES_H
16 #define SUPPORT_FILEUTILITIES_H
17
18 #include <string>
19
20 /// FileOpenable - Returns true IFF Filename names an existing regular
21 /// file which we can successfully open.
22 ///
23 bool FileOpenable (const std::string &Filename);
24
25 /// DiffFiles - Compare the two files specified, returning true if they are
26 /// different or if there is a file error.  If you specify a string to fill in
27 /// for the error option, it will set the string to an error message if an error
28 /// occurs, allowing the caller to distinguish between a failed diff and a file
29 /// system error.
30 ///
31 bool DiffFiles(const std::string &FileA, const std::string &FileB,
32                std::string *Error = 0);
33
34
35 /// MoveFileOverIfUpdated - If the file specified by New is different than Old,
36 /// or if Old does not exist, move the New file over the Old file.  Otherwise,
37 /// remove the New file.
38 ///
39 void MoveFileOverIfUpdated(const std::string &New, const std::string &Old);
40  
41 /// removeFile - Delete the specified file
42 ///
43 void removeFile(const std::string &Filename);
44
45 /// getUniqueFilename - Return a filename with the specified prefix.  If the
46 /// file does not exist yet, return it, otherwise add a suffix to make it
47 /// unique.
48 ///
49 std::string getUniqueFilename(const std::string &FilenameBase);
50
51 ///
52 /// Method: MakeFileExecutable()
53 ///
54 /// Description:
55 ///     This method turns on whatever access attributes are needed to make the
56 ///     specified file executable.
57 ///
58 /// Return value:
59 ///     True  - The operation succeeded.
60 ///     False - The operation failed.
61 ///
62 /// Notes:
63 ///     In case of failure, the file's access attributes are unspecified.
64 ///
65 bool MakeFileExecutable (const std::string & Filename);
66
67 ///
68 /// Method: MakeFileReadable()
69 ///
70 /// Description:
71 ///     This method turns on whatever access attributes are needed to make the
72 ///     specified file readable.
73 ///
74 /// Return value:
75 ///     True  - The operation succeeded.
76 ///     False - The operation failed.
77 ///
78 /// Notes:
79 ///     In case of failure, the file's access attributes are unspecified.
80 ///
81 bool MakeFileReadable (const std::string & Filename);
82
83 #endif