1 # wcsrtombs.m4 serial 3
2 dnl Copyright (C) 2008-2009 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])
12 AC_CHECK_FUNCS_ONCE([wcsrtombs])
13 if test $ac_cv_func_wcsrtombs = no; then
16 gl_WCSRTOMBS_TERMINATION
18 case "$gl_cv_func_wcsrtombs_termination" in
20 *) AC_DEFINE([WCSRTOMBS_TERMINATION_BUG], [1],
21 [Define if the wcsrtombs function may set the source pointer to NULL without NUL-terminating the destination.])
22 REPLACE_WCSRTOMBS=1 ;;
24 case "$gl_cv_func_wcsrtombs_null" in
26 *) AC_DEFINE([WCSRTOMBS_NULL_ARG_BUG], [1],
27 [Define if the wcsrtombs function has the NULL destination argument bug.])
28 REPLACE_WCSRTOMBS=1 ;;
31 if test $HAVE_WCSRTOMBS = 0 || test $REPLACE_WCSRTOMBS = 1; then
33 AC_LIBOBJ([wcsrtombs])
34 AC_LIBOBJ([wcsrtombs-state])
39 dnl Test whether the wcsrtombs implementation stores a non-NULL source pointer
40 dnl as long as it has not written the final NUL byte to the destination string.
41 dnl The OSF/1 5.1 implementation stores a NULL pointer already after storing
42 dnl the last non-NUL character, even if there is no more room for the
43 dnl terminating NUL character.
44 dnl Result is gl_cv_func_wcsrtombs_termination.
46 AC_DEFUN([gl_WCSRTOMBS_TERMINATION],
48 AC_REQUIRE([AC_PROG_CC])
49 AC_REQUIRE([gt_LOCALE_FR])
50 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
51 AC_CACHE_CHECK([whether wcsrtombs updates the source pointer correctly],
52 [gl_cv_func_wcsrtombs_termination],
54 dnl Initial guess, used when cross-compiling or when no suitable locale
59 osf*) gl_cv_func_wcsrtombs_termination="guessing no" ;;
60 # Guess yes otherwise.
61 *) gl_cv_func_wcsrtombs_termination="guessing yes" ;;
64 if test $LOCALE_FR != none; then
71 if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
73 const char original[] = "B\374\337er";
76 if (mbstowcs (input, original, 10) == 5)
78 const wchar_t *src = input;
80 wcsrtombs (output, &src, 5, NULL);
87 [gl_cv_func_wcsrtombs_termination=yes],
88 [gl_cv_func_wcsrtombs_termination=no],
94 dnl Test whether the wcsrtombs implementation supports a NULL argument
95 dnl correctly. This is not the case on HP-UX 11.11 and OSF/1 5.1: These
96 dnl implementations updates the source pointer also if the destination argument
98 dnl Result is gl_cv_func_wcsrtombs_null.
100 AC_DEFUN([gl_WCSRTOMBS_NULL],
102 AC_REQUIRE([AC_PROG_CC])
103 AC_REQUIRE([gt_LOCALE_FR])
104 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
105 AC_CACHE_CHECK([whether wcsrtombs supports a NULL argument correctly],
106 [gl_cv_func_wcsrtombs_null],
108 dnl Initial guess, used when cross-compiling or when no suitable locale
112 # Guess no on HP-UX and OSF/1.
113 hpux* | osf*) gl_cv_func_wcsrtombs_null="guessing no" ;;
114 # Guess yes otherwise.
115 *) gl_cv_func_wcsrtombs_null="guessing yes" ;;
118 if test $LOCALE_FR != none; then
125 if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
127 const char original[] = "B\374\337er";
130 if (mbstowcs (input, original, 10) == 5)
132 const wchar_t *src = input;
133 wcsrtombs (NULL, &src, 10, NULL);
140 [gl_cv_func_wcsrtombs_null=yes],
141 [gl_cv_func_wcsrtombs_null=no],
147 # Prerequisites of lib/wcsrtombs.c.
148 AC_DEFUN([gl_PREREQ_WCSRTOMBS], [