1 # wcsrtombs.m4 serial 4
2 dnl Copyright (C) 2008-2010 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])
13 if test $REPLACE_MBSTATE_T = 1; then
16 AC_CHECK_FUNCS_ONCE([wcsrtombs])
17 if test $ac_cv_func_wcsrtombs = no; then
20 if test $HAVE_WCSRTOMBS != 0 && test $REPLACE_WCSRTOMBS != 1; then
21 gl_WCSRTOMBS_TERMINATION
23 case "$gl_cv_func_wcsrtombs_termination" in
25 *) AC_DEFINE([WCSRTOMBS_TERMINATION_BUG], [1],
26 [Define if the wcsrtombs function may set the source pointer to NULL without NUL-terminating the destination.])
27 REPLACE_WCSRTOMBS=1 ;;
29 case "$gl_cv_func_wcsrtombs_null" in
31 *) AC_DEFINE([WCSRTOMBS_NULL_ARG_BUG], [1],
32 [Define if the wcsrtombs function has the NULL destination argument bug.])
33 REPLACE_WCSRTOMBS=1 ;;
36 if test $HAVE_WCSRTOMBS = 0 || test $REPLACE_WCSRTOMBS = 1; then
38 AC_LIBOBJ([wcsrtombs])
39 AC_LIBOBJ([wcsrtombs-state])
44 dnl Test whether the wcsrtombs implementation stores a non-NULL source pointer
45 dnl as long as it has not written the final NUL byte to the destination string.
46 dnl The OSF/1 5.1 implementation stores a NULL pointer already after storing
47 dnl the last non-NUL character, even if there is no more room for the
48 dnl terminating NUL character.
49 dnl Result is gl_cv_func_wcsrtombs_termination.
51 AC_DEFUN([gl_WCSRTOMBS_TERMINATION],
53 AC_REQUIRE([AC_PROG_CC])
54 AC_REQUIRE([gt_LOCALE_FR])
55 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
56 AC_CACHE_CHECK([whether wcsrtombs updates the source pointer correctly],
57 [gl_cv_func_wcsrtombs_termination],
59 dnl Initial guess, used when cross-compiling or when no suitable locale
64 osf*) gl_cv_func_wcsrtombs_termination="guessing no" ;;
65 # Guess yes otherwise.
66 *) gl_cv_func_wcsrtombs_termination="guessing yes" ;;
69 if test $LOCALE_FR != none; then
76 if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
78 const char original[] = "B\374\337er";
81 if (mbstowcs (input, original, 10) == 5)
83 const wchar_t *src = input;
85 wcsrtombs (output, &src, 5, NULL);
92 [gl_cv_func_wcsrtombs_termination=yes],
93 [gl_cv_func_wcsrtombs_termination=no],
99 dnl Test whether the wcsrtombs implementation supports a NULL argument
100 dnl correctly. This is not the case on HP-UX 11.11 and OSF/1 5.1: These
101 dnl implementations updates the source pointer also if the destination argument
103 dnl Result is gl_cv_func_wcsrtombs_null.
105 AC_DEFUN([gl_WCSRTOMBS_NULL],
107 AC_REQUIRE([AC_PROG_CC])
108 AC_REQUIRE([gt_LOCALE_FR])
109 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
110 AC_CACHE_CHECK([whether wcsrtombs supports a NULL argument correctly],
111 [gl_cv_func_wcsrtombs_null],
113 dnl Initial guess, used when cross-compiling or when no suitable locale
117 # Guess no on HP-UX and OSF/1.
118 hpux* | osf*) gl_cv_func_wcsrtombs_null="guessing no" ;;
119 # Guess yes otherwise.
120 *) gl_cv_func_wcsrtombs_null="guessing yes" ;;
123 if test $LOCALE_FR != none; then
130 if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
132 const char original[] = "B\374\337er";
135 if (mbstowcs (input, original, 10) == 5)
137 const wchar_t *src = input;
138 wcsrtombs (NULL, &src, 10, NULL);
145 [gl_cv_func_wcsrtombs_null=yes],
146 [gl_cv_func_wcsrtombs_null=no],
152 # Prerequisites of lib/wcsrtombs.c.
153 AC_DEFUN([gl_PREREQ_WCSRTOMBS], [