diff --git a/src/openrct2.c b/src/openrct2.c index 6a6692d8d9..dc68917c8d 100644 --- a/src/openrct2.c +++ b/src/openrct2.c @@ -47,6 +47,9 @@ #include #include #include +#if defined(__APPLE__) && defined(__MACH__) +#include +#endif // defined(__APPLE__) && defined(__MACH__) #endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) int gOpenRCT2StartupAction = STARTUP_ACTION_TITLE; @@ -171,14 +174,23 @@ static void openrct2_set_exe_path() tempPath[exeDelimiterIndex] = L'\0'; _wfullpath(exePath, tempPath, MAX_PATH); WideCharToMultiByte(CP_UTF8, 0, exePath, countof(exePath), gExePath, countof(gExePath), NULL, NULL); -#else +#else // _WIN32 char exePath[MAX_PATH]; +#if defined(__APPLE__) && defined(__MACH__) + int size = MAX_PATH; + int result = _NSGetExecutablePath(exePath, &size); + if (result != 0) { + log_fatal("failed to get path"); + } + exePath[MAX_PATH - 1] = '\0'; +#else // defined(__APPLE__) && defined(__MACH__) ssize_t bytesRead; bytesRead = readlink("/proc/self/exe", exePath, MAX_PATH); if (bytesRead == -1) { log_fatal("failed to read /proc/self/exe"); } exePath[bytesRead - 1] = '\0'; +#endif // defined(__APPLE__) && defined(__MACH__) log_verbose("######################################## Setting exe path to %s", exePath); char *exeDelimiter = strrchr(exePath, platform_get_path_separator()); if (exeDelimiter == NULL)