.
[gnulib.git] / m4 / memcmp.m4
1 #serial 2
2
3 dnl A replacement for autoconf's AC_FUNC_MEMCMP that detects
4 dnl the losing memcmp on some x86 Next systems.
5 AC_DEFUN(jm_AC_FUNC_MEMCMP,
6 [AC_CACHE_CHECK([for working memcmp], jm_cv_func_memcmp_working,
7 [AC_TRY_RUN(
8 changequote(<<, >>)dnl
9 <<
10 main()
11 {
12   /* Some versions of memcmp are not 8-bit clean.  */
13   char c0 = 0x40, c1 = 0x80, c2 = 0x81;
14   if (memcmp(&c0, &c2, 1) >= 0 || memcmp(&c1, &c2, 1) >= 0)
15     exit (1);
16
17   /* The Next x86 OpenStep bug shows up only when comparing 16 bytes
18      or more and with at least one buffer not starting on a 4-byte boundary.
19      William Lewis provided this test program.   */
20   {
21     char foo[21];
22     char bar[21];
23     int i;
24     for (i = 0; i < 4; i++)
25       {
26         char *a = foo + i;
27         char *b = bar + i;
28         strcpy (a, "--------01111111");
29         strcpy (b, "--------10000000");
30         if (memcmp (a, b, 16) >= 0)
31           exit (1);
32       }
33     exit (0);
34   }
35 }
36 >>,
37 changequote([, ])dnl
38    jm_cv_func_memcmp_working=yes,
39    jm_cv_func_memcmp_working=no,
40    jm_cv_func_memcmp_working=no)])
41 test $jm_cv_func_memcmp_working = no && LIBOBJS="$LIBOBJS memcmp.o"
42 AC_SUBST(LIBOBJS)dnl
43 ])
44
45 dnl If you use this macro in a package, you should
46 dnl add the following two lines to acconfig.h:
47 dnl   /* Define to rpl_memcmp if the replacement function should be used.  */
48 dnl   #undef memcmp
49 dnl
50 AC_DEFUN(jm_FUNC_MEMCMP,
51 [AC_REQUIRE([jm_AC_FUNC_MEMCMP])dnl
52  if test $jm_cv_func_memcmp_working = no; then
53    AC_DEFINE_UNQUOTED(memcmp, rpl_memcmp)
54  fi
55 ])