Blame m4/mbsrtowcs.m4

Packit Service a2489d
# mbsrtowcs.m4 serial 13
Packit Service a2489d
dnl Copyright (C) 2008-2018 Free Software Foundation, Inc.
Packit Service a2489d
dnl This file is free software; the Free Software Foundation
Packit Service a2489d
dnl gives unlimited permission to copy and/or distribute it,
Packit Service a2489d
dnl with or without modifications, as long as this notice is preserved.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_FUNC_MBSRTOWCS],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
Packit Service a2489d
Packit Service a2489d
  AC_REQUIRE([AC_TYPE_MBSTATE_T])
Packit Service a2489d
  gl_MBSTATE_T_BROKEN
Packit Service a2489d
Packit Service a2489d
  AC_CHECK_FUNCS_ONCE([mbsrtowcs])
Packit Service a2489d
  if test $ac_cv_func_mbsrtowcs = no; then
Packit Service a2489d
    HAVE_MBSRTOWCS=0
Packit Service a2489d
    AC_CHECK_DECLS([mbsrtowcs],,, [[
Packit Service a2489d
/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
Packit Service a2489d
   <wchar.h>.
Packit Service a2489d
   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
Packit Service a2489d
   included before <wchar.h>.  */
Packit Service a2489d
#include <stddef.h>
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#include <time.h>
Packit Service a2489d
#include <wchar.h>
Packit Service a2489d
]])
Packit Service a2489d
    if test $ac_cv_have_decl_mbsrtowcs = yes; then
Packit Service a2489d
      dnl On Minix 3.1.8, the system's <wchar.h> declares mbsrtowcs() although
Packit Service a2489d
      dnl it does not have the function. Avoid a collision with gnulib's
Packit Service a2489d
      dnl replacement.
Packit Service a2489d
      REPLACE_MBSRTOWCS=1
Packit Service a2489d
    fi
Packit Service a2489d
  else
Packit Service a2489d
    if test $REPLACE_MBSTATE_T = 1; then
Packit Service a2489d
      REPLACE_MBSRTOWCS=1
Packit Service a2489d
    else
Packit Service a2489d
      gl_MBSRTOWCS_WORKS
Packit Service a2489d
      case "$gl_cv_func_mbsrtowcs_works" in
Packit Service a2489d
        *yes) ;;
Packit Service a2489d
        *) REPLACE_MBSRTOWCS=1 ;;
Packit Service a2489d
      esac
Packit Service a2489d
    fi
Packit Service a2489d
  fi
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether mbsrtowcs works.
Packit Service a2489d
dnl Result is gl_cv_func_mbsrtowcs_works.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_MBSRTOWCS_WORKS],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([gt_LOCALE_FR])
Packit Service a2489d
  AC_REQUIRE([gt_LOCALE_FR_UTF8])
Packit Service a2489d
  AC_REQUIRE([gt_LOCALE_JA])
Packit Service a2489d
  AC_REQUIRE([gt_LOCALE_ZH_CN])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_CACHE_CHECK([whether mbsrtowcs works],
Packit Service a2489d
    [gl_cv_func_mbsrtowcs_works],
Packit Service a2489d
    [
Packit Service a2489d
      dnl Initial guess, used when cross-compiling or when no suitable locale
Packit Service a2489d
      dnl is present.
Packit Service a2489d
changequote(,)dnl
Packit Service a2489d
      case "$host_os" in
Packit Service a2489d
                                   # Guess no on HP-UX, Solaris, mingw.
Packit Service a2489d
        hpux* | solaris* | mingw*) gl_cv_func_mbsrtowcs_works="guessing no" ;;
Packit Service a2489d
                                   # Guess yes otherwise.
Packit Service a2489d
        *)                         gl_cv_func_mbsrtowcs_works="guessing yes" ;;
Packit Service a2489d
      esac
Packit Service a2489d
changequote([,])dnl
Packit Service a2489d
      if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
