Luna/libos/include/os/Directory.h

51 lines
882 B
C
Raw Normal View History

2023-04-28 19:15:41 +00:00
#pragma once
#include <dirent.h>
#include <luna/SharedPtr.h>
#include <luna/String.h>
2023-04-28 20:41:44 +00:00
#include <luna/Vector.h>
#include <os/Path.h>
2023-04-28 19:15:41 +00:00
namespace os
{
class Directory
{
public:
static Result<SharedPtr<Directory>> open(const Path& path);
2023-04-28 19:15:41 +00:00
enum class Filter
{
None,
Hidden,
ParentAndBase
};
Result<String> next(Filter filter);
Result<Vector<String>> list_names(Filter filter);
struct Entry
{
String name;
mode_t mode;
usize size;
time_t mtime;
};
Result<Vector<Entry>> list(Filter filter);
2023-04-28 20:41:44 +00:00
void rewind();
2023-04-28 19:15:41 +00:00
int fd()
{
return dirfd(m_dirp);
}
~Directory();
private:
Directory(Badge<Directory>);
DIR* m_dirp { nullptr };
};
}