diff options
Diffstat (limited to 'source/core')
| -rw-r--r-- | source/core/slang-platform.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/source/core/slang-platform.cpp b/source/core/slang-platform.cpp index aab1f3044..f7e82fdf0 100644 --- a/source/core/slang-platform.cpp +++ b/source/core/slang-platform.cpp @@ -174,12 +174,27 @@ SLANG_COMPILE_TIME_ASSERT(E_OUTOFMEMORY == SLANG_E_OUT_OF_MEMORY); } #else // _WIN32 - /* static */ SlangResult PlatformUtil::getInstancePath([[maybe_unused]] StringBuilder& out) { - // On non Windows it's typically hard to get the instance path, so we'll say not implemented. - // The meaning is also somewhat more ambiguous - is it the exe or the shared library path? +#if defined(__linux__) || defined(__CYGWIN__) + char path[PATH_MAX]; + ssize_t len = readlink("/proc/self/exe", path, sizeof(path) - 1); + if (len == -1) + { + return SLANG_FAIL; + } + + path[len] = '\0'; + String pathString(path); + + // We don't want the instance name, just the path to it + out.clear(); + out.append(Path::getParentDirectory(pathString)); + + return out.getLength() > 0 ? SLANG_OK : SLANG_FAIL; +#else return SLANG_E_NOT_IMPLEMENTED; +#endif } /* static */ SlangResult PlatformUtil::appendResult( |
