diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-06-14 16:43:15 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-06-14 16:43:15 +0000 |
commit | 6a6f04a3b62f882c33f98cb19d9a482d5c6e5779 (patch) | |
tree | a0c6760091318c6ecc58bf94ec81b129f5015352 | |
parent | 3e030e178ad14a0a67d29fe02e38a1adac2de145 (diff) | |
download | bcm5719-llvm-6a6f04a3b62f882c33f98cb19d9a482d5c6e5779.tar.gz bcm5719-llvm-6a6f04a3b62f882c33f98cb19d9a482d5c6e5779.zip |
Convert a use of sys::Path::GetTemporaryDirectory.
llvm-svn: 183987
-rw-r--r-- | llvm/include/llvm/Support/GraphWriter.h | 18 | ||||
-rw-r--r-- | llvm/lib/Support/GraphWriter.cpp | 19 |
2 files changed, 17 insertions, 20 deletions
diff --git a/llvm/include/llvm/Support/GraphWriter.h b/llvm/include/llvm/Support/GraphWriter.h index b0213640191..62547ddf0ce 100644 --- a/llvm/include/llvm/Support/GraphWriter.h +++ b/llvm/include/llvm/Support/GraphWriter.h @@ -319,25 +319,23 @@ raw_ostream &WriteGraph(raw_ostream &O, const GraphType &G, return O; } -std::string createGraphFilename(const Twine &Name); +std::string createGraphFilename(const Twine &Name, int &FD); template <typename GraphType> std::string WriteGraph(const GraphType &G, const Twine &Name, bool ShortNames = false, const Twine &Title = "") { - std::string Filename = createGraphFilename(Name); - errs() << "Writing '" << Filename << "'... "; + int FD; + std::string Filename = createGraphFilename(Name, FD); + raw_fd_ostream O(FD, /*shouldClose=*/ true); - std::string ErrorInfo; - raw_fd_ostream O(Filename.c_str(), ErrorInfo); - - if (ErrorInfo.empty()) { - llvm::WriteGraph(O, G, ShortNames, Title); - errs() << " done. \n"; - } else { + if (FD == -1) { errs() << "error opening file '" << Filename << "' for writing!\n"; return ""; } + llvm::WriteGraph(O, G, ShortNames, Title); + errs() << " done. \n"; + return Filename; } diff --git a/llvm/lib/Support/GraphWriter.cpp b/llvm/lib/Support/GraphWriter.cpp index f651e25e766..163345e4e65 100644 --- a/llvm/lib/Support/GraphWriter.cpp +++ b/llvm/lib/Support/GraphWriter.cpp @@ -66,18 +66,17 @@ StringRef llvm::DOT::getColorString(unsigned ColorNumber) { return Colors[ColorNumber % NumColors]; } -std::string llvm::createGraphFilename(const Twine &Name) { - std::string ErrMsg; - sys::Path Filename = sys::Path::GetTemporaryDirectory(&ErrMsg); - if (Filename.isEmpty()) { - errs() << "Error: " << ErrMsg << "\n"; - return ""; - } - Filename.appendComponent((Name + ".dot").str()); - if (Filename.makeUnique(true,&ErrMsg)) { - errs() << "Error: " << ErrMsg << "\n"; +std::string llvm::createGraphFilename(const Twine &Name, int &FD) { + FD = -1; + SmallString<128> Filename; + error_code EC = sys::fs::unique_file(Twine(Name) + "-%%%%%%%.dot", + FD, Filename); + if (EC) { + errs() << "Error: " << EC.message() << "\n"; return ""; } + + errs() << "Writing '" << Filename << "'... "; return Filename.str(); } |