Is it possible to disable setlocale () in a process?

Currently, we are faced with the problem that an external component (we, unfortunately, do not know which one) loads when using the Windows file open / save dialog, some systems change the process locale, possibly by calling setlocale(LC_ALL, "") .

This will ruin our application because it depends on the standard locale (which is not changed by any of our own components at runtime).

Thus, we need to make sure that either setlocale() never has any effect when called inside the process, or we need to detect when this function is called, and then reset the locale to the "C" standard.

Is there a way to achieve any of these goals?

+5
source share
1 answer

This is not a direct answer to the question, but a solution to the problem. It turned out that a recent iCloud update caused this problem, see this post, for example:

https://discussions.apple.com/thread/5356698

So, there are two solutions, one of which renames ShellStreams.dll , and the other completely removes iClould (if it is not used in any case).

The actual protection that can be used makes setlocale() just thread-global instead of process-global:

 _configthreadlocale(_ENABLE_PER_THREAD_LOCALE) 

It worked in a simple test application, but not in the real world (so this is not a real solution for us).

The most reliable way to solve this problem if you cannot remove iCloud is to use the "_l" functions that work using a specific locale:

 _locale_t localeInfo = _create_locale(LC_NUMERIC, "C"); _sprintf_l(string, format, localeInfo, number); _free_locale(localeInfo); 
+2
source

Source: https://habr.com/ru/post/1203629/


All Articles