aboutsummaryrefslogtreecommitdiff
path: root/zencore/filesystem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'zencore/filesystem.cpp')
-rw-r--r--zencore/filesystem.cpp42
1 files changed, 32 insertions, 10 deletions
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp
index 9274b35de..95b92277b 100644
--- a/zencore/filesystem.cpp
+++ b/zencore/filesystem.cpp
@@ -18,11 +18,21 @@
# include <atlfile.h>
# include <winioctl.h>
# include <winnt.h>
-#else
+#endif
+
+#if ZEN_PLATFORM_LINUX
# include <dirent.h>
# include <fcntl.h>
# include <sys/stat.h>
-# include <sys/statvfs.h>
+# include <unistd.h>
+#endif
+
+#if ZEN_PLATFORM_MAC
+# include <dirent.h>
+# include <fcntl.h>
+# include <libproc.h>
+# include <sys/stat.h>
+# include <sys/syslimits.h>
# include <unistd.h>
#endif
@@ -442,7 +452,8 @@ CloneFile(std::filesystem::path FromPath, std::filesystem::path ToPath)
return false;
#elif ZEN_PLATFORM_MAC
/* clonefile() syscall if APFS */
-# error not implemented
+ ZEN_UNUSED(FromPath, ToPath);
+ ZEN_ERROR("CloneFile() is not implemented on this platform");
return false;
#endif // ZEN_PLATFORM_WINDOWS
}
@@ -921,18 +932,23 @@ PathFromHandle(void* NativeHandle)
ZEN_UNUSED(FinalLength);
return FullPath;
-#elif ZEN_PLATFORM_LINUX
- char Link[256];
+#elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC
+# if ZEN_PLATFORM_LINUX
+ const char* SelfFdPathFormat = "/proc/self/fd/%d";
+# else
+ const char* SelfFdPathFormat = "dev/fd/%d";
+# endif
+
+ char Link[PATH_MAX];
char Path[64];
- sprintf(Path, "/proc/self/fd/%d", int(uintptr_t(NativeHandle)));
+
+ sprintf(Path, SelfFdPathFormat, int(uintptr_t(NativeHandle)));
ssize_t BytesRead = readlink(Path, Link, sizeof(Link) - 1);
if (BytesRead <= 0)
return std::filesystem::path();
Link[BytesRead] = '\0';
return Link;
-#else
-# error Unimplemented platform
#endif // ZEN_PLATFORM_WINDOWS
}
@@ -952,8 +968,14 @@ GetRunningExecutablePath()
Link[BytesRead] = '\0';
return Link;
-#else
-# error Unimplemented platform
+#elif ZEN_PLATFORM_MAC
+ char Buffer[PROC_PIDPATHINFO_MAXSIZE];
+
+ int SelfPid = GetCurrentProcessId();
+ if (proc_pidpath(SelfPid, Buffer, sizeof(Buffer)) <= 0)
+ return {};
+
+ return Buffer;
#endif // ZEN_PLATFORM_WINDOWS
}