diff --git a/io.cpp b/io.cpp index dd3b0729..e62f7b3d 100644 --- a/io.cpp +++ b/io.cpp @@ -131,6 +131,24 @@ indenter::~indenter () m_owner->rdbuf (m_dest); } +//---------------------------------------------------------------------------- +scoped_cwd::scoped_cwd (): + m_original (getcwd (nullptr, 0)) +{ + if (!m_original) + throw errno_error (); +} + + +scoped_cwd::~scoped_cwd () { + set_cwd (m_original.data ()); +} + + +void +util::set_cwd (const boost::filesystem::path &path) { + chdir (path.string ().c_str ()); +} //---------------------------------------------------------------------------- #if defined(HAVE_MMAP) @@ -189,4 +207,3 @@ mapped_file::data (void) const { } #endif - diff --git a/io.hpp b/io.hpp index a42f0fc4..e3a77d7d 100644 --- a/io.hpp +++ b/io.hpp @@ -75,6 +75,18 @@ namespace util { virtual ~indenter (); }; + + class scoped_cwd { + public: + scoped_cwd (); + ~scoped_cwd (); + + protected: + scoped_malloc m_original; + }; + + + void set_cwd (const boost::filesystem::path &); #if defined(HAVE_MMAP)