From: Bruno Haible Date: Tue, 2 Jul 2019 18:56:26 +0000 (+0200) Subject: localcharset, nl_langinfo: Fix return value for UTF-8 locales on MSVC. X-Git-Tag: v1.0~4801 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=ece9e261a3aaa585ec8565f71e657cc4d35f0005;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 7b3d3bdeb7..77d8e9e6a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2019-07-02 Bruno Haible + + 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 getcwd: Fix crash when invoked with size = 0 on MSVC. diff --git a/lib/localcharset.c b/lib/localcharset.c index 80a20b1c78..173d11650c 100644 --- a/lib/localcharset.c +++ b/lib/localcharset.c @@ -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 diff --git a/lib/nl_langinfo.c b/lib/nl_langinfo.c index e8a5595aee..76579a8ad4 100644 --- a/lib/nl_langinfo.c +++ b/lib/nl_langinfo.c @@ -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