]> Savannah Git Hosting - gnulib.git/commitdiff
duplocale: Work around NetBSD 7.0 bug.
authorBruno Haible <bruno@clisp.org>
Tue, 15 Aug 2017 19:18:44 +0000 (21:18 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 15 Aug 2017 19:18:44 +0000 (21:18 +0200)
* m4/duplocale.m4 (gl_FUNC_DUPLOCALE): Test against the NetBSD 7.0 bug.
* lib/duplocale.c: Add comment about NetBSD problem.
* doc/posix-functions/duplocale.texi: Mention the NetBSD problem.

ChangeLog
doc/posix-functions/duplocale.texi
lib/duplocale.c
m4/duplocale.m4

index 57916941409dd0e321419f0b71944a8f897e688d..a9896aa5042990d97b57b309c6616a46ae8936f4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2017-08-15  Bruno Haible  <bruno@clisp.org>
+
+       duplocale: Work around NetBSD 7.0 bug.
+       * m4/duplocale.m4 (gl_FUNC_DUPLOCALE): Test against the NetBSD 7.0 bug.
+       * lib/duplocale.c: Add comment about NetBSD problem.
+       * doc/posix-functions/duplocale.texi: Mention the NetBSD problem.
+
 2017-08-15  Bruno Haible  <bruno@clisp.org>
 
        duplocale tests: Verify use with *_l functions.
index 08ac855b36ace68065b6e0be893b28522f39fca7..876c768a79985558a4d122cfb9833658a2f3402e 100644 (file)
@@ -11,6 +11,10 @@ Portability problems fixed by Gnulib:
 @item
 The argument @code{LC_GLOBAL_LOCALE} is not supported on some platforms:
 glibc 2.11, AIX 7.1.
+@item
+With the argument @code{LC_GLOBAL_LOCALE}, this function returns a wrong result
+on some platforms:
+NetBSD 7.0.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index ac7ec1418b6fa80bbcb0f5dc5145663cc6ccfd7a..97755334db0bab6a01bb56e537a344a22b384b5b 100644 (file)
@@ -34,7 +34,9 @@ rpl_duplocale (locale_t locale)
   /* Work around crash in the duplocale function in glibc < 2.12.
      See <http://sourceware.org/bugzilla/show_bug.cgi?id=10969>.
      Also, on AIX 7.1, duplocale(LC_GLOBAL_LOCALE) returns (locale_t)0 with
-     errno set to EINVAL.  */
+     errno set to EINVAL.
+     Also, on NetBSD 7.0, duplocale(LC_GLOBAL_LOCALE) returns a locale that
+     corresponds to the C locale.  */
   if (locale == LC_GLOBAL_LOCALE)
     {
       /* Create a copy of the locale by fetching the name of each locale
index b5efd246ba6a2922e06951fd8943bafb04d71a83..416742253fa3d0ad6d01a772e2daef7eb726a368 100644 (file)
@@ -1,4 +1,4 @@
-# duplocale.m4 serial 8
+# duplocale.m4 serial 9
 dnl Copyright (C) 2009-2017 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -14,7 +14,10 @@ AC_DEFUN([gl_FUNC_DUPLOCALE],
     dnl See <http://sourceware.org/bugzilla/show_bug.cgi?id=10969>.
     dnl Also, on AIX 7.1, duplocale(LC_GLOBAL_LOCALE) returns (locale_t)0 with
     dnl errno set to EINVAL.
+    dnl Also, on NetBSD 7.0, duplocale(LC_GLOBAL_LOCALE) returns a locale that
+    dnl corresponds to the C locale.
     AC_REQUIRE([gl_LOCALE_H])
+    AC_CHECK_FUNCS_ONCE([snprintf_l nl_langinfo_l])
     AC_CACHE_CHECK([whether duplocale(LC_GLOBAL_LOCALE) works],
       [gl_cv_func_duplocale_works],
       [AC_RUN_IFELSE(
@@ -23,19 +26,57 @@ AC_DEFUN([gl_FUNC_DUPLOCALE],
 #if HAVE_XLOCALE_H
 # include <xlocale.h>
 #endif
+#if HAVE_SNPRINTF_L
+# include <stdio.h>
+#endif
+#if HAVE_NL_LANGINFO_L
+# include <langinfo.h>
+#endif
+#include <string.h>
+struct locale_dependent_values
+{
+  char numeric[100];
+  char time[100];
+};
 int main ()
 {
-  locale_t loc = duplocale (LC_GLOBAL_LOCALE);
+  struct locale_dependent_values expected_result;
+  struct locale_dependent_values result;
+  locale_t loc;
+  setlocale (LC_ALL, "en_US.UTF-8");
+  setlocale (LC_NUMERIC, "de_DE.UTF-8");
+  setlocale (LC_TIME, "fr_FR.UTF-8");
+#if HAVE_SNPRINTF_L
+  snprintf (expected_result.numeric, sizeof (expected_result.numeric), "%g", 3.5);
+#endif
+#if HAVE_NL_LANGINFO_L
+  strcpy (expected_result.time, nl_langinfo (MON_1));
+#endif
+  loc = duplocale (LC_GLOBAL_LOCALE);
   if (!loc)
     return 1;
+#if HAVE_SNPRINTF_L
+  snprintf_l (result.numeric, sizeof (result.numeric), loc, "%g", 3.5);
+#endif
+#if HAVE_NL_LANGINFO_L
+  strcpy (result.time, nl_langinfo_l (MON_1, loc));
+#endif
+#if HAVE_SNPRINTF_L
+  if (strcmp (result.numeric, expected_result.numeric) != 0)
+    return 2;
+#endif
+#if HAVE_NL_LANGINFO_L
+  if (strcmp (result.time, expected_result.time) != 0)
+    return 3;
+#endif
   freelocale (loc);
   return 0;
 }]])],
          [gl_cv_func_duplocale_works=yes],
          [gl_cv_func_duplocale_works=no],
-         [dnl Guess it works except on glibc < 2.12, uClibc, and AIX.
+         [dnl Guess it works except on glibc < 2.12, uClibc, AIX, and NetBSD.
           case "$host_os" in
-            aix*) gl_cv_func_duplocale_works="guessing no";;
+            aix* | netbsd*) gl_cv_func_duplocale_works="guessing no";;
             *-gnu*)
               AC_EGREP_CPP([Unlucky], [
 #include <features.h>