]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/gnulib/m4/memmem.m4
This commit was manufactured by cvs2svn to create branch
[thirdparty/binutils-gdb.git] / gdb / gnulib / m4 / memmem.m4
1 # memmem.m4 serial 9
2 dnl Copyright (C) 2002, 2003, 2004, 2007, 2008 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 dnl Check that memmem is present.
8 AC_DEFUN([gl_FUNC_MEMMEM_SIMPLE],
9 [
10 dnl Persuade glibc <string.h> to declare memmem().
11 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
12
13 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
14 AC_REPLACE_FUNCS(memmem)
15 AC_CHECK_DECLS_ONCE(memmem)
16 if test $ac_cv_have_decl_memmem = no; then
17 HAVE_DECL_MEMMEM=0
18 fi
19 gl_PREREQ_MEMMEM
20 ]) # gl_FUNC_MEMMEM_SIMPLE
21
22 dnl Additionally, check that memmem is efficient and handles empty needles.
23 AC_DEFUN([gl_FUNC_MEMMEM],
24 [
25 AC_REQUIRE([gl_FUNC_MEMMEM_SIMPLE])
26 if test $ac_cv_have_decl_memmem = yes; then
27 AC_CACHE_CHECK([whether memmem works in linear time],
28 [gl_cv_func_memmem_works],
29 [AC_RUN_IFELSE([AC_LANG_PROGRAM([
30 #include <string.h> /* for memmem */
31 #include <stdlib.h> /* for malloc */
32 #include <unistd.h> /* for alarm */
33 ], [[size_t m = 1000000;
34 char *haystack = (char *) malloc (2 * m + 1);
35 char *needle = (char *) malloc (m + 1);
36 void *result = 0;
37 /* Failure to compile this test due to missing alarm is okay,
38 since all such platforms (mingw) also lack memmem. */
39 alarm (5);
40 /* Check for quadratic performance. */
41 if (haystack && needle)
42 {
43 memset (haystack, 'A', 2 * m);
44 haystack[2 * m] = 'B';
45 memset (needle, 'A', m);
46 needle[m] = 'B';
47 result = memmem (haystack, 2 * m + 1, needle, m + 1);
48 }
49 /* Check for empty needle behavior. */
50 return !result || !memmem ("a", 1, 0, 0);]])],
51 [gl_cv_func_memmem_works=yes], [gl_cv_func_memmem_works=no],
52 [dnl pessimistically assume the worst, since even glibc 2.6.1
53 dnl has quadratic complexity in its memmem
54 gl_cv_func_memmem_works="guessing no"])])
55 if test "$gl_cv_func_memmem_works" != yes; then
56 REPLACE_MEMMEM=1
57 AC_LIBOBJ([memmem])
58 fi
59 fi
60 ]) # gl_FUNC_MEMMEM
61
62 # Prerequisites of lib/memmem.c.
63 AC_DEFUN([gl_PREREQ_MEMMEM], [:])