setlocale of "POSIX" on Windows
(too old to reply)
Bruno Haible
2017-04-21 13:42:20 UTC
Raw Message
test-mbrtowc5.sh fails on native Windows: The mingw or MSVC setlocale()
understands the special locale name "C", but not the special locale name
"POSIX". This fixes it.

2017-04-21 Bruno Haible <***@clisp.org>

Fix test-mbrtowc5.sh failure on native Windows.
* lib/setlocale.c (setlocale_unixlike): Accept "POSIX" as an alias for

diff --git a/lib/setlocale.c b/lib/setlocale.c
index af8cc90..d2f203e 100644
--- a/lib/setlocale.c
+++ b/lib/setlocale.c
@@ -633,6 +633,13 @@ setlocale_unixlike (int category, const char *locale)
char ll_buf[64];
char CC_buf[64];

+ /* The native Windows implementation of setlocale understands the special
+ locale name "C", but not "POSIX". Therefore map "POSIX" to "C". */
+#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+ if (locale != NULL && strcmp (locale, "POSIX") == 0)
+ locale = "C";
/* First, try setlocale with the original argument unchanged. */
result = setlocale (category, locale);
if (result != NULL)