Blame m4/mbsrtowcs.m4

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