diff options
Diffstat (limited to 'gl/m4/strstr.m4')
| -rw-r--r-- | gl/m4/strstr.m4 | 91 |
1 files changed, 71 insertions, 20 deletions
diff --git a/gl/m4/strstr.m4 b/gl/m4/strstr.m4 index 779957aa..c486bdb0 100644 --- a/gl/m4/strstr.m4 +++ b/gl/m4/strstr.m4 | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | # strstr.m4 serial 7 | 1 | # strstr.m4 serial 16 |
| 2 | dnl Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2008-2013 Free Software Foundation, Inc. |
| 3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
| 4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
| 5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
| @@ -11,7 +11,51 @@ AC_DEFUN([gl_FUNC_STRSTR_SIMPLE], | |||
| 11 | AC_REQUIRE([gl_FUNC_MEMCHR]) | 11 | AC_REQUIRE([gl_FUNC_MEMCHR]) |
| 12 | if test "$gl_cv_func_memchr_works" != yes; then | 12 | if test "$gl_cv_func_memchr_works" != yes; then |
| 13 | REPLACE_STRSTR=1 | 13 | REPLACE_STRSTR=1 |
| 14 | AC_LIBOBJ([strstr]) | 14 | else |
| 15 | dnl Detect http://sourceware.org/bugzilla/show_bug.cgi?id=12092. | ||
| 16 | AC_CACHE_CHECK([whether strstr works], | ||
| 17 | [gl_cv_func_strstr_works_always], | ||
| 18 | [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ | ||
| 19 | #include <string.h> /* for strstr */ | ||
| 20 | #define P "_EF_BF_BD" | ||
| 21 | #define HAYSTACK "F_BD_CE_BD" P P P P "_C3_88_20" P P P "_C3_A7_20" P | ||
| 22 | #define NEEDLE P P P P P | ||
| 23 | ]], [[return !!strstr (HAYSTACK, NEEDLE); | ||
| 24 | ]])], | ||
| 25 | [gl_cv_func_strstr_works_always=yes], | ||
| 26 | [gl_cv_func_strstr_works_always=no], | ||
| 27 | [dnl glibc 2.12 and cygwin 1.7.7 have a known bug. uClibc is not | ||
| 28 | dnl affected, since it uses different source code for strstr than | ||
| 29 | dnl glibc. | ||
| 30 | dnl Assume that it works on all other platforms, even if it is not | ||
| 31 | dnl linear. | ||
| 32 | AC_EGREP_CPP([Lucky user], | ||
| 33 | [ | ||
| 34 | #ifdef __GNU_LIBRARY__ | ||
| 35 | #include <features.h> | ||
| 36 | #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ > 12) || (__GLIBC__ > 2)) \ | ||
| 37 | || defined __UCLIBC__ | ||
| 38 | Lucky user | ||
| 39 | #endif | ||
| 40 | #elif defined __CYGWIN__ | ||
| 41 | #include <cygwin/version.h> | ||
| 42 | #if CYGWIN_VERSION_DLL_COMBINED > CYGWIN_VERSION_DLL_MAKE_COMBINED (1007, 7) | ||
| 43 | Lucky user | ||
| 44 | #endif | ||
| 45 | #else | ||
| 46 | Lucky user | ||
| 47 | #endif | ||
| 48 | ], | ||
| 49 | [gl_cv_func_strstr_works_always="guessing yes"], | ||
| 50 | [gl_cv_func_strstr_works_always="guessing no"]) | ||
| 51 | ]) | ||
| 52 | ]) | ||
| 53 | case "$gl_cv_func_strstr_works_always" in | ||
| 54 | *yes) ;; | ||
| 55 | *) | ||
| 56 | REPLACE_STRSTR=1 | ||
| 57 | ;; | ||
| 58 | esac | ||
| 15 | fi | 59 | fi |
| 16 | ]) # gl_FUNC_STRSTR_SIMPLE | 60 | ]) # gl_FUNC_STRSTR_SIMPLE |
| 17 | 61 | ||
| @@ -24,16 +68,18 @@ AC_DEFUN([gl_FUNC_STRSTR], | |||
| 24 | [gl_cv_func_strstr_linear], | 68 | [gl_cv_func_strstr_linear], |
| 25 | [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ | 69 | [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ |
| 26 | #include <signal.h> /* for signal */ | 70 | #include <signal.h> /* for signal */ |
| 27 | #include <string.h> /* for memmem */ | 71 | #include <string.h> /* for strstr */ |
| 28 | #include <stdlib.h> /* for malloc */ | 72 | #include <stdlib.h> /* for malloc */ |
| 29 | #include <unistd.h> /* for alarm */ | 73 | #include <unistd.h> /* for alarm */ |
| 30 | ]], [[size_t m = 1000000; | 74 | static void quit (int sig) { exit (sig + 128); } |
| 75 | ]], [[ | ||
| 76 | int result = 0; | ||
| 77 | size_t m = 1000000; | ||
| 31 | char *haystack = (char *) malloc (2 * m + 2); | 78 | char *haystack = (char *) malloc (2 * m + 2); |
| 32 | char *needle = (char *) malloc (m + 2); | 79 | char *needle = (char *) malloc (m + 2); |
| 33 | void *result = 0; | ||
| 34 | /* Failure to compile this test due to missing alarm is okay, | 80 | /* Failure to compile this test due to missing alarm is okay, |
| 35 | since all such platforms (mingw) also have quadratic strstr. */ | 81 | since all such platforms (mingw) also have quadratic strstr. */ |
| 36 | signal (SIGALRM, SIG_DFL); | 82 | signal (SIGALRM, quit); |
| 37 | alarm (5); | 83 | alarm (5); |
| 38 | /* Check for quadratic performance. */ | 84 | /* Check for quadratic performance. */ |
| 39 | if (haystack && needle) | 85 | if (haystack && needle) |
| @@ -44,36 +90,41 @@ AC_DEFUN([gl_FUNC_STRSTR], | |||
| 44 | memset (needle, 'A', m); | 90 | memset (needle, 'A', m); |
| 45 | needle[m] = 'B'; | 91 | needle[m] = 'B'; |
| 46 | needle[m + 1] = 0; | 92 | needle[m + 1] = 0; |
| 47 | result = strstr (haystack, needle); | 93 | if (!strstr (haystack, needle)) |
| 94 | result |= 1; | ||
| 48 | } | 95 | } |
| 49 | return !result;]])], | 96 | return result; |
| 97 | ]])], | ||
| 50 | [gl_cv_func_strstr_linear=yes], [gl_cv_func_strstr_linear=no], | 98 | [gl_cv_func_strstr_linear=yes], [gl_cv_func_strstr_linear=no], |
| 51 | [dnl Only glibc >= 2.9 and cygwin >= 1.7.0 are known to have a | 99 | [dnl Only glibc > 2.12 on processors without SSE 4.2 instructions and |
| 52 | dnl strstr that works in linear time. | 100 | dnl cygwin > 1.7.7 are known to have a bug-free strstr that works in |
| 101 | dnl linear time. | ||
| 53 | AC_EGREP_CPP([Lucky user], | 102 | AC_EGREP_CPP([Lucky user], |
| 54 | [ | 103 | [ |
| 55 | #include <features.h> | 104 | #include <features.h> |
| 56 | #ifdef __GNU_LIBRARY__ | 105 | #ifdef __GNU_LIBRARY__ |
| 57 | #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 9) || (__GLIBC__ > 2) | 106 | #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ > 12) || (__GLIBC__ > 2)) \ |
| 107 | && !(defined __i386__ || defined __x86_64__) \ | ||
| 108 | && !defined __UCLIBC__ | ||
| 58 | Lucky user | 109 | Lucky user |
| 59 | #endif | 110 | #endif |
| 60 | #endif | 111 | #endif |
| 61 | #ifdef __CYGWIN__ | 112 | #ifdef __CYGWIN__ |
| 62 | #include <cygwin/version.h> | 113 | #include <cygwin/version.h> |
| 63 | #if CYGWIN_VERSION_DLL_MAJOR >= 1007 | 114 | #if CYGWIN_VERSION_DLL_COMBINED > CYGWIN_VERSION_DLL_MAKE_COMBINED (1007, 7) |
| 64 | Lucky user | 115 | Lucky user |
| 65 | #endif | 116 | #endif |
| 66 | #endif | 117 | #endif |
| 67 | ], | 118 | ], |
| 68 | [gl_cv_func_strstr_linear=yes], | 119 | [gl_cv_func_strstr_linear="guessing yes"], |
| 69 | [gl_cv_func_strstr_linear="guessing no"]) | 120 | [gl_cv_func_strstr_linear="guessing no"]) |
| 70 | ]) | 121 | ]) |
| 71 | ]) | 122 | ]) |
| 72 | if test "$gl_cv_func_strstr_linear" != yes; then | 123 | case "$gl_cv_func_strstr_linear" in |
| 73 | REPLACE_STRSTR=1 | 124 | *yes) ;; |
| 74 | fi | 125 | *) |
| 75 | fi | 126 | REPLACE_STRSTR=1 |
| 76 | if test $REPLACE_STRSTR = 1; then | 127 | ;; |
| 77 | AC_LIBOBJ([strstr]) | 128 | esac |
| 78 | fi | 129 | fi |
| 79 | ]) # gl_FUNC_STRSTR | 130 | ]) # gl_FUNC_STRSTR |
