c32tob: prefer https: URLs
[gnulib.git] / m4 / wcsnrtombs.m4
blob1acb153c8b70efccb74ad7f5ad454fd11b9471f0
1 # wcsnrtombs.m4 serial 6
2 dnl Copyright (C) 2008-2020 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_WCSNRTOMBS],
9   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
11   AC_REQUIRE([AC_TYPE_MBSTATE_T])
12   gl_MBSTATE_T_BROKEN
14   AC_CHECK_FUNCS_ONCE([wcsnrtombs])
15   if test $ac_cv_func_wcsnrtombs = no; then
16     HAVE_WCSNRTOMBS=0
17   else
18     if test $REPLACE_MBSTATE_T = 1; then
19       REPLACE_WCSNRTOMBS=1
20     else
21       gl_WCSNRTOMBS_WORKS_IN_TRADITIONAL_LOCALE
22       case "$gl_cv_func_wcsnrtombs_works_in_traditional_locale" in
23         *yes) ;;
24         *) REPLACE_WCSNRTOMBS=1 ;;
25       esac
27     fi
28   fi
31 # Prerequisites of lib/wcsnrtombs.c.
32 AC_DEFUN([gl_PREREQ_WCSNRTOMBS], [
33   :
36 dnl Test whether wcsnrtombs works in an ISO-8859-1 locale.
37 dnl Result is gl_cv_func_wcsnrtombs_works_in_traditional_locale.
39 AC_DEFUN([gl_WCSNRTOMBS_WORKS_IN_TRADITIONAL_LOCALE],
41   AC_REQUIRE([AC_PROG_CC])
42   AC_REQUIRE([gt_LOCALE_FR])
43   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
44   AC_CACHE_CHECK([whether wcsnrtombs works in a traditional locale],
45     [gl_cv_func_wcsnrtombs_works_in_traditional_locale],
46     [
47       dnl Initial guess, used when cross-compiling or when no suitable locale
48       dnl is present.
49 changequote(,)dnl
50       case "$host_os" in
51                   # Guess no on Solaris.
52         solaris*) gl_cv_func_wcsnrtombs_works_in_traditional_locale="guessing no" ;;
53                   # Guess yes otherwise.
54         *)        gl_cv_func_wcsnrtombs_works_in_traditional_locale="guessing yes" ;;
55       esac
56 changequote([,])dnl
57       if test $LOCALE_FR != none; then
58         AC_RUN_IFELSE(
59           [AC_LANG_SOURCE([[
60 #include <locale.h>
61 #include <stdlib.h>
62 #include <string.h>
63 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
64    <wchar.h>.
65    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
66    included before <wchar.h>.  */
67 #include <stddef.h>
68 #include <stdio.h>
69 #include <time.h>
70 #include <wchar.h>
71 int main ()
73   /* This fails on Solaris 11.4.  */
74   if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
75     {
76       /* Locale encoding is ISO-8859-1 or ISO-8859-15.  */
77       const char original[] = "B\374\337er"; /* "Büßer" */
78       wchar_t input[10];
79       size_t ret;
80       const wchar_t *src;
82       #define BUFSIZE 20
83       char buf[BUFSIZE];
84       memset (buf, '_', BUFSIZE);
86       ret = mbstowcs (input, original, 10);
87       if (!(ret == 5))
88         return 1;
90       src = input;
91       ret = wcsnrtombs (buf, &src, 6, 2, NULL);
92       if (!(ret == 2))
93         return 2;
94       if (!(src == input + 2))
95         return 3;
96       if (!(memcmp (buf, original, ret) == 0))
97         return 4;
98     }
99   return 0;
100 }]])],
101           [gl_cv_func_wcsnrtombs_works_in_traditional_locale=yes],
102           [gl_cv_func_wcsnrtombs_works_in_traditional_locale=no],
103           [:])
104       fi
105     ])