1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00

SystemStats (Linux): Fix locale clobbering

This fixes a bug where the wrong locale was being restored when querying locale 
information.
This commit is contained in:
Oli 2025-10-23 12:21:31 +01:00
parent a2a9c54e31
commit 2da6a5fb62

View file

@ -43,10 +43,11 @@ static String getCpuInfo (const char* key)
static String getLocaleValue (nl_item key)
{
auto oldLocale = ::setlocale (LC_ALL, "");
auto result = String::fromUTF8 (nl_langinfo (key));
::setlocale (LC_ALL, oldLocale);
return result;
const String oldLocale { ::setlocale (LC_ALL, nullptr) };
const ScopeGuard restore { [oldLocale] { ::setlocale (LC_ALL, oldLocale.toRawUTF8()); } };
::setlocale (LC_ALL, ""); // restore locale from env
return String::fromUTF8 (nl_langinfo (key));
}
#endif