stdopen: Fix compilation error with IRIX cc.
[gnulib.git] / m4 / duplocale.m4
blobc2c95dd652607e92ecce9ba2e7b1a1eff10a9300
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],
23       [AC_RUN_IFELSE(
24          [AC_LANG_SOURCE([[
25 #include <locale.h>
26 #if HAVE_XLOCALE_H
27 # include <xlocale.h>
28 #endif
29 #if HAVE_SNPRINTF_L
30 # include <stdio.h>
31 #endif
32 #if HAVE_NL_LANGINFO_L
33 # include <langinfo.h>
34 #endif
35 #include <string.h>
36 struct locale_dependent_values
38   char numeric[100];
39   char time[100];
41 int main ()
43   struct locale_dependent_values expected_result;
44   struct locale_dependent_values result;
45   locale_t loc;
46   setlocale (LC_ALL, "en_US.UTF-8");
47   setlocale (LC_NUMERIC, "de_DE.UTF-8");
48   setlocale (LC_TIME, "fr_FR.UTF-8");
49 #if HAVE_SNPRINTF_L
50   snprintf (expected_result.numeric, sizeof (expected_result.numeric), "%g", 3.5);
51 #endif
52 #if HAVE_NL_LANGINFO_L
53   strcpy (expected_result.time, nl_langinfo (MON_1));
54 #endif
55   loc = duplocale (LC_GLOBAL_LOCALE);
56   if (!loc)
57     return 1;
58 #if HAVE_SNPRINTF_L
59   snprintf_l (result.numeric, sizeof (result.numeric), loc, "%g", 3.5);
60 #endif
61 #if HAVE_NL_LANGINFO_L
62   strcpy (result.time, nl_langinfo_l (MON_1, loc));
63 #endif
64 #if HAVE_SNPRINTF_L
65   if (strcmp (result.numeric, expected_result.numeric) != 0)
66     return 2;
67 #endif
68 #if HAVE_NL_LANGINFO_L
69   if (strcmp (result.time, expected_result.time) != 0)
70     return 3;
71 #endif
72   freelocale (loc);
73   return 0;
74 }]])],
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.
78           case "$host_os" in
79             aix* | netbsd*) gl_cv_func_duplocale_works="guessing no";;
80             *-gnu* | gnu*)
81               AC_EGREP_CPP([Unlucky], [
82 #include <features.h>
83 #ifdef __GNU_LIBRARY__
84  #if (__GLIBC__ == 2 && __GLIBC_MINOR__ < 12)
85   Unlucky GNU user
86  #endif
87 #endif
88 #ifdef __UCLIBC__
89  Unlucky user
90 #endif
91                 ],
92                 [gl_cv_func_duplocale_works="guessing no"],
93                 [gl_cv_func_duplocale_works="guessing yes"])
94               ;;
95             *) gl_cv_func_duplocale_works="guessing yes";;
96           esac
97          ])
98       ])
99     case "$gl_cv_func_duplocale_works" in
100       *no) REPLACE_DUPLOCALE=1 ;;
101     esac
102   else
103     HAVE_DUPLOCALE=0
104   fi
107 # Prerequisites of lib/duplocale.c.
108 AC_DEFUN([gl_PREREQ_DUPLOCALE],
110   :