1 # strcasestr.m4 serial 20
2 dnl Copyright (C) 2005, 2007-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 strcasestr is present and works.
8 AC_DEFUN([gl_FUNC_STRCASESTR_SIMPLE],
10 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
12 dnl Persuade glibc <string.h> to declare strcasestr().
13 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
15 AC_REQUIRE([gl_FUNC_MEMCHR])
16 AC_CHECK_FUNCS([strcasestr])
17 if test $ac_cv_func_strcasestr = no; then
20 if test "$gl_cv_func_memchr_works" != yes; then
23 dnl Detect http://sourceware.org/bugzilla/show_bug.cgi?id=12092.
24 AC_CACHE_CHECK([whether strcasestr works],
25 [gl_cv_func_strcasestr_works_always],
26 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
27 #include <string.h> /* for strcasestr */
29 #define HAYSTACK "F_BD_CE_BD" P P P P "_C3_88_20" P P P "_C3_A7_20" P
30 #define NEEDLE P P P P P
31 ]], [[return !!strcasestr (HAYSTACK, NEEDLE);
33 [gl_cv_func_strcasestr_works_always=yes],
34 [gl_cv_func_strcasestr_works_always=no],
35 [dnl glibc 2.12 and cygwin 1.7.7 have a known bug. uClibc is not
36 dnl affected, since it uses different source code for strcasestr
38 dnl Assume that it works on all other platforms, even if it is not
40 AC_EGREP_CPP([Lucky user],
42 #ifdef __GNU_LIBRARY__
44 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ > 12) || (__GLIBC__ > 2)) \
48 #elif defined __CYGWIN__
49 #include <cygwin/version.h>
50 #if CYGWIN_VERSION_DLL_COMBINED > CYGWIN_VERSION_DLL_MAKE_COMBINED (1007, 7)
57 [gl_cv_func_strcasestr_works_always=yes],
58 [gl_cv_func_strcasestr_works_always="guessing no"])
61 if test "$gl_cv_func_strcasestr_works_always" != yes; then
66 ]) # gl_FUNC_STRCASESTR_SIMPLE
68 dnl Additionally, check that strcasestr is efficient.
69 AC_DEFUN([gl_FUNC_STRCASESTR],
71 AC_REQUIRE([gl_FUNC_STRCASESTR_SIMPLE])
72 if test $HAVE_STRCASESTR = 1 && test $REPLACE_STRCASESTR = 0; then
73 AC_CACHE_CHECK([whether strcasestr works in linear time],
74 [gl_cv_func_strcasestr_linear],
75 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
76 #include <signal.h> /* for signal */
77 #include <string.h> /* for strcasestr */
78 #include <stdlib.h> /* for malloc */
79 #include <unistd.h> /* for alarm */
80 static void quit (int sig) { exit (sig + 128); }
84 char *haystack = (char *) malloc (2 * m + 2);
85 char *needle = (char *) malloc (m + 2);
86 /* Failure to compile this test due to missing alarm is okay,
87 since all such platforms (mingw) also lack strcasestr. */
88 signal (SIGALRM, quit);
90 /* Check for quadratic performance. */
91 if (haystack && needle)
93 memset (haystack, 'A', 2 * m);
94 haystack[2 * m] = 'B';
95 haystack[2 * m + 1] = 0;
96 memset (needle, 'A', m);
99 if (!strcasestr (haystack, needle))
104 [gl_cv_func_strcasestr_linear=yes], [gl_cv_func_strcasestr_linear=no],
105 [dnl Only glibc > 2.12 and cygwin > 1.7.7 are known to have a
106 dnl strcasestr that works in linear time.
107 AC_EGREP_CPP([Lucky user],
109 #include <features.h>
110 #ifdef __GNU_LIBRARY__
111 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ > 12) || (__GLIBC__ > 2)) \
112 && !defined __UCLIBC__
117 #include <cygwin/version.h>
118 #if CYGWIN_VERSION_DLL_COMBINED > CYGWIN_VERSION_DLL_MAKE_COMBINED (1007, 7)
123 [gl_cv_func_strcasestr_linear=yes],
124 [gl_cv_func_strcasestr_linear="guessing no"])
127 if test "$gl_cv_func_strcasestr_linear" != yes; then
131 ]) # gl_FUNC_STRCASESTR
133 # Prerequisites of lib/strcasestr.c.
134 AC_DEFUN([gl_PREREQ_STRCASESTR], [