#include /* for signal */ #include /* for strstr */ #include /* for malloc */ #include /* for alarm */ static void quit (int sig) { exit (sig + 128); } int main () { int result = 0; size_t m = 1000000; char *haystack = (char *) malloc (2 * m + 2); char *needle = (char *) malloc (m + 2); /* Failure to compile this test due to missing alarm is okay, since all such platforms (mingw) also have quadratic strstr. */ signal (SIGALRM, quit); alarm (5); /* Check for quadratic performance. */ if (haystack && needle) { memset (haystack, 'A', 2 * m); haystack[2 * m] = 'B'; haystack[2 * m + 1] = 0; memset (needle, 'A', m); needle[m] = 'B'; needle[m + 1] = 0; if (!strstr (haystack, needle)) result |= 1; } return result; ; return 0; }