io: remove useless chdir wrapper

just use chdir directly.
This commit is contained in:
Danny Robson 2015-09-15 21:09:37 +10:00
parent b084cb2e4c
commit 0967c5252f
2 changed files with 13 additions and 17 deletions

26
io.cpp
View File

@ -197,21 +197,19 @@ indenter::~indenter ()
m_owner->rdbuf (m_dest); m_owner->rdbuf (m_dest);
} }
//---------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////
scoped_cwd::scoped_cwd (): scoped_cwd::scoped_cwd ()
m_original(boost::filesystem::canonical (getcwd (nullptr, 0))) {
{ ; } m_original.resize (16);
while (getcwd (&m_original[0], m_original.size ()) == nullptr && errno == ERANGE)
m_original.resize (m_original.size () * 2);
scoped_cwd::~scoped_cwd () { errno_error::try_code ();
set_cwd (m_original);
} }
void //-----------------------------------------------------------------------------
util::set_cwd (const boost::filesystem::path &path) { scoped_cwd::~scoped_cwd ()
CHECK (path.string ().size () > 0); {
if (!chdir (m_original.c_str ()))
if (chdir (path.string ().c_str ()) != 0) errno_error::throw_code ();
throw errno_error ();
} }

4
io.hpp
View File

@ -134,12 +134,10 @@ namespace util {
~scoped_cwd (); ~scoped_cwd ();
protected: protected:
boost::filesystem::path m_original; std::string m_original;
}; };
void set_cwd (const boost::filesystem::path &);
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
class path_error : public std::runtime_error { class path_error : public std::runtime_error {
public: public: