1 # strcasestr.m4 serial 13
2 dnl Copyright (C) 2005, 2007, 2008, 2009 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 dnl Persuade glibc <string.h> to declare strcasestr().
11 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
13 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
14 AC_REQUIRE([gl_FUNC_MEMCHR])
15 AC_REPLACE_FUNCS([strcasestr])
16 if test $ac_cv_func_strcasestr = no; then
19 elif test "$gl_cv_func_memchr_works" != yes; then
21 AC_LIBOBJ([strcasestr])
24 ]) # gl_FUNC_STRCASESTR_SIMPLE
26 dnl Additionally, check that strcasestr is efficient.
27 AC_DEFUN([gl_FUNC_STRCASESTR],
29 AC_REQUIRE([gl_FUNC_STRCASESTR_SIMPLE])
30 if test $ac_cv_func_strcasestr = yes; then
31 AC_CACHE_CHECK([whether strcasestr works in linear time],
32 [gl_cv_func_strcasestr_linear],
33 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
34 #include <signal.h> /* for signal */
35 #include <string.h> /* for memmem */
36 #include <stdlib.h> /* for malloc */
37 #include <unistd.h> /* for alarm */
38 ]], [[size_t m = 1000000;
39 char *haystack = (char *) malloc (2 * m + 2);
40 char *needle = (char *) malloc (m + 2);
42 /* Failure to compile this test due to missing alarm is okay,
43 since all such platforms (mingw) also lack strcasestr. */
44 signal (SIGALRM, SIG_DFL);
46 /* Check for quadratic performance. */
47 if (haystack && needle)
49 memset (haystack, 'A', 2 * m);
50 haystack[2 * m] = 'B';
51 haystack[2 * m + 1] = 0;
52 memset (needle, 'A', m);
55 result = strcasestr (haystack, needle);
58 [gl_cv_func_strcasestr_linear=yes], [gl_cv_func_strcasestr_linear=no],
59 [dnl Only glibc >= 2.9 and cygwin >= 1.7.0 are known to have a
60 dnl strcasestr that works in linear time.
61 AC_EGREP_CPP([Lucky user],
64 #ifdef __GNU_LIBRARY__
65 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 9) || (__GLIBC__ > 2)
70 #include <cygwin/version.h>
71 #if CYGWIN_VERSION_DLL_MAJOR >= 1007
76 [gl_cv_func_strcasestr_linear=yes],
77 [gl_cv_func_strcasestr_linear="guessing no"])
80 if test "$gl_cv_func_strcasestr_linear" != yes; then
82 AC_LIBOBJ([strcasestr])
85 ]) # gl_FUNC_STRCASESTR
87 # Prerequisites of lib/strcasestr.c.
88 AC_DEFUN([gl_PREREQ_STRCASESTR], [