| 1 |
# c32rtomb.m4 |
| 2 |
# serial 8 |
| 3 |
dnl Copyright (C) 2020-2024 Free Software Foundation, Inc. |
| 4 |
dnl This file is free software; the Free Software Foundation |
| 5 |
dnl gives unlimited permission to copy and/or distribute it, |
| 6 |
dnl with or without modifications, as long as this notice is preserved. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
AC_DEFUN([gl_FUNC_C32RTOMB], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_UCHAR_H_DEFAULTS]) |
| 12 |
AC_REQUIRE([AC_CANONICAL_HOST]) |
| 13 |
|
| 14 |
AC_REQUIRE([gl_MBRTOC32_SANITYCHECK]) |
| 15 |
AC_REQUIRE([gl_C32RTOMB_SANITYCHECK]) |
| 16 |
|
| 17 |
AC_REQUIRE([gl_CHECK_FUNC_C32RTOMB]) |
| 18 |
if test $gl_cv_func_c32rtomb = no; then |
| 19 |
HAVE_C32RTOMB=0 |
| 20 |
else |
| 21 |
dnl When we override mbrtoc32, redefining the meaning of the char32_t |
| 22 |
dnl values, we need to override c32rtomb as well, for consistency. |
| 23 |
if test $HAVE_WORKING_MBRTOC32 = 0; then |
| 24 |
REPLACE_C32RTOMB=1 |
| 25 |
fi |
| 26 |
AC_CACHE_CHECK([whether c32rtomb return value is correct], |
| 27 |
[gl_cv_func_c32rtomb_retval], |
| 28 |
[ |
| 29 |
dnl Initial guess, used when cross-compiling. |
| 30 |
changequote(,)dnl |
| 31 |
case "$host_os" in |
| 32 |
# Guess no on AIX. |
| 33 |
aix*) gl_cv_func_c32rtomb_retval="guessing no" ;; |
| 34 |
# Guess yes otherwise. |
| 35 |
*) gl_cv_func_c32rtomb_retval="guessing yes" ;; |
| 36 |
esac |
| 37 |
changequote([,])dnl |
| 38 |
AC_RUN_IFELSE( |
| 39 |
[AC_LANG_SOURCE([[ |
| 40 |
#include <stddef.h> |
| 41 |
#ifdef __HAIKU__ |
| 42 |
#include <stdint.h> |
| 43 |
#endif |
| 44 |
#include <uchar.h> |
| 45 |
int main () |
| 46 |
{ |
| 47 |
int result = 0; |
| 48 |
if (c32rtomb (NULL, 0, NULL) != 1) |
| 49 |
result |= 1; |
| 50 |
return result; |
| 51 |
}]])], |
| 52 |
[gl_cv_func_c32rtomb_retval=yes], |
| 53 |
[gl_cv_func_c32rtomb_retval=no], |
| 54 |
[:]) |
| 55 |
]) |
| 56 |
case "$gl_cv_func_c32rtomb_retval" in |
| 57 |
*yes) ;; |
| 58 |
*) AC_DEFINE([C32RTOMB_RETVAL_BUG], [1], |
| 59 |
[Define if the c32rtomb function has an incorrect return value.]) |
| 60 |
REPLACE_C32RTOMB=1 ;; |
| 61 |
esac |
| 62 |
if test $HAVE_WORKING_C32RTOMB = 0; then |
| 63 |
REPLACE_C32RTOMB=1 |
| 64 |
fi |
| 65 |
fi |
| 66 |
]) |
| 67 |
|
| 68 |
AC_DEFUN([gl_CHECK_FUNC_C32RTOMB], |
| 69 |
[ |
| 70 |
dnl Cf. gl_CHECK_FUNCS_ANDROID |
| 71 |
AC_CHECK_DECL([c32rtomb], , , |
| 72 |
[[#ifdef __HAIKU__ |
| 73 |
#include <stdint.h> |
| 74 |
#endif |
| 75 |
#include <uchar.h> |
| 76 |
]]) |
| 77 |
if test $ac_cv_have_decl_c32rtomb = yes; then |
| 78 |
dnl We can't use AC_CHECK_FUNC here, because c32rtomb() is defined as a |
| 79 |
dnl static inline function on Haiku 2020. |
| 80 |
AC_CACHE_CHECK([for c32rtomb], [gl_cv_func_c32rtomb], |
| 81 |
[AC_LINK_IFELSE( |
| 82 |
[AC_LANG_PROGRAM( |
| 83 |
[[#include <stdlib.h> |
| 84 |
#ifdef __HAIKU__ |
| 85 |
#include <stdint.h> |
| 86 |
#endif |
| 87 |
#include <uchar.h> |
| 88 |
]], |
| 89 |
[[char buf[8]; |
| 90 |
return c32rtomb (buf, 0, NULL) == 0; |
| 91 |
]]) |
| 92 |
], |
| 93 |
[gl_cv_func_c32rtomb=yes], |
| 94 |
[gl_cv_func_c32rtomb=no]) |
| 95 |
]) |
| 96 |
else |
| 97 |
gl_cv_func_c32rtomb=no |
| 98 |
fi |
| 99 |
]) |
| 100 |
|
| 101 |
dnl Test whether c32rtomb works not worse than wcrtomb. |
| 102 |
dnl Result is HAVE_WORKING_C32RTOMB. |
| 103 |
|
| 104 |
AC_DEFUN([gl_C32RTOMB_SANITYCHECK], |
| 105 |
[ |
| 106 |
AC_REQUIRE([AC_PROG_CC]) |
| 107 |
AC_REQUIRE([gl_TYPE_CHAR32_T]) |
| 108 |
AC_REQUIRE([gl_CHECK_FUNC_C32RTOMB]) |
| 109 |
AC_REQUIRE([gt_LOCALE_ZH_CN]) |
| 110 |
AC_REQUIRE([AC_CANONICAL_HOST]) |
| 111 |
if test $GNULIBHEADERS_OVERRIDE_CHAR32_T = 1 || test $gl_cv_func_c32rtomb = no; then |
| 112 |
HAVE_WORKING_C32RTOMB=0 |
| 113 |
else |
| 114 |
AC_CACHE_CHECK([whether c32rtomb works as well as wcrtomb], |
| 115 |
[gl_cv_func_c32rtomb_sanitycheck], |
| 116 |
[ |
| 117 |
dnl Initial guess, used when cross-compiling or when no suitable locale |
| 118 |
dnl is present. |
| 119 |
changequote(,)dnl |
| 120 |
case "$host_os" in |
| 121 |
# Guess no on Solaris derivatives. |
| 122 |
solaris*) |
| 123 |
if test -f /etc/release && grep 'Oracle Solaris' /etc/release >/dev/null; then |
| 124 |
gl_cv_func_c32rtomb_sanitycheck="guessing yes" |
| 125 |
else |
| 126 |
gl_cv_func_c32rtomb_sanitycheck="guessing no" |
| 127 |
fi |
| 128 |
;; |
| 129 |
# Guess yes otherwise. |
| 130 |
*) |
| 131 |
gl_cv_func_c32rtomb_sanitycheck="guessing yes" |
| 132 |
;; |
| 133 |
esac |
| 134 |
changequote([,])dnl |
| 135 |
if test $LOCALE_ZH_CN != none; then |
| 136 |
AC_RUN_IFELSE( |
| 137 |
[AC_LANG_SOURCE([[ |
| 138 |
#include <locale.h> |
| 139 |
#include <stdlib.h> |
| 140 |
#include <string.h> |
| 141 |
#include <wchar.h> |
| 142 |
#ifdef __HAIKU__ |
| 143 |
#include <stdint.h> |
| 144 |
#endif |
| 145 |
#include <uchar.h> |
| 146 |
int main () |
| 147 |
{ |
| 148 |
int result = 0; |
| 149 |
/* This fails on Solaris 11 OmniOS: |
| 150 |
c32rtomb returns (size_t)-1. |
| 151 |
wcrtomb returns 4 (correct). */ |
| 152 |
if (strcmp ("$LOCALE_ZH_CN", "none") != 0 |
| 153 |
&& setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL) |
| 154 |
{ |
| 155 |
mbstate_t state; |
| 156 |
wchar_t wc = (wchar_t) 0xBADFACE; |
| 157 |
char buf[16]; |
| 158 |
memset (&state, '\0', sizeof (mbstate_t)); |
| 159 |
if (mbrtowc (&wc, "\201\060\211\070", 4, &state) == 4 |
| 160 |
&& wcrtomb (buf, wc, NULL) == 4 |
| 161 |
&& memcmp (buf, "\201\060\211\070", 4) == 0) |
| 162 |
{ |
| 163 |
char32_t c32 = (wchar_t) 0xBADFACE; |
| 164 |
memset (&state, '\0', sizeof (mbstate_t)); |
| 165 |
if (mbrtoc32 (&c32, "\201\060\211\070", 4, &state) == 4 |
| 166 |
&& c32rtomb (buf, c32, NULL) != 4) |
| 167 |
result |= 1; |
| 168 |
} |
| 169 |
} |
| 170 |
return result; |
| 171 |
}]])], |
| 172 |
[gl_cv_func_c32rtomb_sanitycheck=yes], |
| 173 |
[gl_cv_func_c32rtomb_sanitycheck=no], |
| 174 |
[:]) |
| 175 |
fi |
| 176 |
]) |
| 177 |
case "$gl_cv_func_c32rtomb_sanitycheck" in |
| 178 |
*yes) |
| 179 |
HAVE_WORKING_C32RTOMB=1 |
| 180 |
AC_DEFINE([HAVE_WORKING_C32RTOMB], [1], |
| 181 |
[Define if the c32rtomb function basically works.]) |
| 182 |
;; |
| 183 |
*) HAVE_WORKING_C32RTOMB=0 ;; |
| 184 |
esac |
| 185 |
fi |
| 186 |
AC_SUBST([HAVE_WORKING_C32RTOMB]) |
| 187 |
]) |