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