NEWS.stable: update
[gnulib.git] / m4 / wcsrtombs.m4
1 # wcsrtombs.m4 serial 9
2 dnl Copyright (C) 2008-2011 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.
6
7 AC_DEFUN([gl_FUNC_WCSRTOMBS],
8 [
9   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
10
11   AC_REQUIRE([AC_TYPE_MBSTATE_T])
12   gl_MBSTATE_T_BROKEN
13
14   AC_CHECK_FUNCS_ONCE([wcsrtombs])
15   if test $ac_cv_func_wcsrtombs = no; then
16     HAVE_WCSRTOMBS=0
17   else
18     if test $REPLACE_MBSTATE_T = 1; then
19       REPLACE_WCSRTOMBS=1
20     else
21       gl_WCSRTOMBS_TERMINATION
22       gl_WCSRTOMBS_NULL
23       case "$gl_cv_func_wcsrtombs_termination" in
24         *yes) ;;
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 ;;
28       esac
29       case "$gl_cv_func_wcsrtombs_null" in
30         *yes) ;;
31         *) AC_DEFINE([WCSRTOMBS_NULL_ARG_BUG], [1],
32              [Define if the wcsrtombs function has the NULL destination argument bug.])
33            REPLACE_WCSRTOMBS=1 ;;
34       esac
35     fi
36   fi
37   if test $HAVE_WCSRTOMBS = 0 || test $REPLACE_WCSRTOMBS = 1; then
38     AC_LIBOBJ([wcsrtombs])
39     AC_LIBOBJ([wcsrtombs-state])
40     gl_PREREQ_WCSRTOMBS
41   fi
42 ])
43
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.
50
51 AC_DEFUN([gl_WCSRTOMBS_TERMINATION],
52 [
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],
58     [
59       dnl Initial guess, used when cross-compiling or when no suitable locale
60       dnl is present.
61 changequote(,)dnl
62       case "$host_os" in
63               # Guess no on OSF/1.
64         osf*) gl_cv_func_wcsrtombs_termination="guessing no" ;;
65               # Guess yes otherwise.
66         *)    gl_cv_func_wcsrtombs_termination="guessing yes" ;;
67       esac
68 changequote([,])dnl
69       if test $LOCALE_FR != none; then
70         AC_RUN_IFELSE(
71           [AC_LANG_SOURCE([[
72 #include <locale.h>
73 #include <stdlib.h>
74 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
75    <wchar.h>.
76    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
77    included before <wchar.h>.  */
78 #include <stddef.h>
79 #include <stdio.h>
80 #include <time.h>
81 #include <wchar.h>
82 int main ()
83 {
84   if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
85     {
86       const char original[] = "B\374\337er";
87       wchar_t input[10];
88
89       if (mbstowcs (input, original, 10) == 5)
90         {
91           const wchar_t *src = input;
92           char output[5];
93           wcsrtombs (output, &src, 5, NULL);
94           if (src != input + 5)
95             return 1;
96         }
97     }
98   return 0;
99 }]])],
100           [gl_cv_func_wcsrtombs_termination=yes],
101           [gl_cv_func_wcsrtombs_termination=no],
102           [:])
103       fi
104     ])
105 ])
106
107 dnl Test whether the wcsrtombs implementation supports a NULL argument
108 dnl correctly. This is not the case on HP-UX 11.11 and OSF/1 5.1: These
109 dnl implementations updates the source pointer also if the destination argument
110 dnl is NULL.
111 dnl Result is gl_cv_func_wcsrtombs_null.
112
113 AC_DEFUN([gl_WCSRTOMBS_NULL],
114 [
115   AC_REQUIRE([AC_PROG_CC])
116   AC_REQUIRE([gt_LOCALE_FR])
117   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
118   AC_CACHE_CHECK([whether wcsrtombs supports a NULL argument correctly],
119     [gl_cv_func_wcsrtombs_null],
120     [
121       dnl Initial guess, used when cross-compiling or when no suitable locale
122       dnl is present.
123 changequote(,)dnl
124       case "$host_os" in
125                                # Guess no on HP-UX, OSF/1, mingw.
126         hpux* | osf* | mingw*) gl_cv_func_wcsrtombs_null="guessing no" ;;
127                                # Guess yes otherwise.
128         *)                     gl_cv_func_wcsrtombs_null="guessing yes" ;;
129       esac
130 changequote([,])dnl
131       if test $LOCALE_FR != none; then
132         AC_RUN_IFELSE(
133           [AC_LANG_SOURCE([[
134 #include <locale.h>
135 #include <stdlib.h>
136 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
137    <wchar.h>.
138    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
139    included before <wchar.h>.  */
140 #include <stddef.h>
141 #include <stdio.h>
142 #include <time.h>
143 #include <wchar.h>
144 int main ()
145 {
146   int result = 0;
147   if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
148     {
149       const char original[] = "B\374\337er";
150       wchar_t input[10];
151
152       if (mbstowcs (input, original, 10) == 5)
153         {
154           const wchar_t *src = input;
155           size_t ret = wcsrtombs (NULL, &src, 3, NULL);
156           if (ret != 5)
157             result |= 1;
158           if (src != input)
159             result |= 2;
160         }
161     }
162   return result;
163 }]])],
164           [gl_cv_func_wcsrtombs_null=yes],
165           [gl_cv_func_wcsrtombs_null=no],
166           [:])
167       fi
168     ])
169 ])
170
171 # Prerequisites of lib/wcsrtombs.c.
172 AC_DEFUN([gl_PREREQ_WCSRTOMBS], [
173   :
174 ])