1 # duplocale.m4 serial 12
2 dnl Copyright (C) 2009-2020 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_DUPLOCALE],
9 AC_REQUIRE([gl_LOCALE_H_DEFAULTS])
10 AC_REQUIRE([AC_CANONICAL_HOST])
11 AC_REQUIRE([gl_FUNC_SETLOCALE_NULL])
12 AC_CHECK_FUNCS_ONCE([duplocale])
13 if test $ac_cv_func_duplocale = yes; then
14 dnl Check against glibc bug where duplocale crashes.
15 dnl See <https://sourceware.org/bugzilla/show_bug.cgi?id=10969>.
16 dnl Also, on AIX 7.1, duplocale(LC_GLOBAL_LOCALE) returns (locale_t)0 with
17 dnl errno set to EINVAL.
18 dnl Also, on NetBSD 7.0, duplocale(LC_GLOBAL_LOCALE) returns a locale that
19 dnl corresponds to the C locale.
20 AC_REQUIRE([gl_LOCALE_H])
21 if test $HAVE_LOCALE_T = 1; then
22 AC_CHECK_FUNCS_ONCE([snprintf_l nl_langinfo_l])
23 AC_CACHE_CHECK([whether duplocale(LC_GLOBAL_LOCALE) works],
24 [gl_cv_func_duplocale_works],
34 #if HAVE_NL_LANGINFO_L
35 # include <langinfo.h>
38 struct locale_dependent_values
45 struct locale_dependent_values expected_result;
46 struct locale_dependent_values result;
48 setlocale (LC_ALL, "en_US.UTF-8");
49 setlocale (LC_NUMERIC, "de_DE.UTF-8");
50 setlocale (LC_TIME, "fr_FR.UTF-8");
52 snprintf (expected_result.numeric, sizeof (expected_result.numeric), "%g", 3.5);
54 #if HAVE_NL_LANGINFO_L
55 strcpy (expected_result.time, nl_langinfo (MON_1));
57 loc = duplocale (LC_GLOBAL_LOCALE);
61 snprintf_l (result.numeric, sizeof (result.numeric), loc, "%g", 3.5);
63 #if HAVE_NL_LANGINFO_L
64 strcpy (result.time, nl_langinfo_l (MON_1, loc));
67 if (strcmp (result.numeric, expected_result.numeric) != 0)
70 #if HAVE_NL_LANGINFO_L
71 if (strcmp (result.time, expected_result.time) != 0)
77 [gl_cv_func_duplocale_works=yes],
78 [gl_cv_func_duplocale_works=no],
79 [dnl Guess it works except on glibc < 2.12, uClibc, AIX, and NetBSD.
81 aix* | netbsd*) gl_cv_func_duplocale_works="guessing no";;
83 AC_EGREP_CPP([Unlucky], [
85 #ifdef __GNU_LIBRARY__
86 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ < 12)
94 [gl_cv_func_duplocale_works="guessing no"],
95 [gl_cv_func_duplocale_works="guessing yes"])
97 *) gl_cv_func_duplocale_works="guessing yes";;
101 case "$gl_cv_func_duplocale_works" in
102 *no) REPLACE_DUPLOCALE=1 ;;
105 dnl In 2019, some versions of z/OS lack the locale_t type and have broken
106 dnl newlocale, duplocale, freelocale functions. In this situation, we
107 dnl cannot use nor override duplocale.
113 if test $REPLACE_DUPLOCALE = 1; then
114 LIB_DUPLOCALE="$LIB_SETLOCALE_NULL"
118 dnl LIB_DUPLOCALE is expected to be '-pthread' or '-lpthread' on AIX
119 dnl with gcc or xlc, and empty otherwise.
120 AC_SUBST([LIB_DUPLOCALE])
123 # Prerequisites of lib/duplocale.c.
124 AC_DEFUN([gl_PREREQ_DUPLOCALE],