2 dnl Copyright (C) 2008-2018 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_WCRTOMB],
9 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
11 AC_REQUIRE([AC_TYPE_MBSTATE_T])
14 AC_CHECK_FUNCS_ONCE([wcrtomb])
15 if test $ac_cv_func_wcrtomb = no; then
17 AC_CHECK_DECLS([wcrtomb],,, [[
18 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
20 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
21 included before <wchar.h>. */
27 if test $ac_cv_have_decl_wcrtomb = yes; then
28 dnl On Minix 3.1.8, the system's <wchar.h> declares wcrtomb() although
29 dnl it does not have the function. Avoid a collision with gnulib's
34 if test $REPLACE_MBSTATE_T = 1; then
37 dnl On AIX 4.3, OSF/1 5.1 and Solaris <= 11.3, wcrtomb (NULL, 0, NULL)
38 dnl sometimes returns 0 instead of 1.
39 AC_REQUIRE([AC_PROG_CC])
40 AC_REQUIRE([gt_LOCALE_FR])
41 AC_REQUIRE([gt_LOCALE_FR_UTF8])
42 AC_REQUIRE([gt_LOCALE_JA])
43 AC_REQUIRE([gt_LOCALE_ZH_CN])
44 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
45 AC_CACHE_CHECK([whether wcrtomb return value is correct],
46 [gl_cv_func_wcrtomb_retval],
48 dnl Initial guess, used when cross-compiling or when no suitable locale
52 # Guess no on AIX 4, OSF/1 and Solaris.
53 aix4* | osf* | solaris*) gl_cv_func_wcrtomb_retval="guessing no" ;;
54 # Guess yes on native Windows.
55 mingw*) gl_cv_func_wcrtomb_retval="guessing yes" ;;
56 # Guess yes otherwise.
57 *) gl_cv_func_wcrtomb_retval="guessing yes" ;;
60 if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
65 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
67 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
68 included before <wchar.h>. */
76 if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
78 if (wcrtomb (NULL, 0, NULL) != 1)
81 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
83 if (wcrtomb (NULL, 0, NULL) != 1)
86 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
88 if (wcrtomb (NULL, 0, NULL) != 1)
91 if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
93 if (wcrtomb (NULL, 0, NULL) != 1)
98 [gl_cv_func_wcrtomb_retval=yes],
99 [gl_cv_func_wcrtomb_retval=no],
103 case "$gl_cv_func_wcrtomb_retval" in
105 *) REPLACE_WCRTOMB=1 ;;
111 # Prerequisites of lib/wcrtomb.c.
112 AC_DEFUN([gl_PREREQ_WCRTOMB], [