From 0967c5252fd2c23733245c5965bb4a193a7bcc85 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 15 Sep 2015 21:09:37 +1000 Subject: [PATCH] io: remove useless chdir wrapper just use chdir directly. --- io.cpp | 26 ++++++++++++-------------- io.hpp | 4 +--- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/io.cpp b/io.cpp index c6ff5c5a..cbbf4a53 100644 --- a/io.cpp +++ b/io.cpp @@ -197,21 +197,19 @@ indenter::~indenter () m_owner->rdbuf (m_dest); } -//---------------------------------------------------------------------------- -scoped_cwd::scoped_cwd (): - m_original(boost::filesystem::canonical (getcwd (nullptr, 0))) -{ ; } - - -scoped_cwd::~scoped_cwd () { - set_cwd (m_original); +////////////////////////////////////////////////////////////////////////////// +scoped_cwd::scoped_cwd () +{ + m_original.resize (16); + while (getcwd (&m_original[0], m_original.size ()) == nullptr && errno == ERANGE) + m_original.resize (m_original.size () * 2); + errno_error::try_code (); } -void -util::set_cwd (const boost::filesystem::path &path) { - CHECK (path.string ().size () > 0); - - if (chdir (path.string ().c_str ()) != 0) - throw errno_error (); +//----------------------------------------------------------------------------- +scoped_cwd::~scoped_cwd () +{ + if (!chdir (m_original.c_str ())) + errno_error::throw_code (); } diff --git a/io.hpp b/io.hpp index cfb4b2bf..c63fe0ff 100644 --- a/io.hpp +++ b/io.hpp @@ -134,12 +134,10 @@ namespace util { ~scoped_cwd (); protected: - boost::filesystem::path m_original; + std::string m_original; }; - void set_cwd (const boost::filesystem::path &); - //------------------------------------------------------------------------- class path_error : public std::runtime_error { public: