>From a1971db1d4fe4430a48475a751602f861812503e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 15 Aug 2017 21:18:44 +0200 Subject: [PATCH 2/2] 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. --- ChangeLog | 7 ++++++ doc/posix-functions/duplocale.texi | 4 ++++ lib/duplocale.c | 4 +++- m4/duplocale.m4 | 49 ++++++++++++++++++++++++++++++++++---- 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5791694..a9896aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2017-08-15 Bruno Haible + 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 + duplocale tests: Verify use with *_l functions. * modules/duplocale-tests (configure.ac): Test for uselocale and some *_l functions. diff --git a/doc/posix-functions/duplocale.texi b/doc/posix-functions/duplocale.texi index 08ac855..876c768 100644 --- a/doc/posix-functions/duplocale.texi +++ b/doc/posix-functions/duplocale.texi @@ -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. address@hidden +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: diff --git a/lib/duplocale.c b/lib/duplocale.c index ac7ec14..9775533 100644 --- a/lib/duplocale.c +++ b/lib/duplocale.c @@ -34,7 +34,9 @@ rpl_duplocale (locale_t locale) /* Work around crash in the duplocale function in glibc < 2.12. See . 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 diff --git a/m4/duplocale.m4 b/m4/duplocale.m4 index b5efd24..4167422 100644 --- a/m4/duplocale.m4 +++ b/m4/duplocale.m4 @@ -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 . 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 #endif +#if HAVE_SNPRINTF_L +# include +#endif +#if HAVE_NL_LANGINFO_L +# include +#endif +#include +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 -- 2.7.4