warnings: fix compilation with old autoconf
[gnulib/ericb.git] / m4 / wctob.m4
blob9de49601492367038b99469b4a6156907ebb1719
1 # wctob.m4 serial 11
2 dnl Copyright (C) 2008-2017 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_WCTOB],
9   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
11   AC_CHECK_FUNCS_ONCE([wctob])
12   if test $ac_cv_func_wctob = no; then
13     HAVE_WCTOB=0
14     HAVE_DECL_WCTOB=0
15   else
16     HAVE_WCTOB=1
18     dnl Solaris 9 has the wctob() function but it does not work.
19     dnl Cygwin 1.7.2 has the wctob() function but it clobbers caller-owned
20     dnl registers, see <http://cygwin.com/ml/cygwin/2010-05/msg00015.html>.
21     AC_REQUIRE([AC_PROG_CC])
22     AC_REQUIRE([gt_LOCALE_FR])
23     AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
24     AC_CACHE_CHECK([whether wctob works],
25       [gl_cv_func_wctob_works],
26       [
27         dnl Initial guess, used when cross-compiling or when no suitable locale
28         dnl is present.
29 changequote(,)dnl
30         case "$host_os" in
31             # Guess no on Solaris <= 9 and Cygwin.
32           solaris2.[1-9] | solaris2.[1-9].* | cygwin*)
33             gl_cv_func_wctob_works="guessing no" ;;
34             # Guess no on native Windows.
35           mingw*)
36             gl_cv_func_wctob_works="guessing no" ;;
37             # Guess yes otherwise.
38           *) gl_cv_func_wctob_works="guessing yes" ;;
39         esac
40 changequote([,])dnl
41         case "$host_os" in
42           cygwin*)
43             AC_RUN_IFELSE(
44               [AC_LANG_SOURCE([[
45 #include <locale.h>
46 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
47    <wchar.h>.
48    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
49    included before <wchar.h>.  */
50 #include <stddef.h>
51 #include <stdio.h>
52 #include <time.h>
53 #include <wchar.h>
55 register long global __asm__ ("%ebx");
57 int main ()
59   setlocale (LC_ALL, "en_US.UTF-8");
61   global = 0x12345678;
62   if (wctob (0x00FC) != -1)
63     return 1;
64   if (global != 0x12345678)
65     return 2;
66   return 0;
67 }]])],
68               [:],
69               [gl_cv_func_wctob_works=no],
70               [:])
71             ;;
72         esac
73         if test "$gl_cv_func_wctob_works" != no && test $LOCALE_FR != none; then
74           AC_RUN_IFELSE(
75             [AC_LANG_SOURCE([[
76 #include <locale.h>
77 #include <string.h>
78 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
79    <wchar.h>.
80    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
81    included before <wchar.h>.  */
82 #include <stddef.h>
83 #include <stdio.h>
84 #include <time.h>
85 #include <wchar.h>
86 int main ()
88   if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
89     {
90       wchar_t wc;
92       if (mbtowc (&wc, "\374", 1) == 1)
93         if (wctob (wc) != (unsigned char) '\374')
94           return 1;
95     }
96   return 0;
97 }]])],
98             [gl_cv_func_wctob_works=yes],
99             [gl_cv_func_wctob_works=no],
100             [:])
101         fi
102       ])
103     case "$gl_cv_func_wctob_works" in
104       *yes) ;;
105       *) REPLACE_WCTOB=1 ;;
106     esac
107     if test $REPLACE_WCTOB = 0; then
109       dnl IRIX 6.5 has the wctob() function but does not declare it.
110       AC_CHECK_DECLS([wctob], [], [], [[
111 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
112    <wchar.h>.
113    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be included
114    before <wchar.h>.  */
115 #include <stddef.h>
116 #include <stdio.h>
117 #include <time.h>
118 #include <wchar.h>
120       if test $ac_cv_have_decl_wctob != yes; then
121         HAVE_DECL_WCTOB=0
122       fi
123     fi
124   fi
127 # Prerequisites of lib/wctob.c.
128 AC_DEFUN([gl_PREREQ_WCTOB], [
129   :