aboutsummaryrefslogtreecommitdiff
path: root/zencore/filesystem.cpp
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-10-25 14:26:35 +0200
committerMartin Ridgers <[email protected]>2021-10-25 22:50:43 +0200
commita2d68c0a4aa703dbcc8c60c578c64783ba7e3f97 (patch)
treeab7b70f278e10fbdd92b7510440da3dbcb577026 /zencore/filesystem.cpp
parentDisabled unused-value warning as it fires at ZEN_UNUSED() sites (diff)
downloadzen-a2d68c0a4aa703dbcc8c60c578c64783ba7e3f97.tar.xz
zen-a2d68c0a4aa703dbcc8c60c578c64783ba7e3f97.zip
Implemented ScanFile() on POSIX
Diffstat (limited to 'zencore/filesystem.cpp')
-rw-r--r--zencore/filesystem.cpp39
1 files changed, 35 insertions, 4 deletions
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp
index 0f74b44c4..50a82c99b 100644
--- a/zencore/filesystem.cpp
+++ b/zencore/filesystem.cpp
@@ -621,12 +621,43 @@ ScanFile(std::filesystem::path Path, const uint64_t ChunkSize, std::function<voi
ProcessFunc(ReadBuffer.data(), dwBytesRead);
}
-
- return true;
#else
- ZEN_ERROR("ScanFile() is not implemented on this platform");
- return false;
+ int Fd = open(Path.c_str(), O_RDONLY);
+ if (Fd < 0)
+ {
+ return false;
+ }
+
+ bool Success = true;
+
+ void* Buffer = malloc(ChunkSize);
+ while (true)
+ {
+ int BytesRead = read(Fd, Buffer, ChunkSize);
+ if (BytesRead < 0)
+ {
+ Success = false;
+ break;
+ }
+
+ if (BytesRead == 0)
+ {
+ break;
+ }
+
+ ProcessFunc(Buffer, BytesRead);
+ }
+
+ free(Buffer);
+ close(Fd);
+
+ if (!Success)
+ {
+ ThrowLastError("file scan failed");
+ }
#endif // ZEN_PLATFORM_WINDOWS
+
+ return true;
}
std::string