"Fossies" - the Fresh Open Source Software Archive

Member "gcal-4.1/m4/mbrtowc.m4" (22 Jan 2017, 20136 Bytes) of package /linux/misc/gcal-4.1.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "mbrtowc.m4": 4_vs_4.1.

    1 # mbrtowc.m4 serial 27  -*- coding: utf-8 -*-
    2 dnl Copyright (C) 2001-2002, 2004-2005, 2008-2017 Free Software Foundation,
    3 dnl 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.
    7 
    8 AC_DEFUN([gl_FUNC_MBRTOWC],
    9 [
   10   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
   11 
   12   AC_REQUIRE([AC_TYPE_MBSTATE_T])
   13   gl_MBSTATE_T_BROKEN
   14 
   15   AC_CHECK_FUNCS_ONCE([mbrtowc])
   16   if test $ac_cv_func_mbrtowc = no; then
   17     HAVE_MBRTOWC=0
   18     AC_CHECK_DECLS([mbrtowc],,, [[
   19 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
   20    <wchar.h>.
   21    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
   22    included before <wchar.h>.  */
   23 #include <stddef.h>
   24 #include <stdio.h>
   25 #include <time.h>
   26 #include <wchar.h>
   27 ]])
   28     if test $ac_cv_have_decl_mbrtowc = yes; then
   29       dnl On Minix 3.1.8, the system's <wchar.h> declares mbrtowc() although
   30       dnl it does not have the function. Avoid a collision with gnulib's
   31       dnl replacement.
   32       REPLACE_MBRTOWC=1
   33     fi
   34   else
   35     if test $REPLACE_MBSTATE_T = 1; then
   36       REPLACE_MBRTOWC=1
   37     else
   38       gl_MBRTOWC_NULL_ARG1
   39       gl_MBRTOWC_NULL_ARG2
   40       gl_MBRTOWC_RETVAL
   41       gl_MBRTOWC_NUL_RETVAL
   42       gl_MBRTOWC_EMPTY_INPUT
   43       gl_MBRTOWC_C_LOCALE
   44       case "$gl_cv_func_mbrtowc_null_arg1" in
   45         *yes) ;;
   46         *) AC_DEFINE([MBRTOWC_NULL_ARG1_BUG], [1],
   47              [Define if the mbrtowc function has the NULL pwc argument bug.])
   48            REPLACE_MBRTOWC=1
   49            ;;
   50       esac
   51       case "$gl_cv_func_mbrtowc_null_arg2" in
   52         *yes) ;;
   53         *) AC_DEFINE([MBRTOWC_NULL_ARG2_BUG], [1],
   54              [Define if the mbrtowc function has the NULL string argument bug.])
   55            REPLACE_MBRTOWC=1
   56            ;;
   57       esac
   58       case "$gl_cv_func_mbrtowc_retval" in
   59         *yes) ;;
   60         *) AC_DEFINE([MBRTOWC_RETVAL_BUG], [1],
   61              [Define if the mbrtowc function returns a wrong return value.])
   62            REPLACE_MBRTOWC=1
   63            ;;
   64       esac
   65       case "$gl_cv_func_mbrtowc_nul_retval" in
   66         *yes) ;;
   67         *) AC_DEFINE([MBRTOWC_NUL_RETVAL_BUG], [1],
   68              [Define if the mbrtowc function does not return 0 for a NUL character.])
   69            REPLACE_MBRTOWC=1
   70            ;;
   71       esac
   72       case "$gl_cv_func_mbrtowc_empty_input" in
   73         *yes) ;;
   74         *) AC_DEFINE([MBRTOWC_EMPTY_INPUT_BUG], [1],
   75              [Define if the mbrtowc function does not return (size_t) -2
   76               for empty input.])
   77            REPLACE_MBRTOWC=1
   78            ;;
   79       esac
   80       case $gl_cv_C_locale_sans_EILSEQ in
   81         *yes) ;;
   82         *) AC_DEFINE([C_LOCALE_MAYBE_EILSEQ], [1],
   83              [Define to 1 if the C locale may have encoding errors.])
   84            REPLACE_MBRTOWC=1
   85            ;;
   86       esac
   87     fi
   88   fi
   89 ])
   90 
   91 dnl Test whether mbsinit() and mbrtowc() need to be overridden in a way that
   92 dnl redefines the semantics of the given mbstate_t type.
   93 dnl Result is REPLACE_MBSTATE_T.
   94 dnl When this is set to 1, we replace both mbsinit() and mbrtowc(), in order to
   95 dnl avoid inconsistencies.
   96 
   97 AC_DEFUN([gl_MBSTATE_T_BROKEN],
   98 [
   99   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
  100 
  101   AC_REQUIRE([AC_TYPE_MBSTATE_T])
  102   AC_CHECK_FUNCS_ONCE([mbsinit])
  103   AC_CHECK_FUNCS_ONCE([mbrtowc])
  104   if test $ac_cv_func_mbsinit = yes && test $ac_cv_func_mbrtowc = yes; then
  105     gl_MBRTOWC_INCOMPLETE_STATE
  106     gl_MBRTOWC_SANITYCHECK
  107     REPLACE_MBSTATE_T=0
  108     case "$gl_cv_func_mbrtowc_incomplete_state" in
  109       *yes) ;;
  110       *) REPLACE_MBSTATE_T=1 ;;
  111     esac
  112     case "$gl_cv_func_mbrtowc_sanitycheck" in
  113       *yes) ;;
  114       *) REPLACE_MBSTATE_T=1 ;;
  115     esac
  116   else
  117     REPLACE_MBSTATE_T=1
  118   fi
  119 ])
  120 
  121 dnl Test whether mbrtowc puts the state into non-initial state when parsing an
  122 dnl incomplete multibyte character.
  123 dnl Result is gl_cv_func_mbrtowc_incomplete_state.
  124 
  125 AC_DEFUN([gl_MBRTOWC_INCOMPLETE_STATE],
  126 [
  127   AC_REQUIRE([AC_PROG_CC])
  128   AC_REQUIRE([gt_LOCALE_JA])
  129   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  130   AC_CACHE_CHECK([whether mbrtowc handles incomplete characters],
  131     [gl_cv_func_mbrtowc_incomplete_state],
  132     [
  133       dnl Initial guess, used when cross-compiling or when no suitable locale
  134       dnl is present.
  135 changequote(,)dnl
  136       case "$host_os" in
  137                      # Guess no on AIX and OSF/1.
  138         aix* | osf*) gl_cv_func_mbrtowc_incomplete_state="guessing no" ;;
  139                      # Guess yes otherwise.
  140         *)           gl_cv_func_mbrtowc_incomplete_state="guessing yes" ;;
  141       esac
  142 changequote([,])dnl
  143       if test $LOCALE_JA != none; then
  144         AC_RUN_IFELSE(
  145           [AC_LANG_SOURCE([[
  146 #include <locale.h>
  147 #include <string.h>
  148 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  149    <wchar.h>.
  150    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  151    included before <wchar.h>.  */
  152 #include <stddef.h>
  153 #include <stdio.h>
  154 #include <time.h>
  155 #include <wchar.h>
  156 int main ()
  157 {
  158   if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
  159     {
  160       const char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
  161       mbstate_t state;
  162       wchar_t wc;
  163 
  164       memset (&state, '\0', sizeof (mbstate_t));
  165       if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
  166         if (mbsinit (&state))
  167           return 2;
  168     }
  169   return 0;
  170 }]])],
  171           [gl_cv_func_mbrtowc_incomplete_state=yes],
  172           [gl_cv_func_mbrtowc_incomplete_state=no],
  173           [:])
  174       fi
  175     ])
  176 ])
  177 
  178 dnl Test whether mbrtowc works not worse than mbtowc.
  179 dnl Result is gl_cv_func_mbrtowc_sanitycheck.
  180 
  181 AC_DEFUN([gl_MBRTOWC_SANITYCHECK],
  182 [
  183   AC_REQUIRE([AC_PROG_CC])
  184   AC_REQUIRE([gt_LOCALE_ZH_CN])
  185   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  186   AC_CACHE_CHECK([whether mbrtowc works as well as mbtowc],
  187     [gl_cv_func_mbrtowc_sanitycheck],
  188     [
  189       dnl Initial guess, used when cross-compiling or when no suitable locale
  190       dnl is present.
  191 changequote(,)dnl
  192       case "$host_os" in
  193                     # Guess no on Solaris 8.
  194         solaris2.8) gl_cv_func_mbrtowc_sanitycheck="guessing no" ;;
  195                     # Guess yes otherwise.
  196         *)          gl_cv_func_mbrtowc_sanitycheck="guessing yes" ;;
  197       esac
  198 changequote([,])dnl
  199       if test $LOCALE_ZH_CN != none; then
  200         AC_RUN_IFELSE(
  201           [AC_LANG_SOURCE([[
  202 #include <locale.h>
  203 #include <stdlib.h>
  204 #include <string.h>
  205 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  206    <wchar.h>.
  207    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  208    included before <wchar.h>.  */
  209 #include <stddef.h>
  210 #include <stdio.h>
  211 #include <time.h>
  212 #include <wchar.h>
  213 int main ()
  214 {
  215   /* This fails on Solaris 8:
  216      mbrtowc returns 2, and sets wc to 0x00F0.
  217      mbtowc returns 4 (correct) and sets wc to 0x5EDC.  */
  218   if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
  219     {
  220       char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */
  221       mbstate_t state;
  222       wchar_t wc;
  223 
  224       memset (&state, '\0', sizeof (mbstate_t));
  225       if (mbrtowc (&wc, input + 3, 6, &state) != 4
  226           && mbtowc (&wc, input + 3, 6) == 4)
  227         return 2;
  228     }
  229   return 0;
  230 }]])],
  231           [gl_cv_func_mbrtowc_sanitycheck=yes],
  232           [gl_cv_func_mbrtowc_sanitycheck=no],
  233           [:])
  234       fi
  235     ])
  236 ])
  237 
  238 dnl Test whether mbrtowc supports a NULL pwc argument correctly.
  239 dnl Result is gl_cv_func_mbrtowc_null_arg1.
  240 
  241 AC_DEFUN([gl_MBRTOWC_NULL_ARG1],
  242 [
  243   AC_REQUIRE([AC_PROG_CC])
  244   AC_REQUIRE([gt_LOCALE_FR_UTF8])
  245   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  246   AC_CACHE_CHECK([whether mbrtowc handles a NULL pwc argument],
  247     [gl_cv_func_mbrtowc_null_arg1],
  248     [
  249       dnl Initial guess, used when cross-compiling or when no suitable locale
  250       dnl is present.
  251 changequote(,)dnl
  252       case "$host_os" in
  253                   # Guess no on Solaris.
  254         solaris*) gl_cv_func_mbrtowc_null_arg1="guessing no" ;;
  255                   # Guess yes otherwise.
  256         *)        gl_cv_func_mbrtowc_null_arg1="guessing yes" ;;
  257       esac
  258 changequote([,])dnl
  259       if test $LOCALE_FR_UTF8 != none; then
  260         AC_RUN_IFELSE(
  261           [AC_LANG_SOURCE([[
  262 #include <locale.h>
  263 #include <stdlib.h>
  264 #include <string.h>
  265 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  266    <wchar.h>.
  267    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  268    included before <wchar.h>.  */
  269 #include <stddef.h>
  270 #include <stdio.h>
  271 #include <time.h>
  272 #include <wchar.h>
  273 int main ()
  274 {
  275   int result = 0;
  276 
  277   if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
  278     {
  279       char input[] = "\303\237er";
  280       mbstate_t state;
  281       wchar_t wc;
  282       size_t ret;
  283 
  284       memset (&state, '\0', sizeof (mbstate_t));
  285       wc = (wchar_t) 0xBADFACE;
  286       ret = mbrtowc (&wc, input, 5, &state);
  287       if (ret != 2)
  288         result |= 1;
  289       if (!mbsinit (&state))
  290         result |= 2;
  291 
  292       memset (&state, '\0', sizeof (mbstate_t));
  293       ret = mbrtowc (NULL, input, 5, &state);
  294       if (ret != 2) /* Solaris 7 fails here: ret is -1.  */
  295         result |= 4;
  296       if (!mbsinit (&state))
  297         result |= 8;
  298     }
  299   return result;
  300 }]])],
  301           [gl_cv_func_mbrtowc_null_arg1=yes],
  302           [gl_cv_func_mbrtowc_null_arg1=no],
  303           [:])
  304       fi
  305     ])
  306 ])
  307 
  308 dnl Test whether mbrtowc supports a NULL string argument correctly.
  309 dnl Result is gl_cv_func_mbrtowc_null_arg2.
  310 
  311 AC_DEFUN([gl_MBRTOWC_NULL_ARG2],
  312 [
  313   AC_REQUIRE([AC_PROG_CC])
  314   AC_REQUIRE([gt_LOCALE_FR_UTF8])
  315   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  316   AC_CACHE_CHECK([whether mbrtowc handles a NULL string argument],
  317     [gl_cv_func_mbrtowc_null_arg2],
  318     [
  319       dnl Initial guess, used when cross-compiling or when no suitable locale
  320       dnl is present.
  321 changequote(,)dnl
  322       case "$host_os" in
  323               # Guess no on OSF/1.
  324         osf*) gl_cv_func_mbrtowc_null_arg2="guessing no" ;;
  325               # Guess yes otherwise.
  326         *)    gl_cv_func_mbrtowc_null_arg2="guessing yes" ;;
  327       esac
  328 changequote([,])dnl
  329       if test $LOCALE_FR_UTF8 != none; then
  330         AC_RUN_IFELSE(
  331           [AC_LANG_SOURCE([[
  332 #include <locale.h>
  333 #include <string.h>
  334 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  335    <wchar.h>.
  336    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  337    included before <wchar.h>.  */
  338 #include <stddef.h>
  339 #include <stdio.h>
  340 #include <time.h>
  341 #include <wchar.h>
  342 int main ()
  343 {
  344   if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
  345     {
  346       mbstate_t state;
  347       wchar_t wc;
  348       int ret;
  349 
  350       memset (&state, '\0', sizeof (mbstate_t));
  351       wc = (wchar_t) 0xBADFACE;
  352       mbrtowc (&wc, NULL, 5, &state);
  353       /* Check that wc was not modified.  */
  354       if (wc != (wchar_t) 0xBADFACE)
  355         return 2;
  356     }
  357   return 0;
  358 }]])],
  359           [gl_cv_func_mbrtowc_null_arg2=yes],
  360           [gl_cv_func_mbrtowc_null_arg2=no],
  361           [:])
  362       fi
  363     ])
  364 ])
  365 
  366 dnl Test whether mbrtowc, when parsing the end of a multibyte character,
  367 dnl correctly returns the number of bytes that were needed to complete the
  368 dnl character (not the total number of bytes of the multibyte character).
  369 dnl Result is gl_cv_func_mbrtowc_retval.
  370 
  371 AC_DEFUN([gl_MBRTOWC_RETVAL],
  372 [
  373   AC_REQUIRE([AC_PROG_CC])
  374   AC_REQUIRE([gt_LOCALE_FR_UTF8])
  375   AC_REQUIRE([gt_LOCALE_JA])
  376   AC_REQUIRE([AC_CANONICAL_HOST])
  377   AC_CACHE_CHECK([whether mbrtowc has a correct return value],
  378     [gl_cv_func_mbrtowc_retval],
  379     [
  380       dnl Initial guess, used when cross-compiling or when no suitable locale
  381       dnl is present.
  382 changequote(,)dnl
  383       case "$host_os" in
  384                                    # Guess no on HP-UX, Solaris, native Windows.
  385         hpux* | solaris* | mingw*) gl_cv_func_mbrtowc_retval="guessing no" ;;
  386                                    # Guess yes otherwise.
  387         *)                         gl_cv_func_mbrtowc_retval="guessing yes" ;;
  388       esac
  389 changequote([,])dnl
  390       if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none \
  391          || { case "$host_os" in mingw*) true;; *) false;; esac; }; then
  392         AC_RUN_IFELSE(
  393           [AC_LANG_SOURCE([[
  394 #include <locale.h>
  395 #include <string.h>
  396 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  397    <wchar.h>.
  398    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  399    included before <wchar.h>.  */
  400 #include <stddef.h>
  401 #include <stdio.h>
  402 #include <time.h>
  403 #include <wchar.h>
  404 int main ()
  405 {
  406   int result = 0;
  407   int found_some_locale = 0;
  408   /* This fails on Solaris.  */
  409   if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
  410     {
  411       char input[] = "B\303\274\303\237er"; /* "Büßer" */
  412       mbstate_t state;
  413       wchar_t wc;
  414 
  415       memset (&state, '\0', sizeof (mbstate_t));
  416       if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
  417         {
  418           input[1] = '\0';
  419           if (mbrtowc (&wc, input + 2, 5, &state) != 1)
  420             result |= 1;
  421         }
  422       found_some_locale = 1;
  423     }
  424   /* This fails on HP-UX 11.11.  */
  425   if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
  426     {
  427       char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
  428       mbstate_t state;
  429       wchar_t wc;
  430 
  431       memset (&state, '\0', sizeof (mbstate_t));
  432       if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
  433         {
  434           input[1] = '\0';
  435           if (mbrtowc (&wc, input + 2, 5, &state) != 2)
  436             result |= 2;
  437         }
  438       found_some_locale = 1;
  439     }
  440   /* This fails on native Windows.  */
  441   if (setlocale (LC_ALL, "Japanese_Japan.932") != NULL)
  442     {
  443       char input[] = "<\223\372\226\173\214\352>"; /* "<日本語>" */
  444       mbstate_t state;
  445       wchar_t wc;
  446 
  447       memset (&state, '\0', sizeof (mbstate_t));
  448       if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2))
  449         {
  450           input[3] = '\0';
  451           if (mbrtowc (&wc, input + 4, 4, &state) != 1)
  452             result |= 4;
  453         }
  454       found_some_locale = 1;
  455     }
  456   if (setlocale (LC_ALL, "Chinese_Taiwan.950") != NULL)
  457     {
  458       char input[] = "<\244\351\245\273\273\171>"; /* "<日本語>" */
  459       mbstate_t state;
  460       wchar_t wc;
  461 
  462       memset (&state, '\0', sizeof (mbstate_t));
  463       if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2))
  464         {
  465           input[3] = '\0';
  466           if (mbrtowc (&wc, input + 4, 4, &state) != 1)
  467             result |= 8;
  468         }
  469       found_some_locale = 1;
  470     }
  471   if (setlocale (LC_ALL, "Chinese_China.936") != NULL)
  472     {
  473       char input[] = "<\310\325\261\276\325\132>"; /* "<日本語>" */
  474       mbstate_t state;
  475       wchar_t wc;
  476 
  477       memset (&state, '\0', sizeof (mbstate_t));
  478       if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2))
  479         {
  480           input[3] = '\0';
  481           if (mbrtowc (&wc, input + 4, 4, &state) != 1)
  482             result |= 16;
  483         }
  484       found_some_locale = 1;
  485     }
  486   return (found_some_locale ? result : 77);
  487 }]])],
  488           [gl_cv_func_mbrtowc_retval=yes],
  489           [if test $? != 77; then
  490              gl_cv_func_mbrtowc_retval=no
  491            fi
  492           ],
  493           [:])
  494       fi
  495     ])
  496 ])
  497 
  498 dnl Test whether mbrtowc, when parsing a NUL character, correctly returns 0.
  499 dnl Result is gl_cv_func_mbrtowc_nul_retval.
  500 
  501 AC_DEFUN([gl_MBRTOWC_NUL_RETVAL],
  502 [
  503   AC_REQUIRE([AC_PROG_CC])
  504   AC_REQUIRE([gt_LOCALE_ZH_CN])
  505   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  506   AC_CACHE_CHECK([whether mbrtowc returns 0 when parsing a NUL character],
  507     [gl_cv_func_mbrtowc_nul_retval],
  508     [
  509       dnl Initial guess, used when cross-compiling or when no suitable locale
  510       dnl is present.
  511 changequote(,)dnl
  512       case "$host_os" in
  513                        # Guess no on Solaris 8 and 9.
  514         solaris2.[89]) gl_cv_func_mbrtowc_nul_retval="guessing no" ;;
  515                        # Guess yes otherwise.
  516         *)             gl_cv_func_mbrtowc_nul_retval="guessing yes" ;;
  517       esac
  518 changequote([,])dnl
  519       if test $LOCALE_ZH_CN != none; then
  520         AC_RUN_IFELSE(
  521           [AC_LANG_SOURCE([[
  522 #include <locale.h>
  523 #include <string.h>
  524 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  525    <wchar.h>.
  526    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  527    included before <wchar.h>.  */
  528 #include <stddef.h>
  529 #include <stdio.h>
  530 #include <time.h>
  531 #include <wchar.h>
  532 int main ()
  533 {
  534   /* This fails on Solaris 8 and 9.  */
  535   if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
  536     {
  537       mbstate_t state;
  538       wchar_t wc;
  539 
  540       memset (&state, '\0', sizeof (mbstate_t));
  541       if (mbrtowc (&wc, "", 1, &state) != 0)
  542         return 2;
  543     }
  544   return 0;
  545 }]])],
  546           [gl_cv_func_mbrtowc_nul_retval=yes],
  547           [gl_cv_func_mbrtowc_nul_retval=no],
  548           [:])
  549       fi
  550     ])
  551 ])
  552 
  553 dnl Test whether mbrtowc returns the correct value on empty input.
  554 
  555 AC_DEFUN([gl_MBRTOWC_EMPTY_INPUT],
  556 [
  557   AC_REQUIRE([AC_PROG_CC])
  558   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  559   AC_CACHE_CHECK([whether mbrtowc works on empty input],
  560     [gl_cv_func_mbrtowc_empty_input],
  561     [
  562       dnl Initial guess, used when cross-compiling or when no suitable locale
  563       dnl is present.
  564 changequote(,)dnl
  565       case "$host_os" in
  566                      # Guess no on AIX and glibc systems.
  567         aix* | *-gnu*)
  568                     gl_cv_func_mbrtowc_empty_input="guessing no" ;;
  569         *)          gl_cv_func_mbrtowc_empty_input="guessing yes" ;;
  570       esac
  571 changequote([,])dnl
  572       AC_RUN_IFELSE(
  573         [AC_LANG_SOURCE([[
  574            #include <wchar.h>
  575            static wchar_t wc;
  576            static mbstate_t mbs;
  577            int
  578            main (void)
  579            {
  580              return mbrtowc (&wc, "", 0, &mbs) != (size_t) -2;
  581            }]])],
  582         [gl_cv_func_mbrtowc_empty_input=yes],
  583         [gl_cv_func_mbrtowc_empty_input=no],
  584         [:])
  585     ])
  586 ])
  587 
  588 dnl Test whether mbrtowc reports encoding errors in the C locale.
  589 dnl Although POSIX was never intended to allow this, the GNU C Library
  590 dnl and other implementations do it.  See:
  591 dnl https://sourceware.org/bugzilla/show_bug.cgi?id=19932
  592 
  593 AC_DEFUN([gl_MBRTOWC_C_LOCALE],
  594 [
  595   AC_CACHE_CHECK([whether the C locale is free of encoding errors],
  596     [gl_cv_C_locale_sans_EILSEQ],
  597     [
  598      dnl Initial guess, used when cross-compiling or when no suitable locale
  599      dnl is present.
  600      gl_cv_C_locale_sans_EILSEQ="guessing no"
  601 
  602      AC_RUN_IFELSE(
  603        [AC_LANG_PROGRAM(
  604           [[#include <limits.h>
  605             #include <locale.h>
  606             #include <wchar.h>
  607           ]], [[
  608             int i;
  609             char *locale = setlocale (LC_ALL, "C");
  610             if (! locale)
  611               return 2;
  612             for (i = CHAR_MIN; i <= CHAR_MAX; i++)
  613               {
  614                 char c = i;
  615                 wchar_t wc;
  616                 mbstate_t mbs = { 0, };
  617                 size_t ss = mbrtowc (&wc, &c, 1, &mbs);
  618                 if (1 < ss)
  619                   return 3;
  620               }
  621             return 0;
  622           ]])],
  623       [gl_cv_C_locale_sans_EILSEQ=yes],
  624       [gl_cv_C_locale_sans_EILSEQ=no],
  625       [:])])
  626 ])
  627 
  628 # Prerequisites of lib/mbrtowc.c.
  629 AC_DEFUN([gl_PREREQ_MBRTOWC], [
  630   :
  631 ])
  632 
  633 
  634 dnl From Paul Eggert
  635 
  636 dnl This is an override of an autoconf macro.
  637 
  638 AC_DEFUN([AC_FUNC_MBRTOWC],
  639 [
  640   dnl Same as AC_FUNC_MBRTOWC in autoconf-2.60.
  641   AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared],
  642     gl_cv_func_mbrtowc,
  643     [AC_LINK_IFELSE(
  644        [AC_LANG_PROGRAM(
  645             [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
  646                  included before <wchar.h>.
  647                  BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
  648                  must be included before <wchar.h>.  */
  649               #include <stddef.h>
  650               #include <stdio.h>
  651               #include <time.h>
  652               #include <wchar.h>]],
  653             [[wchar_t wc;
  654               char const s[] = "";
  655               size_t n = 1;
  656               mbstate_t state;
  657               return ! (sizeof state && (mbrtowc) (&wc, s, n, &state));]])],
  658        gl_cv_func_mbrtowc=yes,
  659        gl_cv_func_mbrtowc=no)])
  660   if test $gl_cv_func_mbrtowc = yes; then
  661     AC_DEFINE([HAVE_MBRTOWC], [1],
  662       [Define to 1 if mbrtowc and mbstate_t are properly declared.])
  663   fi
  664 ])