]> Savannah Git Hosting - gnulib.git/commitdiff
localcharset, nl_langinfo: Fix return value for UTF-8 locales on MSVC.
authorBruno Haible <bruno@clisp.org>
Tue, 2 Jul 2019 18:56:26 +0000 (20:56 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 2 Jul 2019 18:56:26 +0000 (20:56 +0200)
* lib/localcharset.c (locale_charset): Return "UTF-8" instead of
"CPutf8".
* lib/nl_langinfo.c (ctype_codeset): Likewise.

ChangeLog
lib/localcharset.c
lib/nl_langinfo.c

index 7b3d3bdeb7a6df8ba3fcd9f1fb09c2f0e6735bde..77d8e9e6a00e231fa961c8d543532a7a34e6ada6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2019-07-02  Bruno Haible  <bruno@clisp.org>
+
+       localcharset, nl_langinfo: Fix return value for UTF-8 locales on MSVC.
+       * lib/localcharset.c (locale_charset): Return "UTF-8" instead of
+       "CPutf8".
+       * lib/nl_langinfo.c (ctype_codeset): Likewise.
+
 2019-07-02  Bruno Haible  <bruno@clisp.org>
 
        getcwd: Fix crash when invoked with size = 0 on MSVC.
index 80a20b1c78fa1fee8427b1d5e643146ecbbcf35a..173d11650c079e7a5786f2646cea6519c15702a7 100644 (file)
@@ -787,7 +787,12 @@ locale_charset (void)
         encoding is the best bet.  */
       sprintf (buf, "CP%u", GetACP ());
     }
-  codeset = buf;
+  /* For a locale name such as "French_France.65001", in Windows 10,
+     setlocale now returns "French_France.utf8" instead.  */
+  if (strcmp (buf + 2, "65001") == 0 || strcmp (buf + 2, "utf8") == 0)
+    codeset = "UTF-8";
+  else
+    codeset = buf;
 
 # elif defined OS2
 
index e8a5595aeed9364d72c2059a23800c433a5e4928..76579a8ad40016505798c54680d84ce420f1dfb0 100644 (file)
@@ -76,9 +76,15 @@ ctype_codeset (void)
     memmove (buf + 2, codeset, codesetlen + 1);
   else
     sprintf (buf + 2, "%u", GetACP ());
-  codeset = memcpy (buf, "CP", 2);
-# endif
+  /* For a locale name such as "French_France.65001", in Windows 10,
+     setlocale now returns "French_France.utf8" instead.  */
+  if (strcmp (buf + 2, "65001") == 0 || strcmp (buf + 2, "utf8") == 0)
+    return "UTF-8";
+  else
+    return memcpy (buf, "CP", 2);
+# else
   return codeset;
+#endif
 }
 #endif