2012-04-18 Pedro Alves <palves@redhat.com>
[deliverable/binutils-gdb.git] / gdb / gnulib / m4 / memmem.m4
CommitLineData
f434ba03
PA
1# memmem.m4 serial 14
2dnl Copyright (C) 2002, 2003, 2004, 2007, 2008, 2009, 2010 Free Software
3dnl Foundation, Inc.
f6ea5628
DJ
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7
8dnl Check that memmem is present.
9AC_DEFUN([gl_FUNC_MEMMEM_SIMPLE],
10[
11 dnl Persuade glibc <string.h> to declare memmem().
12 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
13
14 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
f434ba03
PA
15 AC_REPLACE_FUNCS([memmem])
16 AC_CHECK_DECLS_ONCE([memmem])
f6ea5628
DJ
17 if test $ac_cv_have_decl_memmem = no; then
18 HAVE_DECL_MEMMEM=0
19 fi
20 gl_PREREQ_MEMMEM
21]) # gl_FUNC_MEMMEM_SIMPLE
22
23dnl Additionally, check that memmem is efficient and handles empty needles.
24AC_DEFUN([gl_FUNC_MEMMEM],
25[
26 AC_REQUIRE([gl_FUNC_MEMMEM_SIMPLE])
27 if test $ac_cv_have_decl_memmem = yes; then
28 AC_CACHE_CHECK([whether memmem works in linear time],
29 [gl_cv_func_memmem_works],
f434ba03
PA
30 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
31#include <signal.h> /* for signal */
f6ea5628
DJ
32#include <string.h> /* for memmem */
33#include <stdlib.h> /* for malloc */
34#include <unistd.h> /* for alarm */
f434ba03 35]], [[size_t m = 1000000;
f6ea5628
DJ
36 char *haystack = (char *) malloc (2 * m + 1);
37 char *needle = (char *) malloc (m + 1);
38 void *result = 0;
39 /* Failure to compile this test due to missing alarm is okay,
40 since all such platforms (mingw) also lack memmem. */
f434ba03 41 signal (SIGALRM, SIG_DFL);
f6ea5628
DJ
42 alarm (5);
43 /* Check for quadratic performance. */
44 if (haystack && needle)
45 {
f434ba03
PA
46 memset (haystack, 'A', 2 * m);
47 haystack[2 * m] = 'B';
48 memset (needle, 'A', m);
49 needle[m] = 'B';
50 result = memmem (haystack, 2 * m + 1, needle, m + 1);
f6ea5628
DJ
51 }
52 /* Check for empty needle behavior. */
53 return !result || !memmem ("a", 1, 0, 0);]])],
f434ba03
PA
54 [gl_cv_func_memmem_works=yes], [gl_cv_func_memmem_works=no],
55 [dnl Only glibc >= 2.9 and cygwin >= 1.7.0 are known to have a
56 dnl memmem that works in linear time.
57 AC_EGREP_CPP([Lucky user],
58 [
59#include <features.h>
60#ifdef __GNU_LIBRARY__
61 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 9) || (__GLIBC__ > 2)
62 Lucky user
63 #endif
64#endif
65#ifdef __CYGWIN__
66 #include <cygwin/version.h>
67 #if CYGWIN_VERSION_DLL_MAJOR >= 1007
68 Lucky user
69 #endif
70#endif
71 ],
72 [gl_cv_func_memmem_works=yes],
73 [gl_cv_func_memmem_works="guessing no"])
74 ])
75 ])
f6ea5628
DJ
76 if test "$gl_cv_func_memmem_works" != yes; then
77 REPLACE_MEMMEM=1
78 AC_LIBOBJ([memmem])
79 fi
80 fi
81]) # gl_FUNC_MEMMEM
82
83# Prerequisites of lib/memmem.c.
84AC_DEFUN([gl_PREREQ_MEMMEM], [:])
This page took 0.405035 seconds and 4 git commands to generate.