Blame m4/mbrlen.m4

Packit 709fb3
# mbrlen.m4 serial 9  -*- coding: utf-8 -*-
Packit 709fb3
dnl Copyright (C) 2008, 2010-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_MBRLEN],
Packit 709fb3
[
Packit 709fb3
  AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
Packit 709fb3
Packit 709fb3
  AC_REQUIRE([AC_TYPE_MBSTATE_T])
Packit 709fb3
  AC_REQUIRE([gl_FUNC_MBRTOWC])
Packit 709fb3
  AC_CHECK_FUNCS_ONCE([mbrlen])
Packit 709fb3
  if test $ac_cv_func_mbrlen = no; then
Packit 709fb3
    HAVE_MBRLEN=0
Packit 709fb3
    AC_CHECK_DECLS([mbrlen],,, [[
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_mbrlen = yes; then
Packit 709fb3
      dnl On Minix 3.1.8, the system's <wchar.h> declares mbrlen() although
Packit 709fb3
      dnl it does not have the function. Avoid a collision with gnulib's
Packit 709fb3
      dnl replacement.
Packit 709fb3
      REPLACE_MBRLEN=1
Packit 709fb3
    fi
Packit 709fb3
  else
Packit 709fb3
    dnl Most bugs affecting the system's mbrtowc function also affect the
Packit 709fb3
    dnl mbrlen function. So override mbrlen whenever mbrtowc is overridden.
Packit 709fb3
    dnl We could also run the individual tests below; the results would be
Packit 709fb3
    dnl the same.
Packit 709fb3
    if test $REPLACE_MBRTOWC = 1; then
Packit 709fb3
      REPLACE_MBRLEN=1
Packit 709fb3
    fi
Packit 709fb3
  fi
Packit 709fb3
])
Packit 709fb3
Packit 709fb3
dnl Test whether mbrlen puts the state into non-initial state when parsing an
Packit 709fb3
dnl incomplete multibyte character.
Packit 709fb3
dnl Result is gl_cv_func_mbrlen_incomplete_state.
Packit 709fb3
Packit 709fb3
AC_DEFUN([gl_MBRLEN_INCOMPLETE_STATE],
Packit 709fb3
[
Packit 709fb3
  AC_REQUIRE([AC_PROG_CC])
Packit 709fb3
  AC_REQUIRE([gt_LOCALE_JA])
Packit 709fb3
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit 709fb3
  AC_CACHE_CHECK([whether mbrlen handles incomplete characters],
Packit 709fb3
    [gl_cv_func_mbrlen_incomplete_state],
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 AIX and OSF/1.
Packit 709fb3
        aix* | osf*) gl_cv_func_mbrlen_incomplete_state="guessing no" ;;
Packit 709fb3
                     # Guess yes otherwise.
Packit 709fb3
        *)           gl_cv_func_mbrlen_incomplete_state="guessing yes" ;;
Packit 709fb3
      esac
Packit 709fb3
changequote([,])dnl
Packit 709fb3
      if test $LOCALE_JA != 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
  if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
Packit 709fb3
    {
Packit 709fb3
      const char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
Packit 709fb3
      mbstate_t state;
Packit 709fb3
Packit 709fb3
      memset (&state, '\0', sizeof (mbstate_t));
Packit 709fb3
      if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
Packit 709fb3
        if (mbsinit (&state))
Packit 709fb3
          return 1;
Packit 709fb3
    }
Packit 709fb3
  return 0;
Packit 709fb3
}]])],
Packit 709fb3
          [gl_cv_func_mbrlen_incomplete_state=yes],
Packit 709fb3
          [gl_cv_func_mbrlen_incomplete_state=no],
Packit 709fb3
          [])
Packit 709fb3
      fi
Packit 709fb3
    ])
Packit 709fb3
])
Packit 709fb3
Packit 709fb3
dnl Test whether mbrlen, when parsing the end of a multibyte character,
Packit 709fb3
dnl correctly returns the number of bytes that were needed to complete the
Packit 709fb3
dnl character (not the total number of bytes of the multibyte character).
Packit 709fb3
dnl Result is gl_cv_func_mbrlen_retval.
Packit 709fb3
Packit 709fb3
AC_DEFUN([gl_MBRLEN_RETVAL],
Packit 709fb3
[
Packit 709fb3
  AC_REQUIRE([AC_PROG_CC])
Packit 709fb3
  AC_REQUIRE([gt_LOCALE_FR_UTF8])
Packit 709fb3
  AC_REQUIRE([gt_LOCALE_JA])
Packit 709fb3
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit 709fb3
  AC_CACHE_CHECK([whether mbrlen has a correct return value],
Packit 709fb3
    [gl_cv_func_mbrlen_retval],
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 and Solaris.
Packit 709fb3
        hpux* | solaris*) gl_cv_func_mbrlen_retval="guessing no" ;;
Packit 709fb3
                          # Guess yes otherwise.
Packit 709fb3
        *)                gl_cv_func_mbrlen_retval="guessing yes" ;;
Packit 709fb3
      esac
Packit 709fb3
changequote([,])dnl
Packit 709fb3
      if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != 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
  /* This fails on Solaris.  */
Packit 709fb3
  if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
Packit 709fb3
    {
Packit 709fb3
      char input[] = "B\303\274\303\237er"; /* "Büßer" */
Packit 709fb3
      mbstate_t state;
Packit 709fb3
Packit 709fb3
      memset (&state, '\0', sizeof (mbstate_t));
Packit 709fb3
      if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
Packit 709fb3
        {
Packit 709fb3
          input[1] = '\0';
Packit 709fb3
          if (mbrlen (input + 2, 5, &state) != 1)
Packit 709fb3
            result |= 1;
Packit 709fb3
        }
Packit 709fb3
    }
Packit 709fb3
  /* This fails on HP-UX 11.11.  */
Packit 709fb3
  if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
Packit 709fb3
    {
Packit 709fb3
      char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
Packit 709fb3
      mbstate_t state;
Packit 709fb3
Packit 709fb3
      memset (&state, '\0', sizeof (mbstate_t));
Packit 709fb3
      if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
Packit 709fb3
        {
Packit 709fb3
          input[1] = '\0';
Packit 709fb3
          if (mbrlen (input + 2, 5, &state) != 2)
Packit 709fb3
            result |= 2;
Packit 709fb3
        }
Packit 709fb3
    }
Packit 709fb3
  return result;
Packit 709fb3
}]])],
Packit 709fb3
          [gl_cv_func_mbrlen_retval=yes],
