NEWS.stable: log cherry-pick [79aac72]->[cc1a9b7] canonicalize-lgpl: use common idiom
[gnulib.git] / m4 / memcmp.m4
1 # memcmp.m4 serial 15
2 dnl Copyright (C) 2002-2004, 2007-2011 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.
6
7 AC_DEFUN([gl_FUNC_MEMCMP],
8 [
9   if test $cross_compiling != no; then
10     # AC_FUNC_MEMCMP as of 2.62 defaults to 'no' when cross compiling.
11     # We default to yes if memcmp appears to exist, which works
12     # better for MinGW.
13     AC_CACHE_CHECK([whether cross-compiling target has memcmp],
14                    [ac_cv_func_memcmp_working],
15                    [AC_LINK_IFELSE([
16                         AC_LANG_PROGRAM([[#include <string.h>
17                                 ]], [[int ret = memcmp ("foo", "bar", 0);]])],
18                         [ac_cv_func_memcmp_working=yes],
19                         [ac_cv_func_memcmp_working=no])])
20   fi
21   AC_FUNC_MEMCMP
22   dnl Note: AC_FUNC_MEMCMP does AC_LIBOBJ([memcmp]).
23   if test $ac_cv_func_memcmp_working = no; then
24     AC_DEFINE([memcmp], [rpl_memcmp],
25       [Define to rpl_memcmp if the replacement function should be used.])
26     gl_PREREQ_MEMCMP
27   fi
28 ])
29
30 # Redefine AC_FUNC_MEMCMP, because it is no longer maintained in Autoconf.
31 AC_DEFUN([AC_FUNC_MEMCMP],
32 [
33   AC_CACHE_CHECK([for working memcmp], [ac_cv_func_memcmp_working],
34     [AC_RUN_IFELSE(
35        [AC_LANG_PROGRAM(
36           [AC_INCLUDES_DEFAULT],
37           [[/* Some versions of memcmp are not 8-bit clean.  */
38             char c0 = '\100', c1 = '\200', c2 = '\201';
39             if (memcmp(&c0, &c2, 1) >= 0 || memcmp(&c1, &c2, 1) >= 0)
40               return 1;
41             /* The Next x86 OpenStep bug shows up only when comparing 16 bytes
42                or more and with at least one buffer not starting on a 4-byte
43                boundary.  William Lewis provided this test program.   */
44             {
45               char foo[21];
46               char bar[21];
47               int i;
48               for (i = 0; i < 4; i++)
49                 {
50                   char *a = foo + i;
51                   char *b = bar + i;
52                   strcpy (a, "--------01111111");
53                   strcpy (b, "--------10000000");
54                   if (memcmp (a, b, 16) >= 0)
55                     return 1;
56                 }
57               return 0;
58             }
59           ]])],
60        [ac_cv_func_memcmp_working=yes],
61        [ac_cv_func_memcmp_working=no],
62        [ac_cv_func_memcmp_working=no])])
63   test $ac_cv_func_memcmp_working = no &&
64     AC_LIBOBJ([memcmp])
65 ])
66
67 # Prerequisites of lib/memcmp.c.
68 AC_DEFUN([gl_PREREQ_MEMCMP], [:])