Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
locale.c: Separate setlocale into bool and query
There are two ways that POSIX specifies to change the locale. The earlier interface is setlocale(), which either returns NULL on failure, or a pointer to global static memory containing the character string of the changed locale. That may very well be the input locale name, or the platform can return something that to it is equivalent. The second, from the 2008 standard, is newlocale() which returns either NULL on failure or a pointer to an opaque object, and there is no official way to find out what the current locale is. (The next proposed version of the Standard will finally add this capability.) Some platforms have introduced a querylocale() to get this information. (glibc has a hidden function to do so.) Note that the return value of setlocale() is problematic, valid only until the next call to that function, which might be immediately from another thread. The value, if needed, has to be saved to a per-thread buffer in a critical section with the function call. That buffer presents opportunities for leaking or being destroyed too early, resulting in heap use after being freed. And it turns out that the value is often not needed; often what is needed is only if the operation failed or succeeded. This commit starts the process of limiting the use of the changed value to just where its really needed. It does this by changing the newlocale() form to return success/failure, removing all the macros that think you can set and get the value in the same operation, and minor fixups.
- Loading branch information