2 dnl Copyright (C) 2008-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.
7 dnl Check that strstr works.
8 AC_DEFUN([gl_FUNC_STRSTR_SIMPLE],
10 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
11 AC_REQUIRE([gl_FUNC_MEMCHR])
12 if test "$gl_cv_func_memchr_works" != yes; then
15 dnl Detect http://sourceware.org/bugzilla/show_bug.cgi?id=12092.
16 AC_CACHE_CHECK([whether strstr works],
17 [gl_cv_func_strstr_works_always],
18 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
19 #include <string.h> /* for strstr */
21 #define HAYSTACK "F_BD_CE_BD" P P P P "_C3_88_20" P P P "_C3_A7_20" P
22 #define NEEDLE P P P P P
23 ]], [[return !!strstr (HAYSTACK, NEEDLE);
25 [gl_cv_func_strstr_works_always=yes],
26 [gl_cv_func_strstr_works_always=no],
27 [dnl glibc 2.12 and cygwin 1.7.7 have a known bug. uClibc is not
28 dnl affected, since it uses different source code for strstr than
30 dnl Assume that it works on all other platforms, even if it is not
32 AC_EGREP_CPP([Lucky user],
34 #ifdef __GNU_LIBRARY__
36 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ > 12) || (__GLIBC__ > 2)) \
40 #elif defined __CYGWIN__
41 #include <cygwin/version.h>
42 #if CYGWIN_VERSION_DLL_COMBINED > CYGWIN_VERSION_DLL_MAKE_COMBINED (1007, 7)
49 [gl_cv_func_strstr_works_always=yes],
50 [gl_cv_func_strstr_works_always="guessing no"])
53 if test "$gl_cv_func_strstr_works_always" != yes; then
57 ]) # gl_FUNC_STRSTR_SIMPLE
59 dnl Additionally, check that strstr is efficient.
60 AC_DEFUN([gl_FUNC_STRSTR],
62 AC_REQUIRE([gl_FUNC_STRSTR_SIMPLE])
63 if test $REPLACE_STRSTR = 0; then
64 AC_CACHE_CHECK([whether strstr works in linear time],
65 [gl_cv_func_strstr_linear],
66 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
67 #include <signal.h> /* for signal */
68 #include <string.h> /* for strstr */
69 #include <stdlib.h> /* for malloc */
70 #include <unistd.h> /* for alarm */
71 static void quit (int sig) { exit (sig + 128); }
75 char *haystack = (char *) malloc (2 * m + 2);
76 char *needle = (char *) malloc (m + 2);
77 /* Failure to compile this test due to missing alarm is okay,
78 since all such platforms (mingw) also have quadratic strstr. */
79 signal (SIGALRM, quit);
81 /* Check for quadratic performance. */
82 if (haystack && needle)
84 memset (haystack, 'A', 2 * m);
85 haystack[2 * m] = 'B';
86 haystack[2 * m + 1] = 0;
87 memset (needle, 'A', m);
90 if (!strstr (haystack, needle))
95 [gl_cv_func_strstr_linear=yes], [gl_cv_func_strstr_linear=no],
96 [dnl Only glibc > 2.12 and cygwin > 1.7.7 are known to have a
97 dnl bug-free strstr that works in linear time.
98 AC_EGREP_CPP([Lucky user],
100 #include <features.h>
101 #ifdef __GNU_LIBRARY__
102 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ > 12) || (__GLIBC__ > 2)) \
103 && !defined __UCLIBC__
108 #include <cygwin/version.h>
109 #if CYGWIN_VERSION_DLL_COMBINED > CYGWIN_VERSION_DLL_MAKE_COMBINED (1007, 7)
114 [gl_cv_func_strstr_linear=yes],
115 [gl_cv_func_strstr_linear="guessing no"])
118 if test "$gl_cv_func_strstr_linear" != yes; then