Use llvm::sys::fs::createTemporaryFile.

llvm-svn: 185717
This commit is contained in:
Rafael Espindola 2013-07-05 20:00:06 +00:00
parent 325fa0fd93
commit a36e78ef5d
9 changed files with 16 additions and 23 deletions

View File

@ -146,11 +146,10 @@ bool FileRemapper::flushToFile(StringRef outputPath, DiagnosticsEngine &Diag) {
} else {
SmallString<64> tempPath;
tempPath = path::filename(origFE->getName());
tempPath += "-%%%%%%%%";
tempPath += path::extension(origFE->getName());
int fd;
if (fs::unique_file(tempPath.str(), fd, tempPath) != llvm::errc::success)
if (fs::createTemporaryFile(path::filename(origFE->getName()),
path::extension(origFE->getName()), fd,
tempPath))
return report("Could not create file: " + tempPath.str(), Diag);
llvm::raw_fd_ostream newOut(fd, /*shouldClose=*/true);

View File

@ -140,8 +140,8 @@ void CXXRecordDecl::viewInheritance(ASTContext& Context) const {
int FD;
SmallString<128> Filename;
error_code EC = sys::fs::unique_file(Self.getAsString() + "-%%%%%%.dot", FD,
Filename);
error_code EC =
sys::fs::createTemporaryFile(Self.getAsString(), "dot", FD, Filename);
if (EC) {
llvm::errs() << "Error: " << EC.message() << "\n";
return;

View File

@ -1616,7 +1616,7 @@ std::string Driver::GetTemporaryPath(StringRef Prefix, const char *Suffix)
const {
SmallString<128> Path;
llvm::error_code EC =
llvm::sys::fs::unique_file(Prefix + "-%%%%%%." + Suffix, Path);
llvm::sys::fs::createTemporaryFile(Prefix, Suffix, Path);
if (EC) {
Diag(clang::diag::err_unable_to_make_temp) << EC.message();
return "";

View File

@ -1244,7 +1244,7 @@ static std::string GetPreamblePCHPath() {
return TmpFile;
SmallString<128> Path;
llvm::sys::fs::unique_file("preamble-%%%%%%.pch", Path);
llvm::sys::fs::createTemporaryFile("preamble", "pch", Path);
return Path.str();
}

View File

@ -855,13 +855,9 @@ static void compileModule(CompilerInstance &ImportingInstance,
IK));
} else {
// Create a temporary module map file.
TempModuleMapFileName = Module->Name;
TempModuleMapFileName += "-%%%%%%%%.map";
int FD;
if (llvm::sys::fs::unique_file(TempModuleMapFileName.str(), FD,
TempModuleMapFileName,
/*makeAbsolute=*/true)
!= llvm::errc::success) {
if (llvm::sys::fs::createTemporaryFile(Module->Name, "map", FD,
TempModuleMapFileName)) {
ImportingInstance.getDiagnostics().Report(diag::err_module_map_temp_file)
<< TempModuleMapFileName;
return;

View File

@ -76,12 +76,10 @@ class FixItRewriteToTemp : public FixItOptions {
public:
std::string RewriteFilename(const std::string &Filename, int &fd) {
SmallString<128> Path;
Path = llvm::sys::path::filename(Filename);
Path += "-%%%%%%%%";
Path += llvm::sys::path::extension(Filename);
SmallString<128> NewPath;
llvm::sys::fs::unique_file(Path.str(), fd, NewPath);
return NewPath.str();
llvm::sys::fs::createTemporaryFile(llvm::sys::path::filename(Filename),
llvm::sys::path::extension(Filename), fd,
Path);
return Path.str();
}
};
} // end anonymous namespace

View File

@ -700,7 +700,7 @@ public:
static ExplodedNode::Auditor* CreateUbiViz() {
SmallString<128> P;
int FD;
llvm::sys::fs::unique_file("llvm_ubi-%%%%%%", FD, P);
llvm::sys::fs::createTemporaryFile("llvm_ubi", "", FD, P);
llvm::errs() << "Writing '" << P.str() << "'.\n";
OwningPtr<llvm::raw_fd_ostream> Stream;

View File

@ -194,7 +194,7 @@ public:
SmallString<1024> Path;
int FD;
llvm::error_code EC =
llvm::sys::fs::unique_file(Twine(Name) + "%%%%%%", FD, Path);
llvm::sys::fs::createTemporaryFile(Name, "", FD, Path);
assert(!EC);
(void)EC;

View File

@ -63,7 +63,7 @@ class RewriterTestContext {
SmallString<1024> Path;
int FD;
llvm::error_code EC =
llvm::sys::fs::unique_file(Twine(Name) + "%%%%%%", FD, Path);
llvm::sys::fs::createTemporaryFile(Name, "", FD, Path);
assert(!EC);
(void)EC;