1 # strcasestr.m4 serial 14
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 static void quit (int sig) { exit (sig + 128); }
43 ]], [[size_t m = 1000000;
44 char *haystack = (char *) malloc (2 * m + 2);
45 char *needle = (char *) malloc (m + 2);
47 /* Failure to compile this test due to missing alarm is okay,
48 since all such platforms (mingw) also lack strcasestr. */
49 signal (SIGALRM, quit);
51 /* Check for quadratic performance. */
52 if (haystack && needle)
54 memset (haystack, 'A', 2 * m);
55 haystack[2 * m] = 'B';
56 haystack[2 * m + 1] = 0;
57 memset (needle, 'A', m);
60 result = strcasestr (haystack, needle);
63 [gl_cv_func_strcasestr_linear=yes], [gl_cv_func_strcasestr_linear=no],
64 [dnl Only glibc >= 2.9 and cygwin >= 1.7.0 are known to have a
65 dnl strcasestr that works in linear time.
66 AC_EGREP_CPP([Lucky user],
69 #ifdef __GNU_LIBRARY__
70 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 9) || (__GLIBC__ > 2)
75 #include <cygwin/version.h>
76 #if CYGWIN_VERSION_DLL_MAJOR >= 1007
81 [gl_cv_func_strcasestr_linear=yes],
82 [gl_cv_func_strcasestr_linear="guessing no"])
85 if test "$gl_cv_func_strcasestr_linear" != yes; then
87 AC_LIBOBJ([strcasestr])
91 ]) # gl_FUNC_STRCASESTR
93 # Prerequisites of lib/strcasestr.c.
94 AC_DEFUN([gl_PREREQ_STRCASESTR], [