diff options
| author | Martin Ridgers <[email protected]> | 2021-12-16 13:38:00 +0100 |
|---|---|---|
| committer | Martin Ridgers <[email protected]> | 2022-01-05 09:34:12 +0100 |
| commit | 6f3d3d86768c71b0c90d5cf64532b4e368f7410e (patch) | |
| tree | eaa190e1c9807664381a9fe7660c68b2a00e6711 | |
| parent | GetRunningExecutablePath() implementation for Mac (diff) | |
| download | zen-6f3d3d86768c71b0c90d5cf64532b4e368f7410e.tar.xz zen-6f3d3d86768c71b0c90d5cf64532b4e368f7410e.zip | |
An implementation of PathFromHandle() for Mac
| -rw-r--r-- | zencore/filesystem.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
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 <fcntl.h> # include <libproc.h> # include <sys/stat.h> +# include <sys/syslimits.h> # include <unistd.h> #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 } |