]> git.cworth.org Git - tar/blob - m4/btowc.m4
2c75c8fb02a6e8794a140f44f4ce49d86028e4df
[tar] / m4 / btowc.m4
1 # btowc.m4 serial 5
2 dnl Copyright (C) 2008-2010 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_BTOWC],
8 [
9   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
10
11   dnl Check whether <wchar.h> is usable at all, first. Otherwise the test
12   dnl program below may lead to an endless loop. See
13   dnl <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>.
14   AC_REQUIRE([gl_WCHAR_H_INLINE_OK])
15
16   AC_CHECK_FUNCS_ONCE([btowc])
17   if test $ac_cv_func_btowc = no; then
18     HAVE_BTOWC=0
19   else
20
21     dnl IRIX 6.5 btowc(EOF) is 0xFF, not WEOF.
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 btowc(EOF) is correct],
26       [gl_cv_func_btowc_eof],
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 IRIX.
33           irix*) gl_cv_func_btowc_eof="guessing no" ;;
34                  # Guess yes otherwise.
35           *)     gl_cv_func_btowc_eof="guessing yes" ;;
36         esac
37 changequote([,])dnl
38         if test $LOCALE_FR != none; then
39           AC_TRY_RUN([
40 #include <locale.h>
41 #include <stdio.h>
42 #include <string.h>
43 #include <wchar.h>
44 int main ()
45 {
46   if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
47     {
48       if (btowc (EOF) != WEOF)
49         return 1;
50     }
51   return 0;
52 }],
53             [gl_cv_func_btowc_eof=yes],
54             [gl_cv_func_btowc_eof=no],
55             [:])
56         fi
57       ])
58     case "$gl_cv_func_btowc_eof" in
59       *yes) ;;
60       *) REPLACE_BTOWC=1 ;;
61     esac
62   fi
63   if test $HAVE_BTOWC = 0 || test $REPLACE_BTOWC = 1; then
64     gl_REPLACE_WCHAR_H
65     AC_LIBOBJ([btowc])
66     gl_PREREQ_BTOWC
67   fi
68 ])
69
70 # Prerequisites of lib/btowc.c.
71 AC_DEFUN([gl_PREREQ_BTOWC], [
72   :
73 ])