Some changes to directory code to help it compile on newer gcc compilers

This commit is contained in:
KimLS 2017-06-10 22:23:27 -07:00
parent 6575d106de
commit 995a4527da
2 changed files with 16 additions and 10 deletions

View File

@ -6,28 +6,35 @@
#include <dirent.h>
#endif
struct EQ::Directory::impl {
DIR *m_dir;
};
EQ::Directory::Directory(const std::string &path)
{
m_dir = opendir(path.c_str());
m_impl = new impl;
m_impl->m_dir = opendir(path.c_str());
}
EQ::Directory::~Directory()
{
if (m_dir) {
closedir(m_dir);
if (m_impl->m_dir) {
closedir(m_impl->m_dir);
}
delete m_impl;
}
bool EQ::Directory::Exists()
{
return m_dir != nullptr;
return m_impl->m_dir != nullptr;
}
void EQ::Directory::GetFiles(std::vector<std::string>& files)
{
if (m_dir) {
if (m_impl->m_dir) {
struct dirent *ent;
while ((ent = readdir(m_dir)) != nullptr) {
while ((ent = readdir(m_impl->m_dir)) != nullptr) {
switch (ent->d_type) {
case DT_REG:
files.push_back(ent->d_name);
@ -37,6 +44,6 @@ void EQ::Directory::GetFiles(std::vector<std::string>& files)
}
}
rewinddir(m_dir);
rewinddir(m_impl->m_dir);
}
}

View File

@ -3,8 +3,6 @@
#include <string>
#include <vector>
struct DIR;
namespace EQ {
class Directory
{
@ -15,6 +13,7 @@ namespace EQ {
bool Exists();
void GetFiles(std::vector<std::string> &files);
private:
DIR *m_dir;
struct impl;
impl *m_impl;
};
}