1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-06-14 06:37:39 +08:00
CMake/Source/cmWorkingDirectory.cxx
Brad King ec1b6157cb Update CMake code using KWSys to account for Status return values
KWSys as of 2021-04-14 changed the return type of `SystemTools`
operations from `bool` to `Status`.  Update our call sites.
This may improve error reporting accuracy in a few places.
2021-04-14 13:14:09 -04:00

37 lines
796 B
C++

/* 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();
}
}