https://github.com/Kitware/CMake
Tip revision: 6fe5df13c274441a1e1a1b10e558ef46db60bf4b authored by Brad King on 01 February 2022, 15:51:25 UTC
CMake 3.21.5
CMake 3.21.5
Tip revision: 6fe5df1
cmWorkingDirectory.cxx
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmWorkingDirectory.h"
#include <cerrno>
#include "cmSystemTools.h"
cmWorkingDirectory::cmWorkingDirectory(std::string const& newdir)
{
this->OldDir = cmSystemTools::GetCurrentWorkingDirectory();
this->SetDirectory(newdir);
}
cmWorkingDirectory::~cmWorkingDirectory()
{
this->Pop();
}
bool cmWorkingDirectory::SetDirectory(std::string const& newdir)
{
if (cmSystemTools::ChangeDirectory(newdir)) {
this->ResultCode = 0;
return true;
}
this->ResultCode = errno;
return false;
}
void cmWorkingDirectory::Pop()
{
if (!this->OldDir.empty()) {
this->SetDirectory(this->OldDir);
this->OldDir.clear();
}
}