From b6967c8a9190efa4e9128850fa723fe3ea3140f7 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Sat, 28 Sep 2024 11:14:31 -0500 Subject: Expand directory interface, remove FileStatus for FudStatus. --- include/fud_directory.hpp | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'include/fud_directory.hpp') diff --git a/include/fud_directory.hpp b/include/fud_directory.hpp index ac48b7b..5a988dc 100644 --- a/include/fud_directory.hpp +++ b/include/fud_directory.hpp @@ -24,9 +24,9 @@ #include #include +#include #include #include -#include namespace fud { @@ -42,6 +42,31 @@ enum class DirectoryEntryType : uint8_t Unknown }; +constexpr const char* DirectoryEntryTypeToString(DirectoryEntryType entryType) +{ + switch (entryType) { + case DirectoryEntryType::Block: + return "Block"; + case DirectoryEntryType::Character: + return "Character"; + case DirectoryEntryType::Directory: + return "Directory"; + case DirectoryEntryType::NamedPipe: + return "Named Pipe"; + case DirectoryEntryType::SymbolicLink: + return "Symbolic Link"; + case DirectoryEntryType::RegularFile: + return "Regular File"; + case DirectoryEntryType::UnixSocket: + return "Unix Socket"; + case DirectoryEntryType::Unknown: + default: + return "Unknown"; + } +} + +struct Stat; + /** \brief Simplified Directory Entry */ struct DirectoryEntry { String name; @@ -49,6 +74,18 @@ struct DirectoryEntry { size_t links; time_t modificationTime; DirectoryEntryType entryType; + + static Result fromStat(const String& name, const Stat& statBuffer); + + [[nodiscard]] constexpr bool isDirectory() const + { + return entryType == DirectoryEntryType::Directory; + } + + [[nodiscard]] constexpr bool isRegularFile() const + { + return entryType == DirectoryEntryType::RegularFile; + } }; class Directory { @@ -70,11 +107,15 @@ class Directory { return m_errorCode; } + Result info(); + Result, FudStatus> getNextEntry(); FudStatus reset(); private: + bool valid() const; + String m_name{}; DIR* m_directory{nullptr}; FudStatus m_status{FudStatus::ObjectInvalid}; -- cgit v1.2.3