immutable: Add tests.
[gnulib.git] / m4 / strfmon_l.m4
blob32a78f0b1f1ecf7a06552a71e06b48849a757dfe
1 # strfmon_l.m4 serial 2
2 dnl Copyright (C) 2017-2021 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_STRFMON_L],
9   AC_REQUIRE([gl_MONETARY_H_DEFAULTS])
10   AC_REQUIRE([gt_LOCALE_FR_UTF8])
12   dnl Persuade glibc <monetary.h> to declare strfmon_l().
13   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14   dnl On Mac OS X 10.12, <monetary.h> may declare strfmon_l() if
15   dnl _USE_EXTENDED_LOCALES_ is defined. But this symbol is supposed
16   dnl to be defined by <xlocale.h>, not by us.
18   AC_CHECK_FUNCS_ONCE([strfmon_l])
19   if test $ac_cv_func_strfmon_l = yes; then
20     dnl Test for bug <https://sourceware.org/bugzilla/show_bug.cgi?id=19633>
21     dnl which was fixed in glibc-2.24.
22     AC_CACHE_CHECK([whether strfmon_l works],
23       [gl_cv_strfmon_l_works],
24       [
25        dnl Initial guess, used when cross-compiling or when no suitable locale
26        dnl is present.
27        case "$host_os" in
28          # Guess no on glibc versions < 2.24.
29          *-gnu* | gnu*)
30            AC_EGREP_CPP([Unlucky],
31              [
32 #include <features.h>
33 #ifdef __GNU_LIBRARY__
34  #if (__GLIBC__ == 2 && __GLIBC_MINOR__ < 24)
35   Unlucky GNU user
36  #endif
37 #endif
38              ],
39              [gl_cv_strfmon_l_works="guessing no"],
40              [gl_cv_strfmon_l_works="guessing yes"])
41            ;;
42          # Guess no on FreeBSD and Cygwin.
43          freebsd* | cygwin*) gl_cv_strfmon_l_works="guessing no" ;;
44          # Guess yes otherwise.
45          *) gl_cv_strfmon_l_works="guessing yes" ;;
46        esac
47        if test $LOCALE_FR_UTF8 != none; then
48          AC_CHECK_HEADERS_ONCE([xlocale.h])
49          AC_RUN_IFELSE(
50            [AC_LANG_SOURCE([[
51 #include <monetary.h>
52 #include <locale.h>
53 #if HAVE_XLOCALE_H
54 # include <xlocale.h>
55 #endif
56 #include <string.h>
57 int main ()
59   /* On older glibc systems:      expected_buf="$123.50" buf="$123,50"
60      On FreeBSD 12.0, Cygwin 2.9: expected_buf="$123.50" buf="123,50 $"
61    */
62   if (setlocale (LC_ALL, "en_US.UTF-8") != NULL)
63     {
64       char expected_buf[80];
65       if (strfmon (expected_buf, sizeof (expected_buf), "%.2n", 123.5) >= 0)
66         if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
67           {
68             locale_t loc = newlocale (LC_ALL_MASK, "en_US.UTF-8", NULL);
69             if (loc != (locale_t) 0)
70               {
71                 char buf[80];
72                 if (strfmon_l (buf, sizeof (buf), loc, "%.2n", 123.5) >= 0)
73                   return strcmp (buf, expected_buf) != 0;
74               }
75           }
76     }
77   return 0;
78 }]])],
79            [gl_cv_strfmon_l_works=yes],
80            [gl_cv_strfmon_l_works=no],
81            [:])
82        fi
83       ])
84     if test "$gl_cv_strfmon_l_works" = no; then
85       REPLACE_STRFMON_L=1
86     fi
87   else
88     HAVE_STRFMON_L=0
89   fi
92 # Prerequisites of lib/strfmon_l.c.
93 AC_DEFUN([gl_PREREQ_STRFMON_L], [
94   :