[llvm] r183987 - Convert a use of sys::Path::GetTemporaryDirectory.
Rafael Espindola
rafael.espindola at gmail.com
Fri Jun 14 09:43:16 PDT 2013
Author: rafael
Date: Fri Jun 14 11:43:15 2013
New Revision: 183987
URL: http://llvm.org/viewvc/llvm-project?rev=183987&view=rev
Log:
Convert a use of sys::Path::GetTemporaryDirectory.
Modified:
llvm/trunk/include/llvm/Support/GraphWriter.h
llvm/trunk/lib/Support/GraphWriter.cpp
Modified: llvm/trunk/include/llvm/Support/GraphWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/GraphWriter.h?rev=183987&r1=183986&r2=183987&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/GraphWriter.h (original)
+++ llvm/trunk/include/llvm/Support/GraphWriter.h Fri Jun 14 11:43:15 2013
@@ -319,25 +319,23 @@ raw_ostream &WriteGraph(raw_ostream &O,
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;
}
Modified: llvm/trunk/lib/Support/GraphWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/GraphWriter.cpp?rev=183987&r1=183986&r2=183987&view=diff
==============================================================================
--- llvm/trunk/lib/Support/GraphWriter.cpp (original)
+++ llvm/trunk/lib/Support/GraphWriter.cpp Fri Jun 14 11:43:15 2013
@@ -66,18 +66,17 @@ StringRef llvm::DOT::getColorString(unsi
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();
}
More information about the llvm-commits
mailing list