-error_code unique_file(const Twine &Model, SmallVectorImpl<char> &ResultPath,
- bool MakeAbsolute) {
- // FIXME: This is really inefficient. unique_path creates a path an tries to
- // open it. We should factor the code so that we just don't create/open the
- // file when we don't need it.
- int FD;
- error_code Ret = unique_file(Model, FD, ResultPath, MakeAbsolute, all_read);
- if (Ret)
- return Ret;
+error_code createUniqueFile(const Twine &Model, int &ResultFd,
+ SmallVectorImpl<char> &ResultPath, unsigned Mode) {
+ return createUniqueEntity(Model, ResultFd, ResultPath, false, Mode, FS_File);
+}
+
+error_code createUniqueFile(const Twine &Model,
+ SmallVectorImpl<char> &ResultPath) {
+ int Dummy;
+ return createUniqueEntity(Model, Dummy, ResultPath, false, 0, FS_Name);
+}
+
+static error_code createTemporaryFile(const Twine &Model, int &ResultFD,
+ llvm::SmallVectorImpl<char> &ResultPath,
+ FSEntity Type) {
+ SmallString<128> Storage;
+ StringRef P = Model.toNullTerminatedStringRef(Storage);
+ assert(P.find_first_of(separators) == 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);
+}
+
+static error_code
+createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD,
+ llvm::SmallVectorImpl<char> &ResultPath,
+ FSEntity Type) {
+ return createTemporaryFile(Prefix + "-%%%%%%." + Suffix, ResultFD, ResultPath,
+ Type);
+}
+