maint: update copyright
[gnulib.git] / m4 / wctob.m4
1 # wctob.m4 serial 10
2 dnl Copyright (C) 2008-2014 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.
6
7 AC_DEFUN([gl_FUNC_WCTOB],
8 [
9   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
10
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
17
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 yes otherwise.
35           *) gl_cv_func_wctob_works="guessing yes" ;;
36         esac
37 changequote([,])dnl
38         case "$host_os" in
39           cygwin*)
40             AC_RUN_IFELSE(
41               [AC_LANG_SOURCE([[
42 #include <locale.h>
43 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
44    <wchar.h>.
45    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
46    included before <wchar.h>.  */
47 #include <stddef.h>
48 #include <stdio.h>
49 #include <time.h>
50 #include <wchar.h>
51
52 register long global __asm__ ("%ebx");
53
54 int main ()
55 {
56   setlocale (LC_ALL, "en_US.UTF-8");
57
58   global = 0x12345678;
59   if (wctob (0x00FC) != -1)
60     return 1;
61   if (global != 0x12345678)
62     return 2;
63   return 0;
64 }]])],
65               [:],
66               [gl_cv_func_wctob_works=no],
67               [:])
68             ;;
69         esac
70         if test "$gl_cv_func_wctob_works" != no && test $LOCALE_FR != none; then
71           AC_RUN_IFELSE(
72             [AC_LANG_SOURCE([[
73 #include <locale.h>
74 #include <string.h>
75 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
76    <wchar.h>.
77    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
78    included before <wchar.h>.  */
79 #include <stddef.h>
80 #include <stdio.h>
81 #include <time.h>
82 #include <wchar.h>
83 int main ()
84 {
85   if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
86     {
87       wchar_t wc;
88
89       if (mbtowc (&wc, "\374", 1) == 1)
90         if (wctob (wc) != (unsigned char) '\374')
91           return 1;
92     }
93   return 0;
94 }]])],
95             [gl_cv_func_wctob_works=yes],
96             [gl_cv_func_wctob_works=no],
97             [:])
98         fi
99       ])
100     case "$gl_cv_func_wctob_works" in
101       *yes) ;;
102       *) REPLACE_WCTOB=1 ;;
103     esac
104     if test $REPLACE_WCTOB = 0; then
105
106       dnl IRIX 6.5 has the wctob() function but does not declare it.
107       AC_CHECK_DECLS([wctob], [], [], [[
108 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
109    <wchar.h>.
110    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be included
111    before <wchar.h>.  */
112 #include <stddef.h>
113 #include <stdio.h>
114 #include <time.h>
115 #include <wchar.h>
116 ]])
117       if test $ac_cv_have_decl_wctob != yes; then
118         HAVE_DECL_WCTOB=0
119       fi
120     fi
121   fi
122 ])
123
124 # Prerequisites of lib/wctob.c.
125 AC_DEFUN([gl_PREREQ_WCTOB], [
126   :
127 ])