diff options
| author | Joshua Vandaƫle <joshua@vandaele.software> | 2026-08-12 19:12:42 +0200 |
|---|---|---|
| committer | Joshua Vandaƫle <joshua@vandaele.software> | 2026-08-12 22:25:11 +0200 |
| commit | 622c711ccfa9ce42b9d6b20bca0085f804f66e59 (patch) | |
| tree | da31ac67c5f4b302a163ef1387430164646293cd /Source/Core/Common/LocaleUtil.cpp | |
| parent | 4ff214cdd26f135251d2266d676ed72dc1c2f8c9 (diff) | |
Fix crashes when using `std::locale{""}` with an invalid LC_ALL
Diffstat (limited to 'Source/Core/Common/LocaleUtil.cpp')
| -rw-r--r-- | Source/Core/Common/LocaleUtil.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Source/Core/Common/LocaleUtil.cpp b/Source/Core/Common/LocaleUtil.cpp new file mode 100644 index 0000000000..b6d923f709 --- /dev/null +++ b/Source/Core/Common/LocaleUtil.cpp @@ -0,0 +1,27 @@ +// Copyright 2026 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "Common/LocaleUtil.h" + +#include <locale.h> + +namespace Common +{ +std::locale GetEnvironmentLocale() +{ +#ifdef _WIN32 + if (_locale_t loc = _create_locale(LC_ALL, "")) + { + _free_locale(loc); + return std::locale{""}; + } +#else + if (locale_t loc = newlocale(LC_ALL_MASK, "", static_cast<locale_t>(0))) + { + freelocale(loc); + return std::locale{""}; + } +#endif + return std::locale::classic(); +} +} // Namespace Common |
