1 # duplocale.m4 serial 10
2 dnl Copyright (C) 2009-2019 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_CHECK_FUNCS_ONCE([duplocale])
12 if test $ac_cv_func_duplocale = yes; then
13 dnl Check against glibc bug where duplocale crashes.
14 dnl See <https://sourceware.org/bugzilla/show_bug.cgi?id=10969>.
15 dnl Also, on AIX 7.1, duplocale(LC_GLOBAL_LOCALE) returns (locale_t)0 with
16 dnl errno set to EINVAL.
17 dnl Also, on NetBSD 7.0, duplocale(LC_GLOBAL_LOCALE) returns a locale that
18 dnl corresponds to the C locale.
19 AC_REQUIRE([gl_LOCALE_H])
20 AC_CHECK_FUNCS_ONCE([snprintf_l nl_langinfo_l])
21 AC_CACHE_CHECK([whether duplocale(LC_GLOBAL_LOCALE) works],
22 [gl_cv_func_duplocale_works],
32 #if HAVE_NL_LANGINFO_L
33 # include <langinfo.h>
36 struct locale_dependent_values
43 struct locale_dependent_values expected_result;
44 struct locale_dependent_values result;
46 setlocale (LC_ALL, "en_US.UTF-8");
47 setlocale (LC_NUMERIC, "de_DE.UTF-8");
48 setlocale (LC_TIME, "fr_FR.UTF-8");
50 snprintf (expected_result.numeric, sizeof (expected_result.numeric), "%g", 3.5);
52 #if HAVE_NL_LANGINFO_L
53 strcpy (expected_result.time, nl_langinfo (MON_1));
55 loc = duplocale (LC_GLOBAL_LOCALE);
59 snprintf_l (result.numeric, sizeof (result.numeric), loc, "%g", 3.5);
61 #if HAVE_NL_LANGINFO_L
62 strcpy (result.time, nl_langinfo_l (MON_1, loc));
65 if (strcmp (result.numeric, expected_result.numeric) != 0)
68 #if HAVE_NL_LANGINFO_L
69 if (strcmp (result.time, expected_result.time) != 0)
75 [gl_cv_func_duplocale_works=yes],
76 [gl_cv_func_duplocale_works=no],
77 [dnl Guess it works except on glibc < 2.12, uClibc, AIX, and NetBSD.
79 aix* | netbsd*) gl_cv_func_duplocale_works="guessing no";;
81 AC_EGREP_CPP([Unlucky], [
83 #ifdef __GNU_LIBRARY__
84 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ < 12)
92 [gl_cv_func_duplocale_works="guessing no"],
93 [gl_cv_func_duplocale_works="guessing yes"])
95 *) gl_cv_func_duplocale_works="guessing yes";;
99 case "$gl_cv_func_duplocale_works" in
100 *no) REPLACE_DUPLOCALE=1 ;;
107 # Prerequisites of lib/duplocale.c.
108 AC_DEFUN([gl_PREREQ_DUPLOCALE],