1 # strcasestr.m4 serial 24
2 dnl Copyright (C) 2005, 2007-2018 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 $HAVE_MEMCHR = 0 || test $REPLACE_MEMCHR = 1; then
23 dnl Detect https://sourceware.org/bugzilla/show_bug.cgi?id=12092
24 dnl and https://sourceware.org/bugzilla/show_bug.cgi?id=23637.
25 AC_CACHE_CHECK([whether strcasestr works],
26 [gl_cv_func_strcasestr_works_always],
29 #include <string.h> /* for strcasestr */
30 #ifdef __GNU_LIBRARY__
32 #if __GLIBC__ == 2 && __GLIBC_MINOR__ == 28
37 #define HAYSTACK "F_BD_CE_BD" P P P P "_C3_88_20" P P P "_C3_A7_20" P
38 #define NEEDLE P P P P P
40 [[return !!strcasestr (HAYSTACK, NEEDLE);
42 [gl_cv_func_strcasestr_works_always=yes],
43 [gl_cv_func_strcasestr_works_always=no],
44 [dnl glibc 2.12 and cygwin 1.7.7 have a known bug. uClibc is not
45 dnl affected, since it uses different source code for strcasestr
47 dnl Assume that it works on all other platforms, even if it is not
49 AC_EGREP_CPP([Lucky user],
51 #ifdef __GNU_LIBRARY__
53 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ > 12) || (__GLIBC__ > 2)) \
57 #elif defined __CYGWIN__
58 #include <cygwin/version.h>
59 #if CYGWIN_VERSION_DLL_COMBINED > CYGWIN_VERSION_DLL_MAKE_COMBINED (1007, 7)
66 [gl_cv_func_strcasestr_works_always="guessing yes"],
67 [gl_cv_func_strcasestr_works_always="guessing no"])
70 case "$gl_cv_func_strcasestr_works_always" in
78 ]) # gl_FUNC_STRCASESTR_SIMPLE
80 dnl Additionally, check that strcasestr is efficient.
81 AC_DEFUN([gl_FUNC_STRCASESTR],
83 AC_REQUIRE([gl_FUNC_STRCASESTR_SIMPLE])
84 if test $HAVE_STRCASESTR = 1 && test $REPLACE_STRCASESTR = 0; then
85 AC_CACHE_CHECK([whether strcasestr works in linear time],
86 [gl_cv_func_strcasestr_linear],
87 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
88 #include <signal.h> /* for signal */
89 #include <string.h> /* for strcasestr */
90 #include <stdlib.h> /* for malloc */
91 #include <unistd.h> /* for alarm */
92 static void quit (int sig) { _exit (sig + 128); }
96 char *haystack = (char *) malloc (2 * m + 2);
97 char *needle = (char *) malloc (m + 2);
98 /* Failure to compile this test due to missing alarm is okay,
99 since all such platforms (mingw) also lack strcasestr. */
100 signal (SIGALRM, quit);
102 /* Check for quadratic performance. */
103 if (haystack && needle)
105 memset (haystack, 'A', 2 * m);
106 haystack[2 * m] = 'B';
107 haystack[2 * m + 1] = 0;
108 memset (needle, 'A', m);
111 if (!strcasestr (haystack, needle))
114 /* Free allocated memory, in case some sanitizer is watching. */
119 [gl_cv_func_strcasestr_linear=yes], [gl_cv_func_strcasestr_linear=no],
120 [dnl Only glibc > 2.12 and cygwin > 1.7.7 are known to have a
121 dnl strcasestr that works in linear time.
122 AC_EGREP_CPP([Lucky user],
124 #include <features.h>
125 #ifdef __GNU_LIBRARY__
126 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ > 12) || (__GLIBC__ > 2)) \
127 && !defined __UCLIBC__
132 #include <cygwin/version.h>
133 #if CYGWIN_VERSION_DLL_COMBINED > CYGWIN_VERSION_DLL_MAKE_COMBINED (1007, 7)
138 [gl_cv_func_strcasestr_linear="guessing yes"],
139 [gl_cv_func_strcasestr_linear="guessing no"])
142 case "$gl_cv_func_strcasestr_linear" in
149 ]) # gl_FUNC_STRCASESTR
151 # Prerequisites of lib/strcasestr.c.
152 AC_DEFUN([gl_PREREQ_STRCASESTR], [