1 # strcasestr.m4 serial 13
2 dnl Copyright (C) 2005, 2007, 2008, 2009, 2010 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
24 if test $HAVE_STRCASESTR = 0 || test $REPLACE_STRCASESTR = 1; then
25 AC_LIBOBJ([strcasestr])
28 ]) # gl_FUNC_STRCASESTR_SIMPLE
30 dnl Additionally, check that strcasestr is efficient.
31 AC_DEFUN([gl_FUNC_STRCASESTR],
33 AC_REQUIRE([gl_FUNC_STRCASESTR_SIMPLE])
34 if test $HAVE_STRCASESTR = 1 && test $REPLACE_STRCASESTR = 0; then
35 AC_CACHE_CHECK([whether strcasestr works in linear time],
36 [gl_cv_func_strcasestr_linear],
37 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
38 #include <signal.h> /* for signal */
39 #include <string.h> /* for memmem */
40 #include <stdlib.h> /* for malloc */
41 #include <unistd.h> /* for alarm */
42 ]], [[size_t m = 1000000;
43 char *haystack = (char *) malloc (2 * m + 2);
44 char *needle = (char *) malloc (m + 2);
46 /* Failure to compile this test due to missing alarm is okay,
47 since all such platforms (mingw) also lack strcasestr. */
48 signal (SIGALRM, SIG_DFL);
50 /* Check for quadratic performance. */
51 if (haystack && needle)
53 memset (haystack, 'A', 2 * m);
54 haystack[2 * m] = 'B';
55 haystack[2 * m + 1] = 0;
56 memset (needle, 'A', m);
59 result = strcasestr (haystack, needle);
62 [gl_cv_func_strcasestr_linear=yes], [gl_cv_func_strcasestr_linear=no],
63 [dnl Only glibc >= 2.9 and cygwin >= 1.7.0 are known to have a
64 dnl strcasestr that works in linear time.
65 AC_EGREP_CPP([Lucky user],
68 #ifdef __GNU_LIBRARY__
69 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 9) || (__GLIBC__ > 2)
74 #include <cygwin/version.h>
75 #if CYGWIN_VERSION_DLL_MAJOR >= 1007
80 [gl_cv_func_strcasestr_linear=yes],
81 [gl_cv_func_strcasestr_linear="guessing no"])
84 if test "$gl_cv_func_strcasestr_linear" != yes; then
86 AC_LIBOBJ([strcasestr])
90 ]) # gl_FUNC_STRCASESTR
92 # Prerequisites of lib/strcasestr.c.
93 AC_DEFUN([gl_PREREQ_STRCASESTR], [