]> Savannah Git Hosting - gnulib.git/commitdiff
localename: Fix test failures on mingw.
authorBruno Haible <bruno@clisp.org>
Wed, 2 May 2018 21:36:18 +0000 (23:36 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 2 May 2018 21:36:54 +0000 (23:36 +0200)
* lib/localename.c (gl_locale_name_thread): Remove code specific to
native Windows.
(gl_locale_name_posix): Move code specific to native Windows here.
* tests/test-localename.c (test_locale_name, test_locale_name_posix):
Accept result without charset suffix, as it appears on mingw.

ChangeLog
lib/localename.c
tests/test-localename.c

index 409848f1412982d2039b2b3e74d18a4c6a061872..990fb2499127f79acc01ed460c0a2c8b5c3afd9a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2018-05-02  Bruno Haible  <bruno@clisp.org>
+
+       localename: Fix test failures on mingw.
+       * lib/localename.c (gl_locale_name_thread): Remove code specific to
+       native Windows.
+       (gl_locale_name_posix): Move code specific to native Windows here.
+       * tests/test-localename.c (test_locale_name, test_locale_name_posix):
+       Accept result without charset suffix, as it appears on mingw.
+
 2018-04-28  Paul Smith  <psmith@gnu.org>
 
        bootstrap: Avoid gnulib operations if not needed
index 74c8ee0011df75a3716a017c7f541f8546104efb..f7a7fa5a738e54070e181f615f41bdd2f03a0e9b 100644 (file)
@@ -2786,7 +2786,27 @@ gl_locale_name_thread (int category, const char *categoryname)
   const char *name = gl_locale_name_thread_unsafe (category, categoryname);
   if (name != NULL)
     return struniq (name);
-#elif defined WINDOWS_NATIVE
+#endif
+  /* On WINDOWS_NATIVE, don't use GetThreadLocale() here, because when
+     SetThreadLocale has not been called - which is a very frequent case -
+     the value of GetThreadLocale() ignores past calls to 'setlocale'.  */
+  return NULL;
+}
+
+/* XPG3 defines the result of 'setlocale (category, NULL)' as:
+   "Directs 'setlocale()' to query 'category' and return the current
+    setting of 'local'."
+   However it does not specify the exact format.  Neither do SUSV2 and
+   ISO C 99.  So we can use this feature only on selected systems (e.g.
+   those using GNU C Library).  */
+#if defined _LIBC || ((defined __GLIBC__ && __GLIBC__ >= 2) && !defined __UCLIBC__)
+# define HAVE_LOCALE_NULL
+#endif
+
+const char *
+gl_locale_name_posix (int category, const char *categoryname)
+{
+#if defined WINDOWS_NATIVE
   if (LC_MIN <= category && category <= LC_MAX)
     {
       char *locname = setlocale (category, NULL);
@@ -2796,8 +2816,8 @@ gl_locale_name_thread (int category, const char *categoryname)
         separated list of locales.  We need only one, so we take the
         one corresponding to LC_CTYPE, as the most important for
         character translations.  */
-      if (strchr (locname, ';'))
-       locname = setlocale (LC_CTYPE, NULL);
+      if (category == LC_ALL && strchr (locname, ';'))
+        locname = setlocale (LC_CTYPE, NULL);
 
       /* Convert locale name to LCID.  We don't want to use
          LocaleNameToLCID because (a) it is only available since Vista,
@@ -2808,22 +2828,6 @@ gl_locale_name_thread (int category, const char *categoryname)
         return gl_locale_name_from_win32_LCID (lcid);
     }
 #endif
-  return NULL;
-}
-
-/* XPG3 defines the result of 'setlocale (category, NULL)' as:
-   "Directs 'setlocale()' to query 'category' and return the current
-    setting of 'local'."
-   However it does not specify the exact format.  Neither do SUSV2 and
-   ISO C 99.  So we can use this feature only on selected systems (e.g.
-   those using GNU C Library).  */
-#if defined _LIBC || ((defined __GLIBC__ && __GLIBC__ >= 2) && !defined __UCLIBC__)
-# define HAVE_LOCALE_NULL
-#endif
-
-const char *
-gl_locale_name_posix (int category, const char *categoryname)
-{
   /* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
      On some systems this can be done by the 'setlocale' function itself.  */
 #if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL
index c0952a1335714c72400b477f6ad2187bead5a4c6..7e866c74ec79db478948de497bc1d58dc057d24d 100644 (file)
@@ -155,7 +155,16 @@ test_locale_name (void)
   if (setlocale (LC_ALL, "") != NULL)
     {
       name = gl_locale_name (LC_CTYPE, "LC_CTYPE");
+#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+      /* On native Windows, here,
+           gl_locale_name_thread (LC_CTYPE, "LC_CTYPE")
+         returns NULL and
+           gl_locale_name_posix (LC_CTYPE, "LC_CTYPE")
+         returns either "de_DE" or "de_DE.UTF-8".  */
+      ASSERT (strcmp (name, "de_DE") == 0 || strcmp (name, "de_DE.UTF-8") == 0);
+#else
       ASSERT (strcmp (name, "de_DE.UTF-8") == 0);
+#endif
       name = gl_locale_name (LC_MESSAGES, "LC_MESSAGES");
       ASSERT (strcmp (name, "fr_FR.UTF-8") == 0);
     }
@@ -575,7 +584,11 @@ test_locale_name_posix (void)
   if (setlocale (LC_ALL, "") != NULL)
     {
       name = gl_locale_name_posix (LC_CTYPE, "LC_CTYPE");
+#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+      ASSERT (strcmp (name, "de_DE") == 0 || strcmp (name, "de_DE.UTF-8") == 0);
+#else
       ASSERT (strcmp (name, "de_DE.UTF-8") == 0);
+#endif
       name = gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES");
       ASSERT (strcmp (name, "fr_FR.UTF-8") == 0);
     }