1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:17:36 +00:00

LibCore: Add CDirIterator, and use it in everything rather than readdir

This commit is contained in:
Robin Burchell 2019-05-27 09:26:54 +02:00 committed by Andreas Kling
parent f352a5094d
commit 9d2b08e06e
9 changed files with 152 additions and 55 deletions

30
LibCore/CDirIterator.h Normal file
View file

@ -0,0 +1,30 @@
#pragma once
#include <dirent.h>
#include <AK/AKString.h>
class CDirIterator {
public:
enum Flags {
NoFlags = 0x0,
SkipDots = 0x1,
};
CDirIterator(const String& path, Flags = Flags::NoFlags);
~CDirIterator();
bool has_error() const { return m_error != 0; }
int error() const { return m_error; }
const char* error_string() const { return strerror(m_error); }
bool has_next();
String next_path();
private:
DIR* m_dir = nullptr;
int m_error = 0;
String m_next;
int m_flags;
bool advance_next();
};