1 # strcasestr.m4 serial 10
2 dnl Copyright (C) 2005, 2007, 2008 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.
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_REPLACE_FUNCS([strcasestr])
15 if test $ac_cv_func_strcasestr = no; then
19 ]) # gl_FUNC_STRCASESTR_SIMPLE
21 dnl Additionally, check that strcasestr is efficient.
22 AC_DEFUN([gl_FUNC_STRCASESTR],
24 AC_REQUIRE([gl_FUNC_STRCASESTR_SIMPLE])
25 if test $ac_cv_func_strcasestr = yes; then
26 AC_CACHE_CHECK([whether strcasestr works in linear time],
27 [gl_cv_func_strcasestr_linear],
28 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
29 #include <string.h> /* for memmem */
30 #include <stdlib.h> /* for malloc */
31 #include <unistd.h> /* for alarm */
32 ]], [[size_t m = 1000000;
33 char *haystack = (char *) malloc (2 * m + 2);
34 char *needle = (char *) malloc (m + 2);
36 /* Failure to compile this test due to missing alarm is okay,
37 since all such platforms (mingw) also lack strcasestr. */
39 /* Check for quadratic performance. */
40 if (haystack && needle)
42 memset (haystack, 'A', 2 * m);
43 haystack[2 * m] = 'B';
44 haystack[2 * m + 1] = 0;
45 memset (needle, 'A', m);
48 result = strcasestr (haystack, needle);
51 [gl_cv_func_strcasestr_linear=yes], [gl_cv_func_strcasestr_linear=no],
52 [dnl Only glibc >= 2.9 is known to have an strcasestr that works in
54 AC_EGREP_CPP([Lucky GNU user],
57 #ifdef __GNU_LIBRARY__
58 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 9) || (__GLIBC__ > 2)
63 [gl_cv_func_strcasestr_linear=yes],
64 [gl_cv_func_strcasestr_linear="guessing no"])
67 if test "$gl_cv_func_strcasestr_linear" != yes; then
69 AC_LIBOBJ([strcasestr])
72 ]) # gl_FUNC_STRCASESTR
74 # Prerequisites of lib/strcasestr.c.
75 AC_DEFUN([gl_PREREQ_STRCASESTR], [