fix(libs): find the executable directory on macOS

libSceFont and libSceNpEntitlementAccess located the executable
through /proc/self/exe, which macOS does not have, so finding the
system fonts and the entitlements file threw there. Use
_NSGetExecutablePath and resolve the path with
std::filesystem::canonical on macOS. Linux and Windows are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ahir Barman Maji 2026-10-12 02:38:05 +05:30
parent 68ac73f3df
commit f30f3e8a84
2 changed files with 22 additions and 0 deletions

View File

@ -6,6 +6,8 @@
#include <system_error>
#ifdef _WIN32
#include <windows.h>
#elif defined(__APPLE__)
#include <mach-o/dyld.h>
#endif
#include "prx/libSceFont/include/FontInternal.hpp"
@ -91,6 +93,15 @@ std::filesystem::path ExecutableDirectory() {
const auto length = GetModuleFileNameW(nullptr, module, MAX_PATH);
if (length == 0 || length == MAX_PATH) throw std::runtime_error("libSceFont: cannot locate the executable");
return std::filesystem::path(module).parent_path();
#elif defined(__APPLE__)
std::uint32_t size = 0;
_NSGetExecutablePath(nullptr, &size);
std::vector<char> executable(size);
std::error_code error;
std::filesystem::path path;
if (_NSGetExecutablePath(executable.data(), &size) == 0) path = std::filesystem::canonical(executable.data(), error);
if (path.empty()) throw std::runtime_error("libSceFont: cannot locate the executable");
return path.parent_path();
#else
return std::filesystem::read_symlink("/proc/self/exe").parent_path();
#endif

View File

@ -12,6 +12,8 @@
#include <vector>
#ifdef _WIN32
#include <windows.h>
#elif defined(__APPLE__)
#include <mach-o/dyld.h>
#endif
static constexpr int SCE_NP_ENTITLEMENT_ACCESS_ERROR_PARAMETER = static_cast<int>(0x80558003);
@ -28,6 +30,15 @@ std::filesystem::path EntitlementsPath() {
const auto length = GetModuleFileNameW(nullptr, module, MAX_PATH);
if (length == 0 || length == MAX_PATH) throw std::runtime_error("NpEntitlementAccess: cannot locate the executable");
return std::filesystem::path(module).parent_path() / "anyps5-entitlements.ini";
#elif defined(__APPLE__)
std::uint32_t size = 0;
_NSGetExecutablePath(nullptr, &size);
std::vector<char> executable(size);
std::error_code error;
std::filesystem::path path;
if (_NSGetExecutablePath(executable.data(), &size) == 0) path = std::filesystem::canonical(executable.data(), error);
if (path.empty()) throw std::runtime_error("NpEntitlementAccess: cannot locate the executable");
return path.parent_path() / "anyps5-entitlements.ini";
#else
return std::filesystem::read_symlink("/proc/self/exe").parent_path() / "anyps5-entitlements.ini";
#endif