libcruft-util/cruft/util/posix/dir.cpp

45 lines
977 B
C++
Raw Normal View History

2015-08-10 15:46:13 +10:00
/*
2018-08-04 15:14:06 +10:00
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
2015-08-10 15:46:13 +10:00
*
* Copyright 2015 Danny Robson <danny@nerdcruft.net>
*/
#include "dir.hpp"
2015-08-10 15:46:13 +10:00
#include "except.hpp"
2015-08-10 15:46:13 +10:00
using cruft::posix::dir;
2015-08-10 15:46:13 +10:00
///////////////////////////////////////////////////////////////////////////////
dir::dir (const std::filesystem::path &p):
m_handle (::opendir (p.string<char> ().c_str ()))
2015-08-10 15:46:13 +10:00
{
if (!m_handle)
error::throw_code ();
2015-08-10 15:46:13 +10:00
}
//-----------------------------------------------------------------------------
dir::~dir ()
{
error::try_code (closedir (m_handle));
2015-08-10 15:46:13 +10:00
}
///////////////////////////////////////////////////////////////////////////////
dir::operator DIR* (void)
{
return m_handle;
}
///////////////////////////////////////////////////////////////////////////////
void
dir::rewind (void)
{
rewinddir (m_handle);
}