* m4/strstr.m4: Delete cruft from copy-n-paste.
[gnulib.git] / m4 / strstr.m4
1 # strstr.m4 serial 1
2 dnl Copyright (C) 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 strstr is efficient.
8 AC_DEFUN([gl_FUNC_STRSTR],
9 [
10   AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
11   AC_CACHE_CHECK([whether strstr works in linear time],
12     [gl_cv_func_strstr_linear],
13     [AC_RUN_IFELSE([AC_LANG_PROGRAM([
14 #include <string.h> /* for memmem */
15 #include <stdlib.h> /* for malloc */
16 #include <unistd.h> /* for alarm */
17 ], [[size_t m = 1000000;
18     char *haystack = (char *) malloc (2 * m + 2);
19     char *needle = (char *) malloc (m + 2);
20     void *result = 0;
21     /* Failure to compile this test due to missing alarm is okay,
22        since all such platforms (mingw) also have quadratic strstr.  */
23     alarm (5);
24     /* Check for quadratic performance.  */
25     if (haystack && needle)
26       {
27         memset (haystack, 'A', 2 * m);
28         haystack[2 * m] = 'B';
29         haystack[2 * m + 1] = 0;
30         memset (needle, 'A', m);
31         needle[m] = 'B';
32         needle[m + 1] = 0;
33         result = strstr (haystack, needle);
34       }
35     return !result;]])],
36       [gl_cv_func_strstr_linear=yes], [gl_cv_func_strstr_linear=no],
37       [dnl pessimistically assume the worst, since even glibc 2.6.1
38        dnl has quadratic complexity in its strstr
39        gl_cv_func_strstr_linear="guessing no"])])
40   if test "$gl_cv_func_strstr_linear" != yes; then
41     REPLACE_STRSTR=1
42     AC_LIBOBJ([strstr])
43   fi
44 ]) # gl_FUNC_STRSTR