aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-07-16 19:44:17 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-07-16 19:44:17 +0000
commitc1b49b56d4132efa2e06deb8f23508d0de4c8800 (patch)
treeac30ab59f60f12465f5b7ffd0823b08a711770e8 /include
parent1a9c39e52a2b1ce474dec773e77d12ae4c335a71 (diff)
downloadexternal_llvm-c1b49b56d4132efa2e06deb8f23508d0de4c8800.zip
external_llvm-c1b49b56d4132efa2e06deb8f23508d0de4c8800.tar.gz
external_llvm-c1b49b56d4132efa2e06deb8f23508d0de4c8800.tar.bz2
Add a wrapper for open.
This centralizes the handling of O_BINARY and opens the way for hiding more differences (like how open behaves with directories). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186447 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/Support/FileSystem.h31
-rw-r--r--include/llvm/Support/ToolOutputFile.h2
-rw-r--r--include/llvm/Support/raw_ostream.h19
3 files changed, 34 insertions, 18 deletions
diff --git a/include/llvm/Support/FileSystem.h b/include/llvm/Support/FileSystem.h
index 5ed151d..800f4eb 100644
--- a/include/llvm/Support/FileSystem.h
+++ b/include/llvm/Support/FileSystem.h
@@ -611,6 +611,37 @@ error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix,
error_code createUniqueDirectory(const Twine &Prefix,
SmallVectorImpl<char> &ResultPath);
+enum OpenFlags {
+ F_None = 0,
+
+ /// F_Excl - When opening a file, this flag makes raw_fd_ostream
+ /// report an error if the file already exists.
+ F_Excl = 1,
+
+ /// F_Append - When opening a file, if it already exists append to the
+ /// existing file instead of returning an error. This may not be specified
+ /// with F_Excl.
+ F_Append = 2,
+
+ /// F_Binary - The file should be opened in binary mode on platforms that
+ /// make this distinction.
+ F_Binary = 4
+};
+
+inline OpenFlags operator|(OpenFlags A, OpenFlags B) {
+ return OpenFlags(unsigned(A) | unsigned(B));
+}
+
+inline OpenFlags &operator|=(OpenFlags &A, OpenFlags B) {
+ A = A | B;
+ return A;
+}
+
+error_code openFileForWrite(const Twine &Name, int &ResultFD, OpenFlags Flags,
+ unsigned Mode = 0666);
+
+error_code openFileForRead(const Twine &Name, int &ResultFD);
+
/// @brief Canonicalize path.
///
/// Sets result to the file system's idea of what path is. The result is always
diff --git a/include/llvm/Support/ToolOutputFile.h b/include/llvm/Support/ToolOutputFile.h
index cc8511f..a2191ad 100644
--- a/include/llvm/Support/ToolOutputFile.h
+++ b/include/llvm/Support/ToolOutputFile.h
@@ -47,7 +47,7 @@ public:
/// tool_output_file - This constructor's arguments are passed to
/// to raw_fd_ostream's constructor.
tool_output_file(const char *filename, std::string &ErrorInfo,
- unsigned Flags = 0);
+ sys::fs::OpenFlags Flags = sys::fs::F_None);
tool_output_file(const char *Filename, int FD);
diff --git a/include/llvm/Support/raw_ostream.h b/include/llvm/Support/raw_ostream.h
index d2b4a2a..ec7e06b 100644
--- a/include/llvm/Support/raw_ostream.h
+++ b/include/llvm/Support/raw_ostream.h
@@ -17,6 +17,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/DataTypes.h"
+#include "llvm/Support/FileSystem.h"
namespace llvm {
class format_object_base;
@@ -335,22 +336,6 @@ class raw_fd_ostream : public raw_ostream {
void error_detected() { Error = true; }
public:
-
- enum {
- /// F_Excl - When opening a file, this flag makes raw_fd_ostream
- /// report an error if the file already exists.
- F_Excl = 1,
-
- /// F_Append - When opening a file, if it already exists append to the
- /// existing file instead of returning an error. This may not be specified
- /// with F_Excl.
- F_Append = 2,
-
- /// F_Binary - The file should be opened in binary mode on platforms that
- /// make this distinction.
- F_Binary = 4
- };
-
/// raw_fd_ostream - Open the specified file for writing. If an error occurs,
/// information about the error is put into ErrorInfo, and the stream should
/// be immediately destroyed; the string will be empty if no error occurred.
@@ -362,7 +347,7 @@ public:
/// file descriptor when it is done (this is necessary to detect
/// output errors).
raw_fd_ostream(const char *Filename, std::string &ErrorInfo,
- unsigned Flags = 0);
+ sys::fs::OpenFlags Flags = sys::fs::F_None);
/// raw_fd_ostream ctor - FD is the file descriptor that this writes to. If
/// ShouldClose is true, this closes the file when the stream is destroyed.