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

4
io.hpp
View File

@ -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: