summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2017-11-27 23:44:11 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2017-11-27 23:44:11 +0000
commitd19c2e812640df745d857e7347e617f1fb18057f (patch)
tree85b0dca00a108f622b1dd1cfaac28f354047d7a4
parentf9b08a382cc1e0669805991849ad69efbd4703e8 (diff)
downloadbcm5719-llvm-d19c2e812640df745d857e7347e617f1fb18057f.tar.gz
bcm5719-llvm-d19c2e812640df745d857e7347e617f1fb18057f.zip
Add OpenFlags to the create(Unique|Temporary)File interfaces.
This will allow a future F_Delete flag to be specified when we want the file to be automatically deleted on close. llvm-svn: 319117
-rw-r--r--llvm/include/llvm/Support/FileSystem.h46
-rw-r--r--llvm/lib/Support/Path.cpp34
2 files changed, 44 insertions, 36 deletions
diff --git a/llvm/include/llvm/Support/FileSystem.h b/llvm/include/llvm/Support/FileSystem.h
index a7874abf481..4a5be15950c 100644
--- a/llvm/include/llvm/Support/FileSystem.h
+++ b/llvm/include/llvm/Support/FileSystem.h
@@ -666,6 +666,26 @@ bool status_known(const basic_file_status &s);
/// platform-specific error_code.
std::error_code status_known(const Twine &path, bool &result);
+enum OpenFlags : unsigned {
+ 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,
+
+ /// The file should be opened in text mode on platforms that make this
+ /// distinction.
+ F_Text = 4,
+
+ /// Open the file for read and write.
+ F_RW = 8
+};
+
/// @brief Create a uniquely named file.
///
/// Generates a unique path suitable for a temporary file and then opens it as a
@@ -689,7 +709,8 @@ std::error_code status_known(const Twine &path, bool &result);
/// otherwise a platform-specific error_code.
std::error_code createUniqueFile(const Twine &Model, int &ResultFD,
SmallVectorImpl<char> &ResultPath,
- unsigned Mode = all_read | all_write);
+ unsigned Mode = all_read | all_write,
+ sys::fs::OpenFlags Flags = sys::fs::F_RW);
/// @brief Simpler version for clients that don't want an open file.
std::error_code createUniqueFile(const Twine &Model,
@@ -743,7 +764,8 @@ public:
/// running the assembler.
std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix,
int &ResultFD,
- SmallVectorImpl<char> &ResultPath);
+ SmallVectorImpl<char> &ResultPath,
+ sys::fs::OpenFlags Flags = sys::fs::F_RW);
/// @brief Simpler version for clients that don't want an open file.
std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix,
@@ -752,26 +774,6 @@ std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix,
std::error_code createUniqueDirectory(const Twine &Prefix,
SmallVectorImpl<char> &ResultPath);
-enum OpenFlags : unsigned {
- 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,
-
- /// The file should be opened in text mode on platforms that make this
- /// distinction.
- F_Text = 4,
-
- /// Open the file for read and write.
- F_RW = 8
-};
-
inline OpenFlags operator|(OpenFlags A, OpenFlags B) {
return OpenFlags(unsigned(A) | unsigned(B));
}
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index cb8e5a8d5f7..9dd6a34c658 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -160,10 +160,11 @@ enum FSEntity {
FS_Name
};
-static std::error_code createUniqueEntity(const Twine &Model, int &ResultFD,
- SmallVectorImpl<char> &ResultPath,
- bool MakeAbsolute, unsigned Mode,
- FSEntity Type) {
+static std::error_code
+createUniqueEntity(const Twine &Model, int &ResultFD,
+ SmallVectorImpl<char> &ResultPath, bool MakeAbsolute,
+ unsigned Mode, FSEntity Type,
+ sys::fs::OpenFlags Flags = sys::fs::F_None) {
SmallString<128> ModelStorage;
Model.toVector(ModelStorage);
@@ -196,7 +197,7 @@ retry_random_path:
case FS_File: {
if (std::error_code EC =
sys::fs::openFileForWrite(Twine(ResultPath.begin()), ResultFD,
- sys::fs::F_RW | sys::fs::F_Excl, Mode)) {
+ Flags | sys::fs::F_Excl, Mode)) {
if (EC == errc::file_exists)
goto retry_random_path;
return EC;
@@ -750,8 +751,9 @@ std::error_code getUniqueID(const Twine Path, UniqueID &Result) {
std::error_code createUniqueFile(const Twine &Model, int &ResultFd,
SmallVectorImpl<char> &ResultPath,
- unsigned Mode) {
- return createUniqueEntity(Model, ResultFd, ResultPath, false, Mode, FS_File);
+ unsigned Mode, sys::fs::OpenFlags Flags) {
+ return createUniqueEntity(Model, ResultFd, ResultPath, false, Mode, FS_File,
+ Flags);
}
std::error_code createUniqueFile(const Twine &Model,
@@ -845,28 +847,32 @@ Expected<TempFile> TempFile::create(const Twine &Model, unsigned Mode) {
static std::error_code
createTemporaryFile(const Twine &Model, int &ResultFD,
- llvm::SmallVectorImpl<char> &ResultPath, FSEntity Type) {
+ llvm::SmallVectorImpl<char> &ResultPath, FSEntity Type,
+ sys::fs::OpenFlags Flags) {
SmallString<128> Storage;
StringRef P = Model.toNullTerminatedStringRef(Storage);
assert(P.find_first_of(separators(Style::native)) == StringRef::npos &&
"Model must be a simple filename.");
// Use P.begin() so that createUniqueEntity doesn't need to recreate Storage.
- return createUniqueEntity(P.begin(), ResultFD, ResultPath,
- true, owner_read | owner_write, Type);
+ return createUniqueEntity(P.begin(), ResultFD, ResultPath, true,
+ owner_read | owner_write, Type, Flags);
}
static std::error_code
createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD,
- llvm::SmallVectorImpl<char> &ResultPath, FSEntity Type) {
+ llvm::SmallVectorImpl<char> &ResultPath, FSEntity Type,
+ sys::fs::OpenFlags Flags = sys::fs::F_None) {
const char *Middle = Suffix.empty() ? "-%%%%%%" : "-%%%%%%.";
return createTemporaryFile(Prefix + Middle + Suffix, ResultFD, ResultPath,
- Type);
+ Type, Flags);
}
std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix,
int &ResultFD,
- SmallVectorImpl<char> &ResultPath) {
- return createTemporaryFile(Prefix, Suffix, ResultFD, ResultPath, FS_File);
+ SmallVectorImpl<char> &ResultPath,
+ sys::fs::OpenFlags Flags) {
+ return createTemporaryFile(Prefix, Suffix, ResultFD, ResultPath, FS_File,
+ Flags);
}
std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix,
OpenPOWER on IntegriCloud