Skip to content

Commit 2fcd410

Browse files
committed
Fix latent crash when no components loaded
fix `ghc::filesystem:filesystem_error` on macOS with unreachable '/proc/self/exe' path
1 parent a8ddbda commit 2fcd410

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

Server/Source/util.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ static LARGE_INTEGER yo;
3131
#include <stdlib.h>
3232
#include <sys/time.h>
3333
#include <unistd.h>
34+
#ifdef __APPLE__
35+
#include <mach-o/dyld.h>
36+
#endif
3437
#define SET_TICKER_RESOLUTION(ms)
3538
#define LIBRARY_OPEN(path) dlopen(path, RTLD_LAZY | RTLD_LOCAL)
3639
#define LIBRARY_OPEN_GLOBAL(path) dlopen(path, RTLD_LAZY | RTLD_GLOBAL)
@@ -153,6 +156,19 @@ ghc::filesystem::path GetExecutablePath()
153156
{
154157
return ghc::filesystem::path();
155158
}
159+
#elif defined(__APPLE__)
160+
char path[4096] = { 0 };
161+
uint32_t size = sizeof(path);
162+
if (_NSGetExecutablePath(path, &size) == 0)
163+
{
164+
std::error_code ec;
165+
auto canonicalPath = ghc::filesystem::canonical(path, ec);
166+
return ec ? ghc::filesystem::path(path) : canonicalPath;
167+
}
168+
else
169+
{
170+
return ghc::filesystem::path();
171+
}
156172
#else
157173
return ghc::filesystem::canonical("/proc/self/exe");
158174
#endif

0 commit comments

Comments
 (0)