Packit 709fb3
          [gl_cv_func_mbrlen_retval=no],
Packit 709fb3
          [])
Packit 709fb3
      fi
Packit 709fb3
    ])
Packit 709fb3
])
Packit 709fb3
Packit 709fb3
dnl Test whether mbrlen, when parsing a NUL character, correctly returns 0.
Packit 709fb3
dnl Result is gl_cv_func_mbrlen_nul_retval.
Packit 709fb3
Packit 709fb3
AC_DEFUN([gl_MBRLEN_NUL_RETVAL],
Packit 709fb3
[
Packit 709fb3
  AC_REQUIRE([AC_PROG_CC])
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 mbrlen returns 0 when parsing a NUL character],
Packit 709fb3
    [gl_cv_func_mbrlen_nul_retval],
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 Solaris 9.
Packit 709fb3
        solaris2.9) gl_cv_func_mbrlen_nul_retval="guessing no" ;;
Packit 709fb3
                    # Guess yes otherwise.
Packit 709fb3
        *)          gl_cv_func_mbrlen_nul_retval="guessing yes" ;;
Packit 709fb3
      esac
Packit 709fb3
changequote([,])dnl
Packit 709fb3
      if 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
  /* This crashes on Solaris 9 inside __mbrtowc_dense_gb18030.  */
Packit 709fb3
  if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
Packit 709fb3
    {
Packit 709fb3
      mbstate_t state;
Packit 709fb3
Packit 709fb3
      memset (&state, '\0', sizeof (mbstate_t));
Packit 709fb3
      if (mbrlen ("", 1, &state) != 0)
Packit 709fb3
        return 1;
Packit 709fb3
    }
Packit 709fb3
  return 0;
Packit 709fb3
}]])],
Packit 709fb3
          [gl_cv_func_mbrlen_nul_retval=yes],
Packit 709fb3
          [gl_cv_func_mbrlen_nul_retval=no],
Packit 709fb3
          [])
Packit 709fb3
      fi
Packit 709fb3
    ])
Packit 709fb3
])
Packit 709fb3
Packit 709fb3
dnl Test whether mbrlen returns the correct value on empty input.
Packit 709fb3
Packit 709fb3
AC_DEFUN([gl_MBRLEN_EMPTY_INPUT],
Packit 709fb3
[
Packit 709fb3
  AC_REQUIRE([AC_PROG_CC])
Packit 709fb3
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit 709fb3
  AC_CACHE_CHECK([whether mbrlen works on empty input],
Packit 709fb3
    [gl_cv_func_mbrlen_empty_input],
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 AIX and glibc systems.
Packit 709fb3
        aix* | *-gnu*)
Packit 709fb3
                    gl_cv_func_mbrlen_empty_input="guessing no" ;;
Packit 709fb3
        *)          gl_cv_func_mbrlen_empty_input="guessing yes" ;;
Packit 709fb3
      esac
Packit 709fb3
changequote([,])dnl
Packit 709fb3
      AC_RUN_IFELSE(
Packit 709fb3
        [AC_LANG_SOURCE([[
Packit 709fb3
           #include <wchar.h>
Packit 709fb3
           static mbstate_t mbs;
Packit 709fb3
           int
Packit 709fb3
           main (void)
Packit 709fb3
           {
Packit 709fb3
             return mbrlen ("", 0, &mbs) != (size_t) -2;
Packit 709fb3
           }]])],
Packit 709fb3
        [gl_cv_func_mbrlen_empty_input=yes],
Packit 709fb3
        [gl_cv_func_mbrlen_empty_input=no],
Packit 709fb3
        [:])
Packit 709fb3
    ])
Packit 709fb3
])
Packit 709fb3
Packit 709fb3
# Prerequisites of lib/mbrlen.c.
Packit 709fb3
AC_DEFUN([gl_PREREQ_MBRLEN], [
Packit 709fb3
  :
Packit 709fb3
])