59 {
60#if defined(_WIN32)
61 HMODULE module_handle = nullptr;
62 if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
reinterpret_cast<LPCWSTR
>(&
MODULE_LOCATION_ANCHOR), &module_handle) == 0) {
63 return {};
64 }
65
66 std::vector<wchar_t> module_path(1024);
67 while (true) {
68 const DWORD path_length = GetModuleFileNameW(module_handle, module_path.data(), static_cast<DWORD>(module_path.size()));
69 if (path_length == 0) {
70 return {};
71 }
72 if (path_length < module_path.size() - 1U) {
73 return std::filesystem::path(std::wstring(module_path.data(), path_length)).parent_path();
74 }
75 module_path.resize(module_path.size() * 2U);
76 }
77#elif defined(__APPLE__) || defined(__linux__)
78 Dl_info module_info{};
80 return {};
81 }
82 return std::filesystem::path(module_info.dli_fname).parent_path();
83#else
84 return {};
85#endif
86 }
const int MODULE_LOCATION_ANCHOR