Import upstream version 1.26
[debian/tar] / m4 / wcrtomb.m4
1 # wcrtomb.m4 serial 8
2 dnl Copyright (C) 2008-2011 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_WCRTOMB],
8 [
9   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
10
11   AC_REQUIRE([AC_TYPE_MBSTATE_T])
12   gl_MBSTATE_T_BROKEN
13
14   AC_CHECK_FUNCS_ONCE([wcrtomb])
15   if test $ac_cv_func_wcrtomb = no; then
16     HAVE_WCRTOMB=0
17   else
18     if test $REPLACE_MBSTATE_T = 1; then
19       REPLACE_WCRTOMB=1
20     else
21       dnl On AIX 4.3, OSF/1 5.1 and Solaris 10, wcrtomb (NULL, 0, NULL) sometimes
22       dnl returns 0 instead of 1.
23       AC_REQUIRE([AC_PROG_CC])
24       AC_REQUIRE([gt_LOCALE_FR])
25       AC_REQUIRE([gt_LOCALE_FR_UTF8])
26       AC_REQUIRE([gt_LOCALE_JA])
27       AC_REQUIRE([gt_LOCALE_ZH_CN])
28       AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
29       AC_CACHE_CHECK([whether wcrtomb return value is correct],
30         [gl_cv_func_wcrtomb_retval],
31         [
32           dnl Initial guess, used when cross-compiling or when no suitable locale
33           dnl is present.
34 changequote(,)dnl
35           case "$host_os" in
36                                      # Guess no on AIX 4, OSF/1 and Solaris.
37             aix4* | osf* | solaris*) gl_cv_func_wcrtomb_retval="guessing no" ;;
38                                      # Guess yes otherwise.
39             *)                       gl_cv_func_wcrtomb_retval="guessing yes" ;;
40           esac
41 changequote([,])dnl
42           if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
43             AC_RUN_IFELSE(
44               [AC_LANG_SOURCE([[
45 #include <locale.h>
46 #include <string.h>
47 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
48    <wchar.h>.
49    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
50    included before <wchar.h>.  */
51 #include <stddef.h>
52 #include <stdio.h>
53 #include <time.h>
54 #include <wchar.h>
55 int main ()
56 {
57   int result = 0;
58   if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
59     {
60       if (wcrtomb (NULL, 0, NULL) != 1)
61         result |= 1;
62     }
63   if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
64     {
65       if (wcrtomb (NULL, 0, NULL) != 1)
66         result |= 2;
67     }
68   if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
69     {
70       if (wcrtomb (NULL, 0, NULL) != 1)
71         result |= 4;
72     }
73   if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
74     {
75       if (wcrtomb (NULL, 0, NULL) != 1)
76         result |= 8;
77     }
78   return result;
79 }]])],
80               [gl_cv_func_wcrtomb_retval=yes],
81               [gl_cv_func_wcrtomb_retval=no],
82               [:])
83           fi
84         ])
85       case "$gl_cv_func_wcrtomb_retval" in
86         *yes) ;;
87         *) REPLACE_WCRTOMB=1 ;;
88       esac
89     fi
90   fi
91   if test $HAVE_WCRTOMB = 0 || test $REPLACE_WCRTOMB = 1; then
92     gl_REPLACE_WCHAR_H
93     AC_LIBOBJ([wcrtomb])
94     gl_PREREQ_WCRTOMB
95   fi
96 ])
97
98 # Prerequisites of lib/wcrtomb.c.
99 AC_DEFUN([gl_PREREQ_WCRTOMB], [
100   :
101 ])