Blame m4/wcrtomb.m4

Packit 8f70b4
# wcrtomb.m4 serial 12
Packit 8f70b4
dnl Copyright (C) 2008-2018 Free Software Foundation, Inc.
Packit 8f70b4
dnl This file is free software; the Free Software Foundation
Packit 8f70b4
dnl gives unlimited permission to copy and/or distribute it,
Packit 8f70b4
dnl with or without modifications, as long as this notice is preserved.
Packit 8f70b4
Packit 8f70b4
AC_DEFUN([gl_FUNC_WCRTOMB],
Packit 8f70b4
[
Packit 8f70b4
  AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
Packit 8f70b4
Packit 8f70b4
  AC_REQUIRE([AC_TYPE_MBSTATE_T])
Packit 8f70b4
  gl_MBSTATE_T_BROKEN
Packit 8f70b4
Packit 8f70b4
  AC_CHECK_FUNCS_ONCE([wcrtomb])
Packit 8f70b4
  if test $ac_cv_func_wcrtomb = no; then
Packit 8f70b4
    HAVE_WCRTOMB=0
Packit 8f70b4
    AC_CHECK_DECLS([wcrtomb],,, [[
Packit 8f70b4
/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
Packit 8f70b4
   <wchar.h>.
Packit 8f70b4
   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
Packit 8f70b4
   included before <wchar.h>.  */
Packit 8f70b4
#include <stddef.h>
Packit 8f70b4
#include <stdio.h>
Packit 8f70b4
#include <time.h>
Packit 8f70b4
#include <wchar.h>
Packit 8f70b4
]])
Packit 8f70b4
    if test $ac_cv_have_decl_wcrtomb = yes; then
Packit 8f70b4
      dnl On Minix 3.1.8, the system's <wchar.h> declares wcrtomb() although
Packit 8f70b4
      dnl it does not have the function. Avoid a collision with gnulib's
Packit 8f70b4
      dnl replacement.
Packit 8f70b4
      REPLACE_WCRTOMB=1
Packit 8f70b4
    fi
Packit 8f70b4
  else
Packit 8f70b4
    if test $REPLACE_MBSTATE_T = 1; then
Packit 8f70b4
      REPLACE_WCRTOMB=1
Packit 8f70b4
    else
Packit 8f70b4
      dnl On AIX 4.3, OSF/1 5.1 and Solaris 10, wcrtomb (NULL, 0, NULL) sometimes
Packit 8f70b4
      dnl returns 0 instead of 1.
Packit 8f70b4
      AC_REQUIRE([AC_PROG_CC])
Packit 8f70b4
      AC_REQUIRE([gt_LOCALE_FR])
Packit 8f70b4
      AC_REQUIRE([gt_LOCALE_FR_UTF8])
Packit 8f70b4
      AC_REQUIRE([gt_LOCALE_JA])
Packit 8f70b4
      AC_REQUIRE([gt_LOCALE_ZH_CN])
Packit 8f70b4
      AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit 8f70b4
      AC_CACHE_CHECK([whether wcrtomb return value is correct],
Packit 8f70b4
        [gl_cv_func_wcrtomb_retval],
Packit 8f70b4
        [
Packit 8f70b4
          dnl Initial guess, used when cross-compiling or when no suitable locale
Packit 8f70b4
          dnl is present.
Packit 8f70b4
changequote(,)dnl
Packit 8f70b4
          case "$host_os" in
Packit 8f70b4
                                     # Guess no on AIX 4, OSF/1 and Solaris.
Packit 8f70b4
            aix4* | osf* | solaris*) gl_cv_func_wcrtomb_retval="guessing no" ;;
Packit 8f70b4
                                     # Guess yes on native Windows.
Packit 8f70b4
            mingw*)                  gl_cv_func_wcrtomb_retval="guessing yes" ;;
Packit 8f70b4
                                     # Guess yes otherwise.
Packit 8f70b4
            *)                       gl_cv_func_wcrtomb_retval="guessing yes" ;;
Packit 8f70b4
          esac
Packit 8f70b4
changequote([,])dnl
Packit 8f70b4
          if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
Packit 8f70b4
            AC_RUN_IFELSE(
Packit 8f70b4
              [AC_LANG_SOURCE([[
Packit 8f70b4
#include <locale.h>
Packit 8f70b4
#include <string.h>
Packit 8f70b4
/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
Packit 8f70b4
   <wchar.h>.
Packit 8f70b4
   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
Packit 8f70b4
   included before <wchar.h>.  */
Packit 8f70b4
#include <stddef.h>
Packit 8f70b4
#include <stdio.h>
Packit 8f70b4
#include <time.h>
Packit 8f70b4
#include <wchar.h>
Packit 8f70b4
int main ()
Packit 8f70b4
{
Packit 8f70b4
  int result = 0;
Packit 8f70b4
  if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
Packit 8f70b4
    {
Packit 8f70b4
      if (wcrtomb (NULL, 0, NULL) != 1)
Packit 8f70b4
        result |= 1;
Packit 8f70b4
    }
Packit 8f70b4
  if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
Packit 8f70b4
    {
Packit 8f70b4
      if (wcrtomb (NULL, 0, NULL) != 1)
Packit 8f70b4
        result |= 2;
Packit 8f70b4
    }
Packit 8f70b4
  if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
Packit 8f70b4
    {
Packit 8f70b4
      if (wcrtomb (NULL, 0, NULL) != 1)
Packit 8f70b4
        result |= 4;
Packit 8f70b4
    }
Packit 8f70b4
  if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
Packit 8f70b4
    {
Packit 8f70b4
      if (wcrtomb (NULL, 0, NULL) != 1)
Packit 8f70b4
        result |= 8;
Packit 8f70b4
    }
Packit 8f70b4
  return result;
Packit 8f70b4
}]])],
Packit 8f70b4
              [gl_cv_func_wcrtomb_retval=yes],
Packit 8f70b4
              [gl_cv_func_wcrtomb_retval=no],
Packit 8f70b4
              [:])
Packit 8f70b4
          fi
Packit 8f70b4
        ])
Packit 8f70b4
      case "$gl_cv_func_wcrtomb_retval" in
Packit 8f70b4
        *yes) ;;
Packit 8f70b4
        *) REPLACE_WCRTOMB=1 ;;
Packit 8f70b4
      esac
Packit 8f70b4
    fi
Packit 8f70b4
  fi
Packit 8f70b4
])
Packit 8f70b4
Packit 8f70b4
# Prerequisites of lib/wcrtomb.c.
Packit 8f70b4
AC_DEFUN([gl_PREREQ_WCRTOMB], [
Packit 8f70b4
  :
Packit 8f70b4
])