Also define mbstate_t, if necessary.
[gnulib.git] / m4 / mbstate_t.m4
1 # serial 4
2
3 # From Paul Eggert.
4
5 # Some versions of BeOS define mbstate_t to be an incomplete type,
6 # so you can't declare an object of that type.
7 # Check for this incompatibility with Standard C.
8
9 # Include stdlib.h first, because otherwise this test would fail on Linux
10 # (at least glibc-2.1.3) because the `_XOPEN_SOURCE 500' definition elicits
11 # a syntax error in wchar.h due to the use of undefined __int32_t.
12
13 AC_DEFUN(AC_MBSTATE_T_OBJECT,
14   [
15    # Check for the mbstate_t type.
16    ac_mbs_tmp=$ac_includes_default
17    ac_includes_default="
18 $ac_includes_default
19 #if HAVE_WCHAR_H
20 # include <wchar.h>
21 #endif
22 "
23    AC_CHECK_TYPE(mbstate_t, int)
24    # Restore the default value.
25    ac_includes_default=$ac_mbs_tmp
26
27    AC_CACHE_CHECK([for mbstate_t object type], ac_cv_type_mbstate_t_object,
28     [AC_TRY_COMPILE([
29 #if HAVE_STDLIB_H
30 # include <stdlib.h>
31 #endif
32 #include <wchar.h>],
33       [mbstate_t x; return sizeof x;],
34       ac_cv_type_mbstate_t_object=yes,
35       ac_cv_type_mbstate_t_object=no)])
36    if test $ac_cv_type_mbstate_t_object = yes; then
37      AC_DEFINE(HAVE_MBSTATE_T_OBJECT, 1,
38                [Define if mbstate_t is an object type.])
39    fi])