| 1 | # wcrtomb.m4 serial 17
|
|---|
| 2 | dnl Copyright (C) 2008-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.
|
|---|
| 6 |
|
|---|
| 7 | AC_DEFUN([gl_FUNC_WCRTOMB],
|
|---|
| 8 | [
|
|---|
| 9 | AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
|
|---|
| 10 |
|
|---|
| 11 | AC_REQUIRE([AC_TYPE_MBSTATE_T])
|
|---|
| 12 | gl_MBSTATE_T_BROKEN
|
|---|
| 13 |
|
|---|
| 14 | AC_CHECK_FUNCS_ONCE([wcrtomb])
|
|---|
| 15 | if test $ac_cv_func_wcrtomb = no; then
|
|---|
| 16 | HAVE_WCRTOMB=0
|
|---|
| 17 | AC_CHECK_DECLS([wcrtomb],,, [[
|
|---|
| 18 | #include <wchar.h>
|
|---|
| 19 | ]])
|
|---|
| 20 | if test $ac_cv_have_decl_wcrtomb = yes; then
|
|---|
| 21 | dnl On Minix 3.1.8, the system's <wchar.h> declares wcrtomb() although
|
|---|
| 22 | dnl it does not have the function. Avoid a collision with gnulib's
|
|---|
| 23 | dnl replacement.
|
|---|
| 24 | REPLACE_WCRTOMB=1
|
|---|
| 25 | fi
|
|---|
| 26 | else
|
|---|
| 27 | dnl We don't actually need to override wcrtomb when redefining the semantics
|
|---|
| 28 | dnl of the mbstate_t type. Tested on 32-bit AIX.
|
|---|
| 29 | dnl if test $REPLACE_MBSTATE_T = 1; then
|
|---|
| 30 | dnl REPLACE_WCRTOMB=1
|
|---|
| 31 | dnl fi
|
|---|
| 32 | if test $REPLACE_WCRTOMB = 0; then
|
|---|
| 33 | dnl On Android 4.3, wcrtomb produces wrong characters in the C locale.
|
|---|
| 34 | dnl On AIX 4.3, OSF/1 5.1 and Solaris <= 11.3, wcrtomb (NULL, 0, NULL)
|
|---|
| 35 | dnl sometimes returns 0 instead of 1.
|
|---|
| 36 | AC_REQUIRE([AC_PROG_CC])
|
|---|
| 37 | AC_REQUIRE([gt_LOCALE_FR])
|
|---|
| 38 | AC_REQUIRE([gt_LOCALE_FR_UTF8])
|
|---|
| 39 | AC_REQUIRE([gt_LOCALE_JA])
|
|---|
| 40 | AC_REQUIRE([gt_LOCALE_ZH_CN])
|
|---|
| 41 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
|
|---|
| 42 | AC_CACHE_CHECK([whether wcrtomb works in the C locale],
|
|---|
| 43 | [gl_cv_func_wcrtomb_works],
|
|---|
| 44 | [AC_RUN_IFELSE(
|
|---|
| 45 | [AC_LANG_SOURCE([[
|
|---|
| 46 | #include <string.h>
|
|---|
| 47 | #include <stdlib.h>
|
|---|
| 48 | #include <wchar.h>
|
|---|
| 49 | int main ()
|
|---|
| 50 | {
|
|---|
| 51 | mbstate_t state;
|
|---|
| 52 | char out[64];
|
|---|
| 53 | int count;
|
|---|
| 54 | memset (&state, 0, sizeof (state));
|
|---|
| 55 | out[0] = 'x';
|
|---|
| 56 | count = wcrtomb (out, L'a', &state);
|
|---|
| 57 | return !(count == 1 && out[0] == 'a');
|
|---|
| 58 | }]])],
|
|---|
| 59 | [gl_cv_func_wcrtomb_works=yes],
|
|---|
| 60 | [gl_cv_func_wcrtomb_works=no],
|
|---|
| 61 | [case "$host_os" in
|
|---|
| 62 | # Guess no on Android.
|
|---|
| 63 | linux*-android*) gl_cv_func_wcrtomb_works="guessing no";;
|
|---|
| 64 | # Guess yes otherwise.
|
|---|
| 65 | *) gl_cv_func_wcrtomb_works="guessing yes";;
|
|---|
| 66 | esac
|
|---|
| 67 | ])
|
|---|
| 68 | ])
|
|---|
| 69 | case "$gl_cv_func_wcrtomb_works" in
|
|---|
| 70 | *yes) ;;
|
|---|
| 71 | *) AC_DEFINE([WCRTOMB_C_LOCALE_BUG], [1],
|
|---|
| 72 | [Define if the wcrtomb function does not work in the C locale.])
|
|---|
| 73 | REPLACE_WCRTOMB=1 ;;
|
|---|
| 74 | esac
|
|---|
| 75 | fi
|
|---|
| 76 | if test $REPLACE_WCRTOMB = 0; then
|
|---|
| 77 | AC_CACHE_CHECK([whether wcrtomb return value is correct],
|
|---|
| 78 | [gl_cv_func_wcrtomb_retval],
|
|---|
| 79 | [
|
|---|
| 80 | dnl Initial guess, used when cross-compiling or when no suitable locale
|
|---|
| 81 | dnl is present.
|
|---|
| 82 | changequote(,)dnl
|
|---|
| 83 | case "$host_os" in
|
|---|
| 84 | # Guess no on AIX 4, OSF/1, Solaris, native Windows.
|
|---|
| 85 | aix4* | osf* | solaris* | mingw*) gl_cv_func_wcrtomb_retval="guessing no" ;;
|
|---|
| 86 | # Guess yes otherwise.
|
|---|
| 87 | *) gl_cv_func_wcrtomb_retval="guessing yes" ;;
|
|---|
| 88 | esac
|
|---|
| 89 | changequote([,])dnl
|
|---|
| 90 | if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
|
|---|
| 91 | AC_RUN_IFELSE(
|
|---|
| 92 | [AC_LANG_SOURCE([[
|
|---|
| 93 | #include <locale.h>
|
|---|
| 94 | #include <string.h>
|
|---|
| 95 | #include <wchar.h>
|
|---|
| 96 | #include <stdlib.h>
|
|---|
| 97 | int main ()
|
|---|
| 98 | {
|
|---|
| 99 | int result = 0;
|
|---|
| 100 | if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
|
|---|
| 101 | {
|
|---|
| 102 | if (wcrtomb (NULL, 0, NULL) != 1)
|
|---|
| 103 | result |= 1;
|
|---|
| 104 | }
|
|---|
| 105 | if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
|
|---|
| 106 | {
|
|---|
| 107 | if (wcrtomb (NULL, 0, NULL) != 1)
|
|---|
| 108 | result |= 2;
|
|---|
| 109 | {
|
|---|
| 110 | wchar_t wc = (wchar_t) 0xBADFACE;
|
|---|
| 111 | if (mbtowc (&wc, "\303\274", 2) == 2)
|
|---|
| 112 | if (wcrtomb (NULL, wc, NULL) != 1)
|
|---|
| 113 | result |= 2;
|
|---|
| 114 | }
|
|---|
| 115 | }
|
|---|
| 116 | if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
|
|---|
| 117 | {
|
|---|
| 118 | if (wcrtomb (NULL, 0, NULL) != 1)
|
|---|
| 119 | result |= 4;
|
|---|
| 120 | }
|
|---|
| 121 | if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
|
|---|
| 122 | {
|
|---|
| 123 | if (wcrtomb (NULL, 0, NULL) != 1)
|
|---|
| 124 | result |= 8;
|
|---|
| 125 | }
|
|---|
| 126 | return result;
|
|---|
| 127 | }]])],
|
|---|
| 128 | [gl_cv_func_wcrtomb_retval=yes],
|
|---|
| 129 | [gl_cv_func_wcrtomb_retval=no],
|
|---|
| 130 | [:])
|
|---|
| 131 | fi
|
|---|
| 132 | ])
|
|---|
| 133 | case "$gl_cv_func_wcrtomb_retval" in
|
|---|
| 134 | *yes) ;;
|
|---|
| 135 | *) AC_DEFINE([WCRTOMB_RETVAL_BUG], [1],
|
|---|
| 136 | [Define if the wcrtomb function has an incorrect return value.])
|
|---|
| 137 | REPLACE_WCRTOMB=1 ;;
|
|---|
| 138 | esac
|
|---|
| 139 | fi
|
|---|
| 140 | fi
|
|---|
| 141 | ])
|
|---|
| 142 |
|
|---|
| 143 | # Prerequisites of lib/wcrtomb.c.
|
|---|
| 144 | AC_DEFUN([gl_PREREQ_WCRTOMB], [
|
|---|
| 145 | :
|
|---|
| 146 | ])
|
|---|