From 0d3a034725bdf221f7ea47eee286854facac4979 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 7 Jul 2020 13:26:14 -0400 Subject: cmGeneratedFileStream: Optionally use custom temporary file extension --- Source/cmGeneratedFileStream.cxx | 14 ++++++++++++-- Source/cmGeneratedFileStream.h | 9 +++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Source/cmGeneratedFileStream.cxx b/Source/cmGeneratedFileStream.cxx index 9cee0e6..119067e 100644 --- a/Source/cmGeneratedFileStream.cxx +++ b/Source/cmGeneratedFileStream.cxx @@ -122,10 +122,15 @@ void cmGeneratedFileStreamBase::Open(std::string const& name) // Create the name of the temporary file. this->TempName = name; #if defined(__VMS) - this->TempName += "_tmp"; + this->TempName += "_"; #else - this->TempName += ".tmp"; + this->TempName += "."; #endif + if (!this->TempExt.empty()) { + this->TempName += this->TempExt; + } else { + this->TempName += "tmp"; + } // Make sure the temporary file that will be used is not present. cmSystemTools::RemoveFile(this->TempName); @@ -216,3 +221,8 @@ void cmGeneratedFileStream::SetName(const std::string& fname) { this->Name = fname; } + +void cmGeneratedFileStream::SetTempExt(std::string const& ext) +{ + this->TempExt = ext; +} diff --git a/Source/cmGeneratedFileStream.h b/Source/cmGeneratedFileStream.h index a9088ac..3dee142 100644 --- a/Source/cmGeneratedFileStream.h +++ b/Source/cmGeneratedFileStream.h @@ -43,6 +43,9 @@ protected: // The name of the final destination file for the output. std::string Name; + // The extension of the temporary file. + std::string TempExt; + // The name of the temporary file. std::string TempName; @@ -138,6 +141,12 @@ public: * the output file to be changed during the use of cmGeneratedFileStream. */ void SetName(const std::string& fname); + + /** + * Set set a custom temporary file extension used with 'Open'. + * This does not work if the file was opened by the constructor. + */ + void SetTempExt(std::string const& ext); }; #endif -- cgit v0.12