Blame m4/wcrtomb.m4

Packit Service a2489d
# wcrtomb.m4 serial 12
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_WCRTOMB],
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([wcrtomb])
Packit Service a2489d
  if test $ac_cv_func_wcrtomb = no; then
Packit Service a2489d
    HAVE_WCRTOMB=0
Packit Service a2489d
    AC_CHECK_DECLS([wcrtomb],,, [[
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_wcrtomb = yes; then
Packit Service a2489d
      dnl On Minix 3.1.8, the system's <wchar.h> declares wcrtomb() 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_WCRTOMB=1
Packit Service a2489d
    fi
Packit Service a2489d
  else
Packit Service a2489d
    if test $REPLACE_MBSTATE_T = 1; then
Packit Service a2489d
      REPLACE_WCRTOMB=1
Packit Service a2489d
    else
Packit Service a2489d
      dnl On AIX 4.3, OSF/1 5.1 and Solaris 10, wcrtomb (NULL, 0, NULL) sometimes
Packit Service a2489d
      dnl returns 0 instead of 1.
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 wcrtomb return value is correct],
Packit Service a2489d
        [gl_cv_func_wcrtomb_retval],
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 AIX 4, OSF/1 and Solaris.
Packit Service a2489d
            aix4* | osf* | solaris*) gl_cv_func_wcrtomb_retval="guessing no" ;;
Packit Service a2489d
                                     # Guess yes on native Windows.
Packit Service a2489d
            mingw*)                  gl_cv_func_wcrtomb_retval="guessing yes" ;;
Packit Service a2489d
                                     # Guess yes otherwise.
Packit Service a2489d
            *)                       gl_cv_func_wcrtomb_retval="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
  if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
Packit Service a2489d
    {
Packit Service a2489d
      if (wcrtomb (NULL, 0, NULL) != 1)
Packit Service a2489d
        result |= 1;
Packit Service a2489d
    }
Packit Service a2489d
  if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
Packit Service a2489d
    {
Packit Service a2489d
      if (wcrtomb (NULL, 0, NULL) != 1)
Packit Service a2489d
        result |= 2;
Packit Service a2489d
    }
Packit Service a2489d
  if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
Packit Service a2489d
    {
Packit Service a2489d
      if (wcrtomb (NULL, 0, NULL) != 1)
Packit Service a2489d
        result |= 4;
Packit Service a2489d
    }
Packit Service a2489d
  if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
Packit Service a2489d
    {
Packit Service a2489d
      if (wcrtomb (NULL, 0, NULL) != 1)
Packit Service a2489d
        result |= 8;
Packit Service a2489d
    }
Packit Service a2489d
  return result;
Packit Service a2489d
}]])],
Packit Service a2489d
              [gl_cv_func_wcrtomb_retval=yes],
Packit Service a2489d
              [gl_cv_func_wcrtomb_retval=no],
Packit Service a2489d
              [:])
Packit Service a2489d
          fi
Packit Service a2489d
        ])
Packit Service a2489d
      case "$gl_cv_func_wcrtomb_retval" in
Packit Service a2489d
        *yes) ;;
Packit Service a2489d
        *) REPLACE_WCRTOMB=1 ;;
Packit Service a2489d
      esac
Packit Service a2489d
    fi
Packit Service a2489d
  fi
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
# Prerequisites of lib/wcrtomb.c.
Packit Service a2489d
AC_DEFUN([gl_PREREQ_WCRTOMB], [
Packit Service a2489d
  :
Packit Service a2489d
])