diff options
Diffstat (limited to 'Source/cmGeneratedFileStream.cxx')
-rw-r--r-- | Source/cmGeneratedFileStream.cxx | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Source/cmGeneratedFileStream.cxx b/Source/cmGeneratedFileStream.cxx index 254b6bf..53f3077 100644 --- a/Source/cmGeneratedFileStream.cxx +++ b/Source/cmGeneratedFileStream.cxx @@ -27,6 +27,12 @@ #endif //---------------------------------------------------------------------------- +cmGeneratedFileStream::cmGeneratedFileStream(): + cmGeneratedFileStreamBase(), Stream() +{ +} + +//---------------------------------------------------------------------------- cmGeneratedFileStream::cmGeneratedFileStream(const char* name, bool quiet): cmGeneratedFileStreamBase(name), Stream(m_TempName.c_str()) @@ -51,12 +57,40 @@ cmGeneratedFileStream::~cmGeneratedFileStream() } //---------------------------------------------------------------------------- +cmGeneratedFileStream& +cmGeneratedFileStream::Open(const char* name, bool quiet) +{ + // Store the file name and construct the temporary file name. + this->cmGeneratedFileStreamBase::Open(name); + + // Open the temporary output file. + this->Stream::open(m_TempName.c_str()); + + // Check if the file opened. + if(!*this && !quiet) + { + cmSystemTools::Error("Cannot open file for write: ", m_TempName.c_str()); + cmSystemTools::ReportLastSystemError(""); + } + return *this; +} + +//---------------------------------------------------------------------------- void cmGeneratedFileStream::SetCopyIfDifferent(bool copy_if_different) { m_CopyIfDifferent = copy_if_different; } //---------------------------------------------------------------------------- +cmGeneratedFileStreamBase::cmGeneratedFileStreamBase(): + m_Name(), + m_TempName(), + m_CopyIfDifferent(false), + m_Okay(false) +{ +} + +//---------------------------------------------------------------------------- cmGeneratedFileStreamBase::cmGeneratedFileStreamBase(const char* name): m_Name(name), m_TempName(name), @@ -92,6 +126,20 @@ cmGeneratedFileStreamBase::~cmGeneratedFileStreamBase() } //---------------------------------------------------------------------------- +void cmGeneratedFileStreamBase::Open(const char* name) +{ + // Save the original name of the file. + m_Name = name; + + // Create the name of the temporary file. + m_TempName = name; + m_TempName += ".tmp"; + + // Make sure the temporary file that will be used is not present. + cmSystemTools::RemoveFile(m_TempName.c_str()); +} + +//---------------------------------------------------------------------------- int cmGeneratedFileStreamBase::RenameFile(const char* oldname, const char* newname) { |