aboutsummaryrefslogtreecommitdiff
path: root/zencore/filesystem.cpp
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-10-25 14:21:09 +0200
committerMartin Ridgers <[email protected]>2021-10-25 22:50:43 +0200
commitd4d34b46af975112c16e661d7f8e04c0d9ac7159 (patch)
tree945c2692d71d2297a8f6734d54ff17be8fb0c6c9 /zencore/filesystem.cpp
parentCopyFile() for POSIX (diff)
downloadzen-d4d34b46af975112c16e661d7f8e04c0d9ac7159.tar.xz
zen-d4d34b46af975112c16e661d7f8e04c0d9ac7159.zip
Included a sketch of how CloneFile() could be on Linux
Diffstat (limited to 'zencore/filesystem.cpp')
-rw-r--r--zencore/filesystem.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp
index 181b879db..25fe371c5 100644
--- a/zencore/filesystem.cpp
+++ b/zencore/filesystem.cpp
@@ -408,10 +408,41 @@ CloneFile(std::filesystem::path FromPath, std::filesystem::path ToPath)
const bool AllOk = (TRUE == SetFileInformationByHandle(TargetFile, FileDispositionInfo, &FileDisposition, sizeof FileDisposition));
return AllOk;
-#else
+#elif ZEN_PLATFORM_LINUX
+# if 0
+ struct ScopedFd
+ {
+ ~ScopedFd() { close(Fd); }
+ int Fd;
+ };
+
+ // The 'from' file
+ int FromFd = open(FromPath.c_str(), O_RDONLY);
+ if (FromFd < 0)
+ {
+ return false;
+ }
+ ScopedFd $From = { FromFd };
+
+ // The 'to' file
+ int ToFd = open(ToPath.c_str(), O_WRONLY|O_CREAT|O_EXCL, 0666);
+ if (ToFd < 0)
+ {
+ return false;
+ }
+ ScopedFd $To = { FromFd };
+
+ ioctl(ToFd, FICLONE, FromFd);
+
+ return false;
+# endif // 0
ZEN_UNUSED(FromPath, ToPath);
ZEN_ERROR("CloneFile() is not implemented on this platform");
return false;
+#elif ZEN_PLATFORM_MAC
+ /* clonefile() syscall if APFS */
+# error not implemented
+ return false;
#endif // ZEN_PLATFORM_WINDOWS
}