Fix portability problem with Tru64 and BSD/OS.
[gnulib.git] / m4 / mbswidth.m4
1 #serial 10
2
3 dnl autoconf tests required for use of mbswidth.c
4 dnl From Bruno Haible.
5
6 AC_DEFUN([gl_MBSWIDTH],
7 [
8   AC_CHECK_HEADERS_ONCE(wchar.h wctype.h)
9   AC_CHECK_FUNCS_ONCE(isascii iswprint mbsinit)
10   AC_CHECK_FUNCS(iswcntrl wcwidth)
11   jm_FUNC_MBRTOWC
12
13   AC_CACHE_CHECK([whether wcwidth is declared], ac_cv_have_decl_wcwidth,
14     [AC_TRY_COMPILE([
15 /* AIX 3.2.5 declares wcwidth in <string.h>. */
16 #if HAVE_STRING_H
17 # include <string.h>
18 #endif
19 #if HAVE_WCHAR_H
20 # include <wchar.h>
21 #endif
22 ], [
23 #ifndef wcwidth
24   char *p = (char *) wcwidth;
25 #endif
26 ], ac_cv_have_decl_wcwidth=yes, ac_cv_have_decl_wcwidth=no)])
27   if test $ac_cv_have_decl_wcwidth = yes; then
28     ac_val=1
29   else
30     ac_val=0
31   fi
32   AC_DEFINE_UNQUOTED(HAVE_DECL_WCWIDTH, $ac_val,
33     [Define to 1 if you have the declaration of wcwidth(), and to 0 otherwise.])
34
35   dnl UnixWare 7.1.1 <wchar.h> has a declaration of a function mbswidth()
36   dnl that clashes with ours.
37   AC_CACHE_CHECK([whether mbswidth is declared in <wchar.h>],
38     ac_cv_have_decl_mbswidth,
39     [AC_TRY_COMPILE([
40 #if HAVE_WCHAR_H
41 # include <wchar.h>
42 #endif
43 ], [
44   char *p = (char *) mbswidth;
45 ], ac_cv_have_decl_mbswidth=yes, ac_cv_have_decl_mbswidth=no)])
46   if test $ac_cv_have_decl_mbswidth = yes; then
47     ac_val=1
48   else
49     ac_val=0
50   fi
51   AC_DEFINE_UNQUOTED(HAVE_DECL_MBSWIDTH_IN_WCHAR_H, $ac_val,
52     [Define to 1 if you have a declaration of mbswidth() in <wchar.h>, and to 0 otherwise.])
53
54   AC_TYPE_MBSTATE_T
55 ])