Add script for determining the set of symbols to export from a library.
[gnulib.git] / m4 / mbsnrtowcs.m4
blobb884f2fd845be9d24f59b5e9a85d889974eeb43e
1 # mbsnrtowcs.m4 serial 5
2 dnl Copyright (C) 2008, 2010-2019 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.
7 AC_DEFUN([gl_FUNC_MBSNRTOWCS],
9   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
11   dnl Persuade glibc <wchar.h> to declare mbsnrtowcs().
12   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
14   AC_REQUIRE([AC_TYPE_MBSTATE_T])
15   gl_MBSTATE_T_BROKEN
17   AC_CHECK_FUNCS_ONCE([mbsnrtowcs])
18   if test $ac_cv_func_mbsnrtowcs = no; then
19     HAVE_MBSNRTOWCS=0
20   else
21     if test $REPLACE_MBSTATE_T = 1; then
22       REPLACE_MBSNRTOWCS=1
23     else
24       gl_MBSNRTOWCS_WORKS_IN_TRADITIONAL_LOCALE
25       case "$gl_cv_func_mbsnrtowcs_works_in_traditional_locale" in
26         *yes) ;;
27         *) REPLACE_MBSNRTOWCS=1 ;;
28       esac
29     fi
30   fi
33 # Prerequisites of lib/mbsnrtowcs.c.
34 AC_DEFUN([gl_PREREQ_MBSNRTOWCS], [
35   :
38 dnl Test whether mbsnrtowcs works in an ISO-8859-1 locale.
39 dnl Result is gl_cv_func_mbsnrtowcs_works_in_traditional_locale.
41 AC_DEFUN([gl_MBSNRTOWCS_WORKS_IN_TRADITIONAL_LOCALE],
43   AC_REQUIRE([AC_PROG_CC])
44   AC_REQUIRE([gt_LOCALE_FR])
45   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
46   AC_CACHE_CHECK([whether mbsnrtowcs works in a traditional locale],
47     [gl_cv_func_mbsnrtowcs_works_in_traditional_locale],
48     [
49       dnl Initial guess, used when cross-compiling or when no suitable locale
50       dnl is present.
51 changequote(,)dnl
52       case "$host_os" in
53                   # Guess no on Solaris.
54         solaris*) gl_cv_func_mbsnrtowcs_works_in_traditional_locale="guessing no" ;;
55                   # Guess yes otherwise.
56         *)        gl_cv_func_mbsnrtowcs_works_in_traditional_locale="guessing yes" ;;
57       esac
58 changequote([,])dnl
59       if test $LOCALE_FR != none; then
60         AC_RUN_IFELSE(
61           [AC_LANG_SOURCE([[
62 #include <locale.h>
63 #include <stdlib.h>
64 #include <string.h>
65 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
66    <wchar.h>.
67    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
68    included before <wchar.h>.  */
69 #include <stddef.h>
70 #include <stdio.h>
71 #include <time.h>
72 #include <wchar.h>
73 int main ()
75   /* This fails on Solaris 11.4:
76      mbsnrtowcs stores a wrong wide character: 0xDF instead of btowc (0xDF).  */
77   if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
78     {
79       /* Locale encoding is ISO-8859-1 or ISO-8859-15.  */
80       char input[] = "B\374\337er"; /* "Büßer" */
81       mbstate_t state;
82       mbstate_t temp_state;
83       wchar_t wc;
84       size_t ret;
85       const char *src;
87       #define BUFSIZE 10
88       wchar_t buf[BUFSIZE];
89       {
90         size_t i;
91         for (i = 0; i < BUFSIZE; i++)
92           buf[i] = (wchar_t) 0xBADFACE;
93       }
95       memset (&state, '\0', sizeof (mbstate_t));
97       wc = (wchar_t) 0xBADFACE;
98       ret = mbrtowc (&wc, input, 1, &state);
99       if (!(ret == 1 && wc == 'B' && mbsinit (&state)))
100         return 1;
101       input[0] = '\0';
103       wc = (wchar_t) 0xBADFACE;
104       ret = mbrtowc (&wc, input + 1, 1, &state);
105       if (!(ret == 1 && wctob (wc) == (unsigned char) '\374' && mbsinit (&state)))
106         return 2;
107       input[1] = '\0';
109       src = input + 2;
110       temp_state = state;
111       ret = mbsnrtowcs (NULL, &src, 4, 1, &temp_state);
112       if (!(ret == 3 && src == input + 2 && mbsinit (&state)))
113         return 3;
115       src = input + 2;
116       ret = mbsnrtowcs (buf, &src, 4, 1, &state);
117       if (!(ret == 1))
118         return 4;
119       if (!(src == input + 3))
120         return 5;
121       if (!(buf[0] == btowc ((unsigned char) '\337')))
122         return 6;
123     }
124   return 0;
125 }]])],
126           [gl_cv_func_mbsnrtowcs_works_in_traditional_locale=yes],
127           [gl_cv_func_mbsnrtowcs_works_in_traditional_locale=no],
128           [:])
129       fi
130     ])