1 # wcsrtombs.m4 serial 12
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_WCSRTOMBS],
9 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
11 AC_REQUIRE([AC_TYPE_MBSTATE_T])
14 AC_CHECK_FUNCS_ONCE([wcsrtombs])
15 if test $ac_cv_func_wcsrtombs = no; then
17 AC_CHECK_DECLS([wcsrtombs],,, [[
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_wcsrtombs = yes; then
28 dnl On Minix 3.1.8, the system's <wchar.h> declares wcsrtombs() although
29 dnl it does not have the function. Avoid a collision with gnulib's
34 if test $REPLACE_MBSTATE_T = 1; then
37 gl_WCSRTOMBS_TERMINATION
39 case "$gl_cv_func_wcsrtombs_termination" in
41 *) AC_DEFINE([WCSRTOMBS_TERMINATION_BUG], [1],
42 [Define if the wcsrtombs function may set the source pointer to NULL without NUL-terminating the destination.])
43 REPLACE_WCSRTOMBS=1 ;;
45 case "$gl_cv_func_wcsrtombs_null" in
47 *) AC_DEFINE([WCSRTOMBS_NULL_ARG_BUG], [1],
48 [Define if the wcsrtombs function has the NULL destination argument bug.])
49 REPLACE_WCSRTOMBS=1 ;;
55 dnl Test whether the wcsrtombs implementation stores a non-NULL source pointer
56 dnl as long as it has not written the final NUL byte to the destination string.
57 dnl The OSF/1 5.1 implementation stores a NULL pointer already after storing
58 dnl the last non-NUL character, even if there is no more room for the
59 dnl terminating NUL character.
60 dnl Result is gl_cv_func_wcsrtombs_termination.
62 AC_DEFUN([gl_WCSRTOMBS_TERMINATION],
64 AC_REQUIRE([AC_PROG_CC])
65 AC_REQUIRE([gt_LOCALE_FR])
66 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
67 AC_CACHE_CHECK([whether wcsrtombs updates the source pointer correctly],
68 [gl_cv_func_wcsrtombs_termination],
70 dnl Initial guess, used when cross-compiling or when no suitable locale
75 osf*) gl_cv_func_wcsrtombs_termination="guessing no" ;;
76 # Guess yes on native Windows.
77 mingw*) gl_cv_func_wcsrtombs_termination="guessing yes" ;;
78 # Guess yes otherwise.
79 *) gl_cv_func_wcsrtombs_termination="guessing yes" ;;
82 if test $LOCALE_FR != none; then
87 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
89 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
90 included before <wchar.h>. */
97 if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
99 const char original[] = "B\374\337er";
102 if (mbstowcs (input, original, 10) == 5)
104 const wchar_t *src = input;
106 wcsrtombs (output, &src, 5, NULL);
107 if (src != input + 5)
113 [gl_cv_func_wcsrtombs_termination=yes],
114 [gl_cv_func_wcsrtombs_termination=no],
120 dnl Test whether the wcsrtombs implementation supports a NULL argument
121 dnl correctly. This is not the case on HP-UX 11.11 and OSF/1 5.1: These
122 dnl implementations updates the source pointer also if the destination argument
124 dnl Result is gl_cv_func_wcsrtombs_null.
126 AC_DEFUN([gl_WCSRTOMBS_NULL],
128 AC_REQUIRE([AC_PROG_CC])
129 AC_REQUIRE([gt_LOCALE_FR])
130 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
131 AC_CACHE_CHECK([whether wcsrtombs supports a NULL argument correctly],
132 [gl_cv_func_wcsrtombs_null],
134 dnl Initial guess, used when cross-compiling or when no suitable locale
138 # Guess no on HP-UX, OSF/1, mingw.
139 hpux* | osf* | mingw*) gl_cv_func_wcsrtombs_null="guessing no" ;;
140 # Guess yes on native Windows.
141 mingw*) gl_cv_func_wcsrtombs_null="guessing yes" ;;
142 # Guess yes otherwise.
143 *) gl_cv_func_wcsrtombs_null="guessing yes" ;;
146 if test $LOCALE_FR != none; then
151 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
153 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
154 included before <wchar.h>. */
162 if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
164 const char original[] = "B\374\337er";
167 if (mbstowcs (input, original, 10) == 5)
169 const wchar_t *src = input;
170 size_t ret = wcsrtombs (NULL, &src, 3, NULL);
179 [gl_cv_func_wcsrtombs_null=yes],
180 [gl_cv_func_wcsrtombs_null=no],
186 # Prerequisites of lib/wcsrtombs.c.
187 AC_DEFUN([gl_PREREQ_WCSRTOMBS], [