summaryrefslogtreecommitdiff
path: root/include/fud_directory.hpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-09-28 11:14:31 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-09-28 11:14:31 -0500
commitb6967c8a9190efa4e9128850fa723fe3ea3140f7 (patch)
tree101be12055abd27968fce2666d573c80f8afe22d /include/fud_directory.hpp
parent987466c74332025fae74d196ff680a57ccb247a2 (diff)
Expand directory interface, remove FileStatus for FudStatus.
Diffstat (limited to 'include/fud_directory.hpp')
-rw-r--r--include/fud_directory.hpp43
1 files changed, 42 insertions, 1 deletions
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 <cstdint>
#include <cstdio>
+#include <ctime>
#include <dirent.h>
#include <optional>
-#include <ctime>
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<DirectoryEntry, FudStatus> 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<DirectoryEntry, FudStatus> info();
+
Result<std::optional<DirectoryEntry>, FudStatus> getNextEntry();
FudStatus reset();
private:
+ bool valid() const;
+
String m_name{};
DIR* m_directory{nullptr};
FudStatus m_status{FudStatus::ObjectInvalid};