summaryrefslogtreecommitdiffstats
path: root/gl/m4/mbrtowc.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/mbrtowc.m4')
-rw-r--r--gl/m4/mbrtowc.m4100
1 files changed, 21 insertions, 79 deletions
diff --git a/gl/m4/mbrtowc.m4 b/gl/m4/mbrtowc.m4
index 62c4fdb3..a49872fa 100644
--- a/gl/m4/mbrtowc.m4
+++ b/gl/m4/mbrtowc.m4
@@ -1,10 +1,11 @@
1# mbrtowc.m4 1# mbrtowc.m4
2# serial 44 -*- coding: utf-8 -*- 2# serial 47
3dnl Copyright (C) 2001-2002, 2004-2005, 2008-2024 Free Software Foundation, 3dnl Copyright (C) 2001-2002, 2004-2005, 2008-2026 Free Software Foundation,
4dnl Inc. 4dnl Inc.
5dnl This file is free software; the Free Software Foundation 5dnl This file is free software; the Free Software Foundation
6dnl gives unlimited permission to copy and/or distribute it, 6dnl gives unlimited permission to copy and/or distribute it,
7dnl with or without modifications, as long as this notice is preserved. 7dnl with or without modifications, as long as this notice is preserved.
8dnl This file is offered as-is, without any warranty.
8 9
9AC_DEFUN([gl_FUNC_MBRTOWC], 10AC_DEFUN([gl_FUNC_MBRTOWC],
10[ 11[
@@ -32,7 +33,6 @@ AC_DEFUN([gl_FUNC_MBRTOWC],
32 REPLACE_MBRTOWC=1 33 REPLACE_MBRTOWC=1
33 else 34 else
34 gl_MBRTOWC_NULL_ARG1 35 gl_MBRTOWC_NULL_ARG1
35 gl_MBRTOWC_NULL_ARG2
36 gl_MBRTOWC_RETVAL 36 gl_MBRTOWC_RETVAL
37 gl_MBRTOWC_NUL_RETVAL 37 gl_MBRTOWC_NUL_RETVAL
38 gl_MBRTOWC_STORES_INCOMPLETE 38 gl_MBRTOWC_STORES_INCOMPLETE
@@ -45,13 +45,6 @@ AC_DEFUN([gl_FUNC_MBRTOWC],
45 REPLACE_MBRTOWC=1 45 REPLACE_MBRTOWC=1
46 ;; 46 ;;
47 esac 47 esac
48 case "$gl_cv_func_mbrtowc_null_arg2" in
49 *yes) ;;
50 *) AC_DEFINE([MBRTOWC_NULL_ARG2_BUG], [1],
51 [Define if the mbrtowc function has the NULL string argument bug.])
52 REPLACE_MBRTOWC=1
53 ;;
54 esac
55 case "$gl_cv_func_mbrtowc_retval" in 48 case "$gl_cv_func_mbrtowc_retval" in
56 *yes) ;; 49 *yes) ;;
57 *) AC_DEFINE([MBRTOWC_RETVAL_BUG], [1], 50 *) AC_DEFINE([MBRTOWC_RETVAL_BUG], [1],
@@ -160,7 +153,7 @@ AC_DEFUN([gl_MBRTOWC_INCOMPLETE_STATE],
160[ 153[
161 AC_REQUIRE([AC_PROG_CC]) 154 AC_REQUIRE([AC_PROG_CC])
162 AC_REQUIRE([gt_LOCALE_JA]) 155 AC_REQUIRE([gt_LOCALE_JA])
163 AC_REQUIRE([gt_LOCALE_FR_UTF8]) 156 AC_REQUIRE([gt_LOCALE_EN_UTF8])
164 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 157 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
165 AC_CACHE_CHECK([whether mbrtowc handles incomplete characters], 158 AC_CACHE_CHECK([whether mbrtowc handles incomplete characters],
166 [gl_cv_func_mbrtowc_incomplete_state], 159 [gl_cv_func_mbrtowc_incomplete_state],
@@ -169,10 +162,10 @@ AC_DEFUN([gl_MBRTOWC_INCOMPLETE_STATE],
169 dnl is present. 162 dnl is present.
170changequote(,)dnl 163changequote(,)dnl
171 case "$host_os" in 164 case "$host_os" in
172 # Guess no on AIX and OSF/1. 165 # Guess no on AIX.
173 aix* | osf*) gl_cv_func_mbrtowc_incomplete_state="guessing no" ;; 166 aix*) gl_cv_func_mbrtowc_incomplete_state="guessing no" ;;
174 # Guess yes otherwise. 167 # Guess yes otherwise.
175 *) gl_cv_func_mbrtowc_incomplete_state="guessing yes" ;; 168 *) gl_cv_func_mbrtowc_incomplete_state="guessing yes" ;;
176 esac 169 esac
177changequote([,])dnl 170changequote([,])dnl
178 if test $LOCALE_JA != none; then 171 if test $LOCALE_JA != none; then
@@ -200,7 +193,7 @@ int main ()
200 [gl_cv_func_mbrtowc_incomplete_state=no], 193 [gl_cv_func_mbrtowc_incomplete_state=no],
201 [:]) 194 [:])
202 else 195 else
203 if test $LOCALE_FR_UTF8 != none; then 196 if test "$LOCALE_EN_UTF8" != none; then
204 AC_RUN_IFELSE( 197 AC_RUN_IFELSE(
205 [AC_LANG_SOURCE([[ 198 [AC_LANG_SOURCE([[
206#include <locale.h> 199#include <locale.h>
@@ -208,7 +201,7 @@ int main ()
208#include <wchar.h> 201#include <wchar.h>
209int main () 202int main ()
210{ 203{
211 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL) 204 if (setlocale (LC_ALL, "$LOCALE_EN_UTF8") != NULL)
212 { 205 {
213 const char input[] = "B\303\274\303\237er"; /* "Büßer" */ 206 const char input[] = "B\303\274\303\237er"; /* "Büßer" */
214 mbstate_t state; 207 mbstate_t state;
@@ -288,7 +281,7 @@ dnl Result is gl_cv_func_mbrtowc_null_arg1.
288AC_DEFUN([gl_MBRTOWC_NULL_ARG1], 281AC_DEFUN([gl_MBRTOWC_NULL_ARG1],
289[ 282[
290 AC_REQUIRE([AC_PROG_CC]) 283 AC_REQUIRE([AC_PROG_CC])
291 AC_REQUIRE([gt_LOCALE_FR_UTF8]) 284 AC_REQUIRE([gt_LOCALE_EN_UTF8])
292 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 285 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
293 AC_CACHE_CHECK([whether mbrtowc handles a NULL pwc argument], 286 AC_CACHE_CHECK([whether mbrtowc handles a NULL pwc argument],
294 [gl_cv_func_mbrtowc_null_arg1], 287 [gl_cv_func_mbrtowc_null_arg1],
@@ -303,7 +296,7 @@ changequote(,)dnl
303 *) gl_cv_func_mbrtowc_null_arg1="guessing yes" ;; 296 *) gl_cv_func_mbrtowc_null_arg1="guessing yes" ;;
304 esac 297 esac
305changequote([,])dnl 298changequote([,])dnl
306 if test $LOCALE_FR_UTF8 != none; then 299 if test "$LOCALE_EN_UTF8" != none; then
307 AC_RUN_IFELSE( 300 AC_RUN_IFELSE(
308 [AC_LANG_SOURCE([[ 301 [AC_LANG_SOURCE([[
309#include <locale.h> 302#include <locale.h>
@@ -314,7 +307,7 @@ int main ()
314{ 307{
315 int result = 0; 308 int result = 0;
316 309
317 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL) 310 if (setlocale (LC_ALL, "$LOCALE_EN_UTF8") != NULL)
318 { 311 {
319 char input[] = "\303\237er"; 312 char input[] = "\303\237er";
320 mbstate_t state; 313 mbstate_t state;
@@ -345,57 +338,6 @@ int main ()
345 ]) 338 ])
346]) 339])
347 340
348dnl Test whether mbrtowc supports a NULL string argument correctly.
349dnl Result is gl_cv_func_mbrtowc_null_arg2.
350
351AC_DEFUN([gl_MBRTOWC_NULL_ARG2],
352[
353 AC_REQUIRE([AC_PROG_CC])
354 AC_REQUIRE([gt_LOCALE_FR_UTF8])
355 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
356 AC_CACHE_CHECK([whether mbrtowc handles a NULL string argument],
357 [gl_cv_func_mbrtowc_null_arg2],
358 [
359 dnl Initial guess, used when cross-compiling or when no suitable locale
360 dnl is present.
361changequote(,)dnl
362 case "$host_os" in
363 # Guess no on OSF/1.
364 osf*) gl_cv_func_mbrtowc_null_arg2="guessing no" ;;
365 # Guess yes otherwise.
366 *) gl_cv_func_mbrtowc_null_arg2="guessing yes" ;;
367 esac
368changequote([,])dnl
369 if test $LOCALE_FR_UTF8 != none; then
370 AC_RUN_IFELSE(
371 [AC_LANG_SOURCE([[
372#include <locale.h>
373#include <string.h>
374#include <wchar.h>
375int main ()
376{
377 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
378 {
379 mbstate_t state;
380 wchar_t wc;
381 int ret;
382
383 memset (&state, '\0', sizeof (mbstate_t));
384 wc = (wchar_t) 0xBADFACE;
385 mbrtowc (&wc, NULL, 5, &state);
386 /* Check that wc was not modified. */
387 if (wc != (wchar_t) 0xBADFACE)
388 return 2;
389 }
390 return 0;
391}]])],
392 [gl_cv_func_mbrtowc_null_arg2=yes],
393 [gl_cv_func_mbrtowc_null_arg2=no],
394 [:])
395 fi
396 ])
397])
398
399dnl Test whether mbrtowc, when parsing the end of a multibyte character, 341dnl Test whether mbrtowc, when parsing the end of a multibyte character,
400dnl correctly returns the number of bytes that were needed to complete the 342dnl correctly returns the number of bytes that were needed to complete the
401dnl character (not the total number of bytes of the multibyte character). 343dnl character (not the total number of bytes of the multibyte character).
@@ -404,7 +346,7 @@ dnl Result is gl_cv_func_mbrtowc_retval.
404AC_DEFUN([gl_MBRTOWC_RETVAL], 346AC_DEFUN([gl_MBRTOWC_RETVAL],
405[ 347[
406 AC_REQUIRE([AC_PROG_CC]) 348 AC_REQUIRE([AC_PROG_CC])
407 AC_REQUIRE([gt_LOCALE_FR_UTF8]) 349 AC_REQUIRE([gt_LOCALE_EN_UTF8])
408 AC_REQUIRE([gt_LOCALE_JA]) 350 AC_REQUIRE([gt_LOCALE_JA])
409 AC_REQUIRE([AC_CANONICAL_HOST]) 351 AC_REQUIRE([AC_CANONICAL_HOST])
410 AC_CACHE_CHECK([whether mbrtowc has a correct return value], 352 AC_CACHE_CHECK([whether mbrtowc has a correct return value],
@@ -422,7 +364,7 @@ changequote(,)dnl
422 gl_cv_func_mbrtowc_retval="guessing yes" ;; 364 gl_cv_func_mbrtowc_retval="guessing yes" ;;
423 esac 365 esac
424changequote([,])dnl 366changequote([,])dnl
425 if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none \ 367 if test "$LOCALE_EN_UTF8" != none || test $LOCALE_JA != none \
426 || { case "$host_os" in mingw* | windows*) true;; *) false;; esac; }; then 368 || { case "$host_os" in mingw* | windows*) true;; *) false;; esac; }; then
427 AC_RUN_IFELSE( 369 AC_RUN_IFELSE(
428 [AC_LANG_SOURCE([[ 370 [AC_LANG_SOURCE([[
@@ -434,8 +376,8 @@ int main ()
434 int result = 0; 376 int result = 0;
435 int found_some_locale = 0; 377 int found_some_locale = 0;
436 /* This fails on Solaris. */ 378 /* This fails on Solaris. */
437 if (strcmp ("$LOCALE_FR_UTF8", "none") != 0 379 if (strcmp ("$LOCALE_EN_UTF8", "none") != 0
438 && setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL) 380 && setlocale (LC_ALL, "$LOCALE_EN_UTF8") != NULL)
439 { 381 {
440 char input[] = "B\303\274\303\237er"; /* "Büßer" */ 382 char input[] = "B\303\274\303\237er"; /* "Büßer" */
441 mbstate_t state; 383 mbstate_t state;
@@ -649,8 +591,8 @@ int main ()
649 [:]) 591 [:])
650 ;; 592 ;;
651 *) 593 *)
652 AC_REQUIRE([gt_LOCALE_FR_UTF8]) 594 AC_REQUIRE([gt_LOCALE_EN_UTF8])
653 if test $LOCALE_FR_UTF8 != none; then 595 if test "$LOCALE_EN_UTF8" != none; then
654 AC_RUN_IFELSE( 596 AC_RUN_IFELSE(
655 [AC_LANG_SOURCE([[ 597 [AC_LANG_SOURCE([[
656#include <locale.h> 598#include <locale.h>
@@ -658,7 +600,7 @@ int main ()
658#include <wchar.h> 600#include <wchar.h>
659int main () 601int main ()
660{ 602{
661 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL) 603 if (setlocale (LC_ALL, "$LOCALE_EN_UTF8") != NULL)
662 { 604 {
663 wchar_t wc = (wchar_t) 0xBADFACE; 605 wchar_t wc = (wchar_t) 0xBADFACE;
664 mbstate_t state; 606 mbstate_t state;
@@ -715,7 +657,7 @@ AC_DEFUN([gl_MBRTOWC_EMPTY_INPUT],
715dnl Test whether mbrtowc reports encoding errors in the C locale. 657dnl Test whether mbrtowc reports encoding errors in the C locale.
716dnl Although POSIX was never intended to allow this, the GNU C Library 658dnl Although POSIX was never intended to allow this, the GNU C Library
717dnl and other implementations do it. See: 659dnl and other implementations do it. See:
718dnl https://sourceware.org/bugzilla/show_bug.cgi?id=19932 660dnl https://sourceware.org/PR19932
719dnl POSIX has now clarified it: 661dnl POSIX has now clarified it:
720dnl <https://pubs.opengroup.org/onlinepubs/9699919799/functions/mbrtowc.html> 662dnl <https://pubs.opengroup.org/onlinepubs/9699919799/functions/mbrtowc.html>
721dnl says: "In the POSIX locale an [EILSEQ] error cannot occur since all byte 663dnl says: "In the POSIX locale an [EILSEQ] error cannot occur since all byte