1# strcasestr.m4 serial 13 2dnl Copyright (C) 2005, 2007, 2008, 2009 Free Software Foundation, Inc. 3dnl This file is free software; the Free Software Foundation 4dnl gives unlimited permission to copy and/or distribute it, 5dnl with or without modifications, as long as this notice is preserved. 6 7dnl Check that strcasestr is present and works. 8AC_DEFUN([gl_FUNC_STRCASESTR_SIMPLE], 9[ 10 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) 11 12 dnl Persuade glibc <string.h> to declare strcasestr(). 13 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) 14 15 AC_REQUIRE([gl_FUNC_MEMCHR]) 16 AC_CHECK_FUNCS([strcasestr]) 17 if test $ac_cv_func_strcasestr = no; then 18 HAVE_STRCASESTR=0 19 else 20 if test "$gl_cv_func_memchr_works" != yes; then 21 REPLACE_STRCASESTR=1 22 fi 23 fi 24 if test $HAVE_STRCASESTR = 0 || test $REPLACE_STRCASESTR = 1; then 25 AC_LIBOBJ([strcasestr]) 26 gl_PREREQ_STRCASESTR 27 fi 28]) # gl_FUNC_STRCASESTR_SIMPLE 29 30dnl Additionally, check that strcasestr is efficient. 31AC_DEFUN([gl_FUNC_STRCASESTR], 32[ 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); 45 void *result = 0; 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); 49 alarm (5); 50 /* Check for quadratic performance. */ 51 if (haystack && needle) 52 { 53 memset (haystack, 'A', 2 * m); 54 haystack[2 * m] = 'B'; 55 haystack[2 * m + 1] = 0; 56 memset (needle, 'A', m); 57 needle[m] = 'B'; 58 needle[m + 1] = 0; 59 result = strcasestr (haystack, needle); 60 } 61 return !result;]])], 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], 66 [ 67#include <features.h> 68#ifdef __GNU_LIBRARY__ 69 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 9) || (__GLIBC__ > 2) 70 Lucky user 71 #endif 72#endif 73#ifdef __CYGWIN__ 74 #include <cygwin/version.h> 75 #if CYGWIN_VERSION_DLL_MAJOR >= 1007 76 Lucky user 77 #endif 78#endif 79 ], 80 [gl_cv_func_strcasestr_linear=yes], 81 [gl_cv_func_strcasestr_linear="guessing no"]) 82 ]) 83 ]) 84 if test "$gl_cv_func_strcasestr_linear" != yes; then 85 REPLACE_STRCASESTR=1 86 AC_LIBOBJ([strcasestr]) 87 gl_PREREQ_STRCASESTR 88 fi 89 fi 90]) # gl_FUNC_STRCASESTR 91 92# Prerequisites of lib/strcasestr.c. 93AC_DEFUN([gl_PREREQ_STRCASESTR], [ 94 : 95]) 96