1 # wcsnrtombs.m4 serial 6
2 dnl Copyright (C) 2008-2020 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_WCSNRTOMBS],
9 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
11 AC_REQUIRE([AC_TYPE_MBSTATE_T])
14 AC_CHECK_FUNCS_ONCE([wcsnrtombs])
15 if test $ac_cv_func_wcsnrtombs = no; then
18 if test $REPLACE_MBSTATE_T = 1; then
21 gl_WCSNRTOMBS_WORKS_IN_TRADITIONAL_LOCALE
22 case "$gl_cv_func_wcsnrtombs_works_in_traditional_locale" in
24 *) REPLACE_WCSNRTOMBS=1 ;;
31 # Prerequisites of lib/wcsnrtombs.c.
32 AC_DEFUN([gl_PREREQ_WCSNRTOMBS], [
36 dnl Test whether wcsnrtombs works in an ISO-8859-1 locale.
37 dnl Result is gl_cv_func_wcsnrtombs_works_in_traditional_locale.
39 AC_DEFUN([gl_WCSNRTOMBS_WORKS_IN_TRADITIONAL_LOCALE],
41 AC_REQUIRE([AC_PROG_CC])
42 AC_REQUIRE([gt_LOCALE_FR])
43 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
44 AC_CACHE_CHECK([whether wcsnrtombs works in a traditional locale],
45 [gl_cv_func_wcsnrtombs_works_in_traditional_locale],
47 dnl Initial guess, used when cross-compiling or when no suitable locale
51 # Guess no on Solaris.
52 solaris*) gl_cv_func_wcsnrtombs_works_in_traditional_locale="guessing no" ;;
53 # Guess yes otherwise.
54 *) gl_cv_func_wcsnrtombs_works_in_traditional_locale="guessing yes" ;;
57 if test $LOCALE_FR != none; then
63 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
65 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
66 included before <wchar.h>. */
73 /* This fails on Solaris 11.4. */
74 if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
76 /* Locale encoding is ISO-8859-1 or ISO-8859-15. */
77 const char original[] = "B\374\337er"; /* "Büßer" */
84 memset (buf, '_', BUFSIZE);
86 ret = mbstowcs (input, original, 10);
91 ret = wcsnrtombs (buf, &src, 6, 2, NULL);
94 if (!(src == input + 2))
96 if (!(memcmp (buf, original, ret) == 0))
101 [gl_cv_func_wcsnrtombs_works_in_traditional_locale=yes],
102 [gl_cv_func_wcsnrtombs_works_in_traditional_locale=no],