From 44282b2da6334a83c6c5def96d9a83fde317f6e9 Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Thu, 16 Dec 2021 13:36:50 +0100 Subject: Added block of POSIX includes for Mac --- zencore/filesystem.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'zencore/filesystem.cpp') diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp index 9274b35de..fa9183945 100644 --- a/zencore/filesystem.cpp +++ b/zencore/filesystem.cpp @@ -18,7 +18,9 @@ # include # include # include -#else +#endif + +#if ZEN_PLATFORM_LINUX # include # include # include @@ -26,6 +28,13 @@ # include #endif +#if ZEN_PLATFORM_MAC +# include +# include +# include +# include +#endif + #include #include -- cgit v1.2.3 From ce01fd6c9c96c3217b59264c6cca4cb8240701be Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Thu, 16 Dec 2021 13:37:06 +0100 Subject: Removed unused include statement --- zencore/filesystem.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'zencore/filesystem.cpp') diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp index fa9183945..a15a7583d 100644 --- a/zencore/filesystem.cpp +++ b/zencore/filesystem.cpp @@ -24,7 +24,6 @@ # include # include # include -# include # include #endif -- cgit v1.2.3 From 93397b94ae9910427bbb89d6200002ac08580bf1 Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Thu, 16 Dec 2021 13:37:27 +0100 Subject: GetRunningExecutablePath() implementation for Mac --- zencore/filesystem.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'zencore/filesystem.cpp') diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp index a15a7583d..1977e4293 100644 --- a/zencore/filesystem.cpp +++ b/zencore/filesystem.cpp @@ -30,6 +30,7 @@ #if ZEN_PLATFORM_MAC # include # include +# include # include # include #endif @@ -960,8 +961,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 } -- cgit v1.2.3 From 6f3d3d86768c71b0c90d5cf64532b4e368f7410e Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Thu, 16 Dec 2021 13:38:00 +0100 Subject: An implementation of PathFromHandle() for Mac --- zencore/filesystem.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'zencore/filesystem.cpp') diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp index 1977e4293..878d20c42 100644 --- a/zencore/filesystem.cpp +++ b/zencore/filesystem.cpp @@ -32,6 +32,7 @@ # include # include # include +# include # include #endif @@ -930,18 +931,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 } -- cgit v1.2.3 From 182c075db09ca641cc8bcb61b53c86c20f4c1b7b Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Thu, 16 Dec 2021 13:38:19 +0100 Subject: CloneFile()'s unimplemented on Mac but shouldn't be a compile error --- zencore/filesystem.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'zencore/filesystem.cpp') diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp index 878d20c42..95b92277b 100644 --- a/zencore/filesystem.cpp +++ b/zencore/filesystem.cpp @@ -452,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 } -- cgit v1.2.3