immutable: Add tests.
[gnulib.git] / m4 / c32rtomb.m4
blob391d5ac1bca8ae211c7aed78e5ad2d3f8e283e9e
1 # c32rtomb.m4 serial 3
2 dnl Copyright (C) 2020-2021 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_C32RTOMB],
9   AC_REQUIRE([gl_UCHAR_H_DEFAULTS])
11   AC_REQUIRE([gl_MBRTOC32_SANITYCHECK])
13   dnl We can't use AC_CHECK_FUNC here, because c32rtomb() is defined as a
14   dnl static inline function on Haiku 2020.
15   AC_CACHE_CHECK([for c32rtomb], [gl_cv_func_c32rtomb],
16     [AC_LINK_IFELSE(
17        [AC_LANG_PROGRAM(
18           [[#include <stdlib.h>
19             #include <uchar.h>
20           ]],
21           [[char buf[8];
22             return c32rtomb (buf, 0, NULL) == 0;
23           ]])
24        ],
25        [gl_cv_func_c32rtomb=yes],
26        [gl_cv_func_c32rtomb=no])
27     ])
28   if test $gl_cv_func_c32rtomb = no; then
29     HAVE_C32RTOMB=0
30   else
31     dnl When we override mbrtoc32, redefining the meaning of the char32_t
32     dnl values, we need to override c32rtomb as well, for consistency.
33     if test $HAVE_WORKING_MBRTOC32 = 0; then
34       REPLACE_C32RTOMB=1
35     fi
36     AC_CACHE_CHECK([whether c32rtomb return value is correct],
37       [gl_cv_func_c32rtomb_retval],
38       [
39         dnl Initial guess, used when cross-compiling.
40 changequote(,)dnl
41         case "$host_os" in
42           # Guess no on AIX.
43           aix*) gl_cv_func_c32rtomb_retval="guessing no" ;;
44           # Guess yes otherwise.
45           *)    gl_cv_func_c32rtomb_retval="guessing yes" ;;
46         esac
47 changequote([,])dnl
48         AC_RUN_IFELSE(
49           [AC_LANG_SOURCE([[
50 #include <uchar.h>
51 int main ()
53   int result = 0;
54   if (c32rtomb (NULL, 0, NULL) != 1)
55     result |= 1;
56   return result;
57 }]])],
58           [gl_cv_func_c32rtomb_retval=yes],
59           [gl_cv_func_c32rtomb_retval=no],
60           [:])
61       ])
62     case "$gl_cv_func_c32rtomb_retval" in
63       *yes) ;;
64       *) AC_DEFINE([C32RTOMB_RETVAL_BUG], [1],
65            [Define if the c32rtomb function has an incorrect return value.])
66          REPLACE_C32RTOMB=1 ;;
67     esac
68   fi