diff options
| author | JosJuice <josjuice@gmail.com> | 2026-10-03 09:53:13 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-10-03 09:53:13 +0200 |
| commit | af1ab20b356d288208e7324512efed4b0913f79e (patch) | |
| tree | bcb4e06f5f81334876982edf7e69d87120298650 /Source/Core/Common/LocaleUtil.cpp | |
| parent | f76238742c70a3db637f2037b0ed380be4bdead1 (diff) | |
| parent | 622c711ccfa9ce42b9d6b20bca0085f804f66e59 (diff) | |
Merge pull request #14812 from JoshuaVandaele/correct-env-locale
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 |
