1 dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues.
3 dnl Copyright (C) 2007-2020 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 dnl Written by Eric Blake.
10 # wchar_h.m4 serial 48
12 AC_DEFUN([gl_WCHAR_H],
14 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
15 AC_REQUIRE([gl_WCHAR_H_INLINE_OK])
16 dnl Prepare for creating substitute <wchar.h>.
17 dnl Check for <wchar.h> (missing in Linux uClibc when built without wide
18 dnl character support).
19 dnl <wchar.h> is always overridden, because of GNULIB_POSIXCHECK.
20 gl_CHECK_NEXT_HEADERS([wchar.h])
21 if test $ac_cv_header_wchar_h = yes; then
26 AC_SUBST([HAVE_WCHAR_H])
28 AC_REQUIRE([gl_FEATURES_H])
30 AC_REQUIRE([gt_TYPE_WINT_T])
31 if test $gt_cv_c_wint_t = yes; then
36 AC_SUBST([HAVE_WINT_T])
38 AC_REQUIRE([gl_TYPE_WINT_T_PREREQ])
40 dnl Check for declarations of anything we want to poison if the
41 dnl corresponding gnulib module is not in use.
42 gl_WARN_ON_USE_PREPARE([[
43 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
45 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
46 included before <wchar.h>. */
47 #if !(defined __GLIBC__ && !defined __UCLIBC__)
54 [btowc wctob mbsinit mbrtowc mbrlen mbsrtowcs mbsnrtowcs wcrtomb
55 wcsrtombs wcsnrtombs wcwidth
56 wmemchr wmemcmp wmemcpy wmemmove wmempcpy wmemset
57 wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat wcscmp
58 wcsncmp wcscasecmp wcsncasecmp wcscoll wcsxfrm wcsdup wcschr wcsrchr
59 wcscspn wcsspn wcspbrk wcsstr wcstok wcswidth wcsftime
62 AC_REQUIRE([AC_C_RESTRICT])
64 AC_CHECK_DECLS([wcsdup], [], [], [[
65 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
67 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
68 included before <wchar.h>. */
69 #if !(defined __GLIBC__ && !defined __UCLIBC__)
76 if test $ac_cv_have_decl_wcsdup = no; then
81 dnl Check whether <wchar.h> is usable at all.
82 AC_DEFUN([gl_WCHAR_H_INLINE_OK],
84 dnl Test whether <wchar.h> suffers due to the transition from '__inline' to
85 dnl 'gnu_inline'. See <https://sourceware.org/bugzilla/show_bug.cgi?id=4022>
86 dnl and <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>. In summary,
87 dnl glibc version 2.5 or older, together with gcc version 4.3 or newer and
88 dnl the option -std=c99 or -std=gnu99, leads to a broken <wchar.h>.
89 AC_REQUIRE([AC_CANONICAL_HOST])
90 AC_CACHE_CHECK([whether <wchar.h> uses 'inline' correctly],
91 [gl_cv_header_wchar_h_correct_inline],
92 [gl_cv_header_wchar_h_correct_inline=yes
96 AC_LANG_SOURCE([[#define wcstod renamed_wcstod
97 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
99 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
100 included before <wchar.h>. */
105 extern int zero (void);
106 int main () { return zero(); }
108 dnl Do not rename the object file from conftest.$ac_objext to
109 dnl conftest1.$ac_objext, as this will cause the link to fail on
110 dnl z/OS when using the XPLINK object format (due to duplicate
111 dnl CSECT names). Instead, temporarily redefine $ac_compile so
112 dnl that the object file has the latter name from the start.
113 save_ac_compile="$ac_compile"
114 ac_compile=`echo "$save_ac_compile" | sed s/conftest/conftest1/`
115 if echo '#include "conftest.c"' >conftest1.c \
116 && AC_TRY_EVAL([ac_compile]); then
118 AC_LANG_SOURCE([[#define wcstod renamed_wcstod
119 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
121 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
122 included before <wchar.h>. */
127 int zero (void) { return 0; }
129 dnl See note above about renaming object files.
130 ac_compile=`echo "$save_ac_compile" | sed s/conftest/conftest2/`
131 if echo '#include "conftest.c"' >conftest2.c \
132 && AC_TRY_EVAL([ac_compile]); then
133 if $CC -o conftest$ac_exeext $CFLAGS $LDFLAGS conftest1.$ac_objext conftest2.$ac_objext $LIBS >&AS_MESSAGE_LOG_FD 2>&1; then
136 gl_cv_header_wchar_h_correct_inline=no
140 ac_compile="$save_ac_compile"
141 rm -f conftest[12].c conftest[12].$ac_objext conftest$ac_exeext
145 if test $gl_cv_header_wchar_h_correct_inline = no; then
146 AC_MSG_ERROR([<wchar.h> cannot be used with this compiler ($CC $CFLAGS $CPPFLAGS).
147 This is a known interoperability problem of glibc <= 2.5 with gcc >= 4.3 in
148 C99 mode. You have four options:
149 - Add the flag -fgnu89-inline to CC and reconfigure, or
150 - Fix your include files, using parts of
151 <https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b037a293a48718af30d706c2e18c929d0e69a621>, or
152 - Use a gcc version older than 4.3, or
153 - Don't use the flags -std=c99 or -std=gnu99.
154 Configuration aborted.])
158 AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
160 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
161 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
162 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
163 dnl Define it also as a C macro, for the benefit of the unit tests.
164 gl_MODULE_INDICATOR_FOR_TESTS([$1])
167 AC_DEFUN([gl_WCHAR_H_DEFAULTS],
169 GNULIB_BTOWC=0; AC_SUBST([GNULIB_BTOWC])
170 GNULIB_WCTOB=0; AC_SUBST([GNULIB_WCTOB])
171 GNULIB_MBSINIT=0; AC_SUBST([GNULIB_MBSINIT])
172 GNULIB_MBRTOWC=0; AC_SUBST([GNULIB_MBRTOWC])
173 GNULIB_MBRLEN=0; AC_SUBST([GNULIB_MBRLEN])
174 GNULIB_MBSRTOWCS=0; AC_SUBST([GNULIB_MBSRTOWCS])
175 GNULIB_MBSNRTOWCS=0; AC_SUBST([GNULIB_MBSNRTOWCS])
176 GNULIB_WCRTOMB=0; AC_SUBST([GNULIB_WCRTOMB])
177 GNULIB_WCSRTOMBS=0; AC_SUBST([GNULIB_WCSRTOMBS])
178 GNULIB_WCSNRTOMBS=0; AC_SUBST([GNULIB_WCSNRTOMBS])
179 GNULIB_WCWIDTH=0; AC_SUBST([GNULIB_WCWIDTH])
180 GNULIB_WMEMCHR=0; AC_SUBST([GNULIB_WMEMCHR])
181 GNULIB_WMEMCMP=0; AC_SUBST([GNULIB_WMEMCMP])
182 GNULIB_WMEMCPY=0; AC_SUBST([GNULIB_WMEMCPY])
183 GNULIB_WMEMMOVE=0; AC_SUBST([GNULIB_WMEMMOVE])
184 GNULIB_WMEMPCPY=0; AC_SUBST([GNULIB_WMEMPCPY])
185 GNULIB_WMEMSET=0; AC_SUBST([GNULIB_WMEMSET])
186 GNULIB_WCSLEN=0; AC_SUBST([GNULIB_WCSLEN])
187 GNULIB_WCSNLEN=0; AC_SUBST([GNULIB_WCSNLEN])
188 GNULIB_WCSCPY=0; AC_SUBST([GNULIB_WCSCPY])
189 GNULIB_WCPCPY=0; AC_SUBST([GNULIB_WCPCPY])
190 GNULIB_WCSNCPY=0; AC_SUBST([GNULIB_WCSNCPY])
191 GNULIB_WCPNCPY=0; AC_SUBST([GNULIB_WCPNCPY])
192 GNULIB_WCSCAT=0; AC_SUBST([GNULIB_WCSCAT])
193 GNULIB_WCSNCAT=0; AC_SUBST([GNULIB_WCSNCAT])
194 GNULIB_WCSCMP=0; AC_SUBST([GNULIB_WCSCMP])
195 GNULIB_WCSNCMP=0; AC_SUBST([GNULIB_WCSNCMP])
196 GNULIB_WCSCASECMP=0; AC_SUBST([GNULIB_WCSCASECMP])
197 GNULIB_WCSNCASECMP=0; AC_SUBST([GNULIB_WCSNCASECMP])
198 GNULIB_WCSCOLL=0; AC_SUBST([GNULIB_WCSCOLL])
199 GNULIB_WCSXFRM=0; AC_SUBST([GNULIB_WCSXFRM])
200 GNULIB_WCSDUP=0; AC_SUBST([GNULIB_WCSDUP])
201 GNULIB_WCSCHR=0; AC_SUBST([GNULIB_WCSCHR])
202 GNULIB_WCSRCHR=0; AC_SUBST([GNULIB_WCSRCHR])
203 GNULIB_WCSCSPN=0; AC_SUBST([GNULIB_WCSCSPN])
204 GNULIB_WCSSPN=0; AC_SUBST([GNULIB_WCSSPN])
205 GNULIB_WCSPBRK=0; AC_SUBST([GNULIB_WCSPBRK])
206 GNULIB_WCSSTR=0; AC_SUBST([GNULIB_WCSSTR])
207 GNULIB_WCSTOK=0; AC_SUBST([GNULIB_WCSTOK])
208 GNULIB_WCSWIDTH=0; AC_SUBST([GNULIB_WCSWIDTH])
209 GNULIB_WCSFTIME=0; AC_SUBST([GNULIB_WCSFTIME])
210 dnl Assume proper GNU behavior unless another module says otherwise.
211 HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC])
212 HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT])
213 HAVE_MBRTOWC=1; AC_SUBST([HAVE_MBRTOWC])
214 HAVE_MBRLEN=1; AC_SUBST([HAVE_MBRLEN])
215 HAVE_MBSRTOWCS=1; AC_SUBST([HAVE_MBSRTOWCS])
216 HAVE_MBSNRTOWCS=1; AC_SUBST([HAVE_MBSNRTOWCS])
217 HAVE_WCRTOMB=1; AC_SUBST([HAVE_WCRTOMB])
218 HAVE_WCSRTOMBS=1; AC_SUBST([HAVE_WCSRTOMBS])
219 HAVE_WCSNRTOMBS=1; AC_SUBST([HAVE_WCSNRTOMBS])
220 HAVE_WMEMCHR=1; AC_SUBST([HAVE_WMEMCHR])
221 HAVE_WMEMCMP=1; AC_SUBST([HAVE_WMEMCMP])
222 HAVE_WMEMCPY=1; AC_SUBST([HAVE_WMEMCPY])
223 HAVE_WMEMMOVE=1; AC_SUBST([HAVE_WMEMMOVE])
224 HAVE_WMEMPCPY=1; AC_SUBST([HAVE_WMEMPCPY])
225 HAVE_WMEMSET=1; AC_SUBST([HAVE_WMEMSET])
226 HAVE_WCSLEN=1; AC_SUBST([HAVE_WCSLEN])
227 HAVE_WCSNLEN=1; AC_SUBST([HAVE_WCSNLEN])
228 HAVE_WCSCPY=1; AC_SUBST([HAVE_WCSCPY])
229 HAVE_WCPCPY=1; AC_SUBST([HAVE_WCPCPY])
230 HAVE_WCSNCPY=1; AC_SUBST([HAVE_WCSNCPY])
231 HAVE_WCPNCPY=1; AC_SUBST([HAVE_WCPNCPY])
232 HAVE_WCSCAT=1; AC_SUBST([HAVE_WCSCAT])
233 HAVE_WCSNCAT=1; AC_SUBST([HAVE_WCSNCAT])
234 HAVE_WCSCMP=1; AC_SUBST([HAVE_WCSCMP])
235 HAVE_WCSNCMP=1; AC_SUBST([HAVE_WCSNCMP])
236 HAVE_WCSCASECMP=1; AC_SUBST([HAVE_WCSCASECMP])
237 HAVE_WCSNCASECMP=1; AC_SUBST([HAVE_WCSNCASECMP])
238 HAVE_WCSCOLL=1; AC_SUBST([HAVE_WCSCOLL])
239 HAVE_WCSXFRM=1; AC_SUBST([HAVE_WCSXFRM])
240 HAVE_WCSDUP=1; AC_SUBST([HAVE_WCSDUP])
241 HAVE_WCSCHR=1; AC_SUBST([HAVE_WCSCHR])
242 HAVE_WCSRCHR=1; AC_SUBST([HAVE_WCSRCHR])
243 HAVE_WCSCSPN=1; AC_SUBST([HAVE_WCSCSPN])
244 HAVE_WCSSPN=1; AC_SUBST([HAVE_WCSSPN])
245 HAVE_WCSPBRK=1; AC_SUBST([HAVE_WCSPBRK])
246 HAVE_WCSSTR=1; AC_SUBST([HAVE_WCSSTR])
247 HAVE_WCSTOK=1; AC_SUBST([HAVE_WCSTOK])
248 HAVE_WCSWIDTH=1; AC_SUBST([HAVE_WCSWIDTH])
249 HAVE_WCSFTIME=1; AC_SUBST([HAVE_WCSFTIME])
250 HAVE_DECL_WCTOB=1; AC_SUBST([HAVE_DECL_WCTOB])
251 HAVE_DECL_WCSDUP=1; AC_SUBST([HAVE_DECL_WCSDUP])
252 HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH])
253 REPLACE_MBSTATE_T=0; AC_SUBST([REPLACE_MBSTATE_T])
254 REPLACE_BTOWC=0; AC_SUBST([REPLACE_BTOWC])
255 REPLACE_WCTOB=0; AC_SUBST([REPLACE_WCTOB])
256 REPLACE_MBSINIT=0; AC_SUBST([REPLACE_MBSINIT])
257 REPLACE_MBRTOWC=0; AC_SUBST([REPLACE_MBRTOWC])
258 REPLACE_MBRLEN=0; AC_SUBST([REPLACE_MBRLEN])
259 REPLACE_MBSRTOWCS=0; AC_SUBST([REPLACE_MBSRTOWCS])
260 REPLACE_MBSNRTOWCS=0; AC_SUBST([REPLACE_MBSNRTOWCS])
261 REPLACE_WCRTOMB=0; AC_SUBST([REPLACE_WCRTOMB])
262 REPLACE_WCSRTOMBS=0; AC_SUBST([REPLACE_WCSRTOMBS])
263 REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS])
264 REPLACE_WCWIDTH=0; AC_SUBST([REPLACE_WCWIDTH])
265 REPLACE_WCSWIDTH=0; AC_SUBST([REPLACE_WCSWIDTH])
266 REPLACE_WCSFTIME=0; AC_SUBST([REPLACE_WCSFTIME])
267 REPLACE_WCSTOK=0; AC_SUBST([REPLACE_WCSTOK])