git-merge-changelog: Simplify installation instructions.
[gnulib.git] / m4 / wmemcmp.m4
blob89f6ebdc69a8cdc7c5907ae550957b92c9cae747
1 # wmemcmp.m4
2 # serial 6
3 dnl Copyright (C) 2011-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 AC_DEFUN([gl_FUNC_WMEMCMP],
10   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
11   AC_REQUIRE([AC_CANONICAL_HOST])
12   dnl We cannot use AC_CHECK_FUNCS here, because the MSVC 9 header files
13   dnl provide this function as an inline function definition.
14   AC_CACHE_CHECK([for wmemcmp], [gl_cv_func_wmemcmp],
15     [AC_LINK_IFELSE(
16        [AC_LANG_PROGRAM(
17           [[#include <wchar.h>
18           ]],
19           [[return ! wmemcmp ((const wchar_t *) 0, (const wchar_t *) 0, 0);]])
20        ],
21        [gl_cv_func_wmemcmp=yes],
22        [gl_cv_func_wmemcmp=no])
23     ])
24   if test $gl_cv_func_wmemcmp = no; then
25     HAVE_WMEMCMP=0
26   else
27     AC_CACHE_CHECK([whether wmemcmp works for all wide characters],
28       [gl_cv_func_wmemcmp_works],
29       [AC_RUN_IFELSE(
30          [AC_LANG_SOURCE([[
31             #include <wchar.h>
32             int main ()
33             {
34               wchar_t a = (wchar_t) 0x76547654;
35               wchar_t b = (wchar_t) 0x9abc9abc;
36               int cmp = wmemcmp (&a, &b, 1);
37               if ((wchar_t)-1 < 0)
38                 return !(cmp > 0);
39               else
40                 return !(cmp < 0);
41             }
42             ]])
43          ],
44          [gl_cv_func_wmemcmp_works=yes],
45          [gl_cv_func_wmemcmp_works=no],
46          [case "$host_on" in
47             # Guess no on glibc versions < 2.15.
48             *-gnu* | gnu*)
49               AC_EGREP_CPP([Unlucky],
50                 [
51 #include <features.h>
52 #ifdef __GNU_LIBRARY__
53  #if (__GLIBC__ == 2 && __GLIBC_MINOR__ < 15)
54   Unlucky GNU user
55  #endif
56 #endif
57                 ],
58                 [gl_cv_func_wmemcmp_works="guessing no"],
59                 [gl_cv_func_wmemcmp_works="guessing yes"])
60               ;;
61             # Guess no on musl systems.
62             *-musl* | midipix*) gl_cv_func_wmemcmp_works="guessing no" ;;
63             # If we don't know, obey --enable-cross-guesses.
64             *) gl_cv_func_wmemcmp_works="$gl_cross_guess_normal" ;;
65           esac
66          ])
67       ])
68     case "$gl_cv_func_wmemcmp_works" in
69       *yes) ;;
70       *) REPLACE_WMEMCMP=1 ;;
71     esac
72   fi