duplocale.m4 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. # duplocale.m4 serial 14
  2. dnl Copyright (C) 2009-2023 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.
  6. AC_DEFUN([gl_FUNC_DUPLOCALE],
  7. [
  8. AC_REQUIRE([gl_LOCALE_H_DEFAULTS])
  9. AC_REQUIRE([AC_CANONICAL_HOST])
  10. AC_REQUIRE([gl_FUNC_SETLOCALE_NULL])
  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. if test $HAVE_LOCALE_T = 1; then
  21. AC_CHECK_FUNCS_ONCE([snprintf_l nl_langinfo_l])
  22. AC_CACHE_CHECK([whether duplocale(LC_GLOBAL_LOCALE) works],
  23. [gl_cv_func_duplocale_works],
  24. [AC_RUN_IFELSE(
  25. [AC_LANG_SOURCE([[
  26. #include <locale.h>
  27. #if HAVE_XLOCALE_H
  28. # include <xlocale.h>
  29. #endif
  30. #if HAVE_SNPRINTF_L
  31. # include <stdio.h>
  32. #endif
  33. #if HAVE_NL_LANGINFO_L
  34. # include <langinfo.h>
  35. #endif
  36. #include <string.h>
  37. struct locale_dependent_values
  38. {
  39. char numeric[100];
  40. char time[100];
  41. };
  42. int main ()
  43. {
  44. struct locale_dependent_values expected_result;
  45. struct locale_dependent_values result;
  46. locale_t loc;
  47. setlocale (LC_ALL, "en_US.UTF-8");
  48. setlocale (LC_NUMERIC, "de_DE.UTF-8");
  49. setlocale (LC_TIME, "fr_FR.UTF-8");
  50. #if HAVE_SNPRINTF_L
  51. snprintf (expected_result.numeric, sizeof (expected_result.numeric), "%g", 3.5);
  52. #endif
  53. #if HAVE_NL_LANGINFO_L
  54. strcpy (expected_result.time, nl_langinfo (MON_1));
  55. #endif
  56. loc = duplocale (LC_GLOBAL_LOCALE);
  57. if (!loc)
  58. return 1;
  59. #if HAVE_SNPRINTF_L
  60. snprintf_l (result.numeric, sizeof (result.numeric), loc, "%g", 3.5);
  61. #endif
  62. #if HAVE_NL_LANGINFO_L
  63. strcpy (result.time, nl_langinfo_l (MON_1, loc));
  64. #endif
  65. #if HAVE_SNPRINTF_L
  66. if (strcmp (result.numeric, expected_result.numeric) != 0)
  67. return 2;
  68. #endif
  69. #if HAVE_NL_LANGINFO_L
  70. if (strcmp (result.time, expected_result.time) != 0)
  71. return 3;
  72. #endif
  73. freelocale (loc);
  74. return 0;
  75. }]])],
  76. [gl_cv_func_duplocale_works=yes],
  77. [gl_cv_func_duplocale_works=no],
  78. [dnl Guess it works except on glibc < 2.12, uClibc, AIX, and NetBSD.
  79. case "$host_os" in
  80. aix* | netbsd*) gl_cv_func_duplocale_works="guessing no";;
  81. *-gnu* | gnu*)
  82. AC_EGREP_CPP([Unlucky], [
  83. #include <features.h>
  84. #ifdef __GNU_LIBRARY__
  85. #if (__GLIBC__ == 2 && __GLIBC_MINOR__ < 12)
  86. Unlucky GNU user
  87. #endif
  88. #endif
  89. #ifdef __UCLIBC__
  90. Unlucky user
  91. #endif
  92. ],
  93. [gl_cv_func_duplocale_works="guessing no"],
  94. [gl_cv_func_duplocale_works="guessing yes"])
  95. ;;
  96. *) gl_cv_func_duplocale_works="guessing yes";;
  97. esac
  98. ])
  99. ])
  100. case "$gl_cv_func_duplocale_works" in
  101. *no) REPLACE_DUPLOCALE=1 ;;
  102. esac
  103. else
  104. dnl In 2019, some versions of z/OS lack the locale_t type and have broken
  105. dnl newlocale, duplocale, freelocale functions. In this situation, we
  106. dnl cannot use nor override duplocale.
  107. HAVE_DUPLOCALE=0
  108. fi
  109. else
  110. HAVE_DUPLOCALE=0
  111. fi
  112. if test $REPLACE_DUPLOCALE = 1; then
  113. DUPLOCALE_LIB="$SETLOCALE_NULL_LIB"
  114. else
  115. DUPLOCALE_LIB=
  116. fi
  117. dnl DUPLOCALE_LIB is expected to be '-pthread' or '-lpthread' on AIX
  118. dnl with gcc or xlc, and empty otherwise.
  119. AC_SUBST([DUPLOCALE_LIB])
  120. dnl For backward compatibility.
  121. LIB_DUPLOCALE="$DUPLOCALE_LIB"
  122. AC_SUBST([LIB_DUPLOCALE])
  123. ])
  124. # Prerequisites of lib/duplocale.c.
  125. AC_DEFUN([gl_PREREQ_DUPLOCALE],
  126. [
  127. :
  128. ])