autoupdate
[gnulib.git] / m4 / wctob.m4
blobd66c6ff183d06e6653824ddfcf5cfdbe2dc85429
1 # wctob.m4
2 # serial 14
3 dnl Copyright (C) 2008-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.
8 AC_DEFUN([gl_FUNC_WCTOB],
10   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
12   AC_CHECK_FUNCS_ONCE([wctob])
13   if test $ac_cv_func_wctob = no; then
14     HAVE_WCTOB=0
15     HAVE_DECL_WCTOB=0
16   else
17     HAVE_WCTOB=1
19     dnl Solaris 9 has the wctob() function but it does not work.
20     dnl Cygwin 1.7.2 has the wctob() function but it clobbers caller-owned
21     dnl registers, see <https://cygwin.com/ml/cygwin/2010-05/msg00015.html>.
22     AC_REQUIRE([AC_PROG_CC])
23     AC_REQUIRE([gt_LOCALE_FR])
24     AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
25     AC_CACHE_CHECK([whether wctob works],
26       [gl_cv_func_wctob_works],
27       [
28         dnl Initial guess, used when cross-compiling or when no suitable locale
29         dnl is present.
30 changequote(,)dnl
31         case "$host_os" in
32             # Guess no on Solaris <= 9 and Cygwin.
33           solaris2.[1-9] | solaris2.[1-9].* | cygwin*)
34             gl_cv_func_wctob_works="guessing no" ;;
35             # Guess no on native Windows.
36           mingw* | windows*)
37             gl_cv_func_wctob_works="guessing no" ;;
38             # Guess yes otherwise.
39           *) gl_cv_func_wctob_works="guessing yes" ;;
40         esac
41 changequote([,])dnl
42         case "$host_os" in
43           cygwin*)
44             AC_RUN_IFELSE(
45               [AC_LANG_SOURCE([[
46 #include <locale.h>
47 #include <wchar.h>
49 register long global __asm__ ("%ebx");
51 int main ()
53   setlocale (LC_ALL, "en_US.UTF-8");
55   global = 0x12345678;
56   if (wctob (0x00FC) != -1)
57     return 1;
58   if (global != 0x12345678)
59     return 2;
60   return 0;
61 }]])],
62               [:],
63               [gl_cv_func_wctob_works=no],
64               [:])
65             ;;
66         esac
67         if test "$gl_cv_func_wctob_works" != no && test $LOCALE_FR != none; then
68           AC_RUN_IFELSE(
69             [AC_LANG_SOURCE([[
70 #include <locale.h>
71 #include <stdlib.h>
72 #include <wchar.h>
73 int main ()
75   if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
76     {
77       wchar_t wc;
79       if (mbtowc (&wc, "\374", 1) == 1)
80         if (wctob (wc) != (unsigned char) '\374')
81           return 1;
82     }
83   return 0;
84 }]])],
85             [gl_cv_func_wctob_works=yes],
86             [gl_cv_func_wctob_works=no],
87             [:])
88         fi
89       ])
90     case "$gl_cv_func_wctob_works" in
91       *yes) ;;
92       *) REPLACE_WCTOB=1 ;;
93     esac
94     if test $REPLACE_WCTOB = 0; then
96       dnl IRIX 6.5 has the wctob() function but does not declare it.
97       AC_CHECK_DECLS([wctob], [], [], [[
98         #include <wchar.h>
99       ]])
100       if test $ac_cv_have_decl_wctob != yes; then
101         HAVE_DECL_WCTOB=0
102       fi
103     fi
104   fi
107 # Prerequisites of lib/wctob.c.
108 AC_DEFUN([gl_PREREQ_WCTOB], [
109   :