fchmod-tests, fchmodat tests, lchmod tests: Add more tests.
[gnulib.git] / m4 / wcsnrtombs.m4
blob39ee11804542e5141e9471a456fd90fa19c06e01
1 # wcsnrtombs.m4 serial 7
2 dnl Copyright (C) 2008-2021 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 #include <wchar.h>
64 int main ()
66   /* This fails on Solaris 11.4.  */
67   if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
68     {
69       /* Locale encoding is ISO-8859-1 or ISO-8859-15.  */
70       const char original[] = "B\374\337er"; /* "Büßer" */
71       wchar_t input[10];
72       size_t ret;
73       const wchar_t *src;
75       #define BUFSIZE 20
76       char buf[BUFSIZE];
77       memset (buf, '_', BUFSIZE);
79       ret = mbstowcs (input, original, 10);
80       if (!(ret == 5))
81         return 1;
83       src = input;
84       ret = wcsnrtombs (buf, &src, 6, 2, NULL);
85       if (!(ret == 2))
86         return 2;
87       if (!(src == input + 2))
88         return 3;
89       if (!(memcmp (buf, original, ret) == 0))
90         return 4;
91     }
92   return 0;
93 }]])],
94           [gl_cv_func_wcsnrtombs_works_in_traditional_locale=yes],
95           [gl_cv_func_wcsnrtombs_works_in_traditional_locale=no],
96           [:])
97       fi
98     ])