Packit Service a2489d
        AC_RUN_IFELSE(
Packit Service a2489d
          [AC_LANG_SOURCE([[
Packit Service a2489d
#include <locale.h>
Packit Service a2489d
#include <string.h>
Packit Service a2489d
/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
Packit Service a2489d
   <wchar.h>.
Packit Service a2489d
   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
Packit Service a2489d
   included before <wchar.h>.  */
Packit Service a2489d
#include <stddef.h>
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#include <time.h>
Packit Service a2489d
#include <wchar.h>
Packit Service a2489d
int main ()
Packit Service a2489d
{
Packit Service a2489d
  int result = 0;
Packit Service a2489d
  /* Test whether the function supports a NULL destination argument.
Packit Service a2489d
     This fails on native Windows.  */
Packit Service a2489d
  if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
Packit Service a2489d
    {
Packit Service a2489d
      const char input[] = "\337er";
Packit Service a2489d
      const char *src = input;
Packit Service a2489d
      mbstate_t state;
Packit Service a2489d
Packit Service a2489d
      memset (&state, '\0', sizeof (mbstate_t));
Packit Service a2489d
      if (mbsrtowcs (NULL, &src, 1, &state) != 3
Packit Service a2489d
          || src != input)
Packit Service a2489d
        result |= 1;
Packit Service a2489d
    }
Packit Service a2489d
  /* Test whether the function works when started with a conversion state
Packit Service a2489d
     in non-initial state.  This fails on HP-UX 11.11 and Solaris 10.  */
Packit Service a2489d
  if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
Packit Service a2489d
    {
Packit Service a2489d
      const char input[] = "B\303\274\303\237er";
Packit Service a2489d
      mbstate_t state;
Packit Service a2489d
Packit Service a2489d
      memset (&state, '\0', sizeof (mbstate_t));
Packit Service a2489d
      if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2))
Packit Service a2489d
        if (!mbsinit (&state))
Packit Service a2489d
          {
Packit Service a2489d
            const char *src = input + 2;
Packit Service a2489d
            if (mbsrtowcs (NULL, &src, 10, &state) != 4)
Packit Service a2489d
              result |= 2;
Packit Service a2489d
          }
Packit Service a2489d
    }
Packit Service a2489d
  if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
Packit Service a2489d
    {
Packit Service a2489d
      const char input[] = "<\306\374\313\334\270\354>";
Packit Service a2489d
      mbstate_t state;
Packit Service a2489d
Packit Service a2489d
      memset (&state, '\0', sizeof (mbstate_t));
Packit Service a2489d
      if (mbrtowc (NULL, input + 3, 1, &state) == (size_t)(-2))
Packit Service a2489d
        if (!mbsinit (&state))
Packit Service a2489d
          {
Packit Service a2489d
            const char *src = input + 4;
Packit Service a2489d
            if (mbsrtowcs (NULL, &src, 10, &state) != 3)
Packit Service a2489d
              result |= 4;
Packit Service a2489d
          }
Packit Service a2489d
    }
Packit Service a2489d
  if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
Packit Service a2489d
    {
Packit Service a2489d
      const char input[] = "B\250\271\201\060\211\070er";
Packit Service a2489d
      mbstate_t state;
Packit Service a2489d
Packit Service a2489d
      memset (&state, '\0', sizeof (mbstate_t));
Packit Service a2489d
      if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2))
Packit Service a2489d
        if (!mbsinit (&state))
Packit Service a2489d
          {
Packit Service a2489d
            const char *src = input + 2;
Packit Service a2489d
            if (mbsrtowcs (NULL, &src, 10, &state) != 4)
Packit Service a2489d
              result |= 8;
Packit Service a2489d
          }
Packit Service a2489d
    }
Packit Service a2489d
  return result;
Packit Service a2489d
}]])],
Packit Service a2489d
          [gl_cv_func_mbsrtowcs_works=yes],
Packit Service a2489d
          [gl_cv_func_mbsrtowcs_works=no],
Packit Service a2489d
          [:])
Packit Service a2489d
      fi
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
# Prerequisites of lib/mbsrtowcs.c.
Packit Service a2489d
AC_DEFUN([gl_PREREQ_MBSRTOWCS], [
Packit Service a2489d
  :
Packit Service a2489d
])