6d1baf2
diff -Nrup a/NEWS b/NEWS
6d1baf2
--- a/NEWS	2012-09-14 14:31:29.000000000 -0600
6d1baf2
+++ b/NEWS	2012-09-20 15:43:07.883932826 -0600
6d1baf2
@@ -9,7 +9,7 @@ Version 2.17
6d1baf2
 
6d1baf2
 * The following bugs are resolved with this release:
6d1baf2
 
6d1baf2
-  1349, 3479, 5400, 6778, 6808, 9685, 9914, 10014, 10038, 11607, 13412,
6d1baf2
+  1349, 3479, 5400, 6778, 6808, 9685, 9914, 10014, 10038, 13412,
6d1baf2
   13542, 13717, 13696, 13939, 13966, 14042, 14090, 14166, 14150, 14151,
6d1baf2
   14154, 14157, 14166, 14173, 14195, 14237, 14252, 14283, 14298, 14303,
6d1baf2
   14307, 14328, 14331, 14336, 14337, 14347, 14349, 14459, 14476, 14505,
6d1baf2
@@ -27,9 +27,6 @@ Version 2.17
6d1baf2
 * SystemTap static probes have been added into the dynamic linker.
6d1baf2
   Implemented by Gary Benson.
6d1baf2
 
6d1baf2
-* Optimizations of string functions strstr, strcasestr and memmem.
6d1baf2
-  Implemented by Maxim Kuvyrkov.
6d1baf2
-
6d1baf2
 * The minimum Linux kernel version that this version of the GNU C Library
6d1baf2
   can be used with is 2.6.16.
6d1baf2
 
6d1baf2
diff -Nrup a/string/Makefile b/string/Makefile
6d1baf2
--- a/string/Makefile	2012-09-14 14:31:29.000000000 -0600
6d1baf2
+++ b/string/Makefile	2012-09-20 15:42:02.189221257 -0600
6d1baf2
@@ -1,4 +1,4 @@
6d1baf2
-# Copyright (C) 1991-2002, 2005-2011, 2012 Free Software Foundation, Inc.
6d1baf2
+# Copyright (C) 1991-2002, 2005-2010, 2011 Free Software Foundation, Inc.
6d1baf2
 # This file is part of the GNU C Library.
6d1baf2
 
6d1baf2
 # The GNU C Library is free software; you can redistribute it and/or
6d1baf2
@@ -56,7 +56,9 @@ tests		:= tester inl-tester noinl-tester
6d1baf2
 		   tst-strtok tst-strxfrm bug-strcoll1 tst-strfry	\
6d1baf2
 		   bug-strtok1 $(addprefix test-,$(strop-tests))	\
6d1baf2
 		   bug-envz1 tst-strxfrm2 tst-endian tst-svc2		\
6d1baf2
-		   bug-strstr1 bug-strcasestr1 bug-strchr1 tst-strtok_r
6d1baf2
+		   bug-strstr1 bug-strchr1
6d1baf2
+distribute	:= memcopy.h pagecopy.h tst-svc.expect test-string.h	\
6d1baf2
+		   str-two-way.h
6d1baf2
 
6d1baf2
 
6d1baf2
 include ../Rules
6d1baf2
@@ -74,7 +76,6 @@ CFLAGS-stratcliff.c = -fno-builtin
6d1baf2
 CFLAGS-test-ffs.c = -fno-builtin
6d1baf2
 CFLAGS-tst-inlcall.c = -fno-builtin
6d1baf2
 CFLAGS-bug-strstr1.c = -fno-builtin
6d1baf2
-CFLAGS-bug-strcasestr1.c = -fno-builtin
6d1baf2
 
6d1baf2
 ifeq ($(cross-compiling),no)
6d1baf2
 tests: $(objpfx)tst-svc.out
6d1baf2
diff -Nrup a/string/bug-strcasestr1.c b/string/bug-strcasestr1.c
6d1baf2
--- a/string/bug-strcasestr1.c	2012-09-14 14:31:29.000000000 -0600
6d1baf2
+++ b/string/bug-strcasestr1.c	1969-12-31 17:00:00.000000000 -0700
6d1baf2
@@ -1,39 +0,0 @@
6d1baf2
-/* Test for non-submitted strcasestr bug.
6d1baf2
-   Copyright (C) 2012 Free Software Foundation, Inc.
6d1baf2
-   This file is part of the GNU C Library.
6d1baf2
-
6d1baf2
-   The GNU C Library is free software; you can redistribute it and/or
6d1baf2
-   modify it under the terms of the GNU Lesser General Public
6d1baf2
-   License as published by the Free Software Foundation; either
6d1baf2
-   version 2.1 of the License, or (at your option) any later version.
6d1baf2
-
6d1baf2
-   The GNU C Library is distributed in the hope that it will be useful,
6d1baf2
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
6d1baf2
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
6d1baf2
-   Lesser General Public License for more details.
6d1baf2
-
6d1baf2
-   You should have received a copy of the GNU Lesser General Public
6d1baf2
-   License along with the GNU C Library; if not, see
6d1baf2
-   <http://www.gnu.org/licenses/>.  */
6d1baf2
-
6d1baf2
-#include <stdio.h>
6d1baf2
-#include <string.h>
6d1baf2
-
6d1baf2
-#define TEST_FUNCTION do_test ()
6d1baf2
-static int
6d1baf2
-do_test (void)
6d1baf2
-{
6d1baf2
-  const char haystack[] = "AOKB";
6d1baf2
-  const char needle[] = "OK";
6d1baf2
-  const char *sub = strcasestr (haystack, needle);
6d1baf2
-
6d1baf2
-  if (sub == NULL)
6d1baf2
-    {
6d1baf2
-      fprintf (stderr, "BUG: didn't find \"%s\" in \"%s\"\n", needle, haystack);
6d1baf2
-      return 1;
6d1baf2
-    }
6d1baf2
-
6d1baf2
-  return 0;
6d1baf2
-}
6d1baf2
-
6d1baf2
-#include "../test-skeleton.c"
6d1baf2
diff -Nrup a/string/str-two-way.h b/string/str-two-way.h
6d1baf2
--- a/string/str-two-way.h	2012-09-14 14:31:29.000000000 -0600
6d1baf2
+++ b/string/str-two-way.h	2012-09-20 15:41:31.478356212 -0600
6d1baf2
@@ -1,5 +1,5 @@
6d1baf2
 /* Byte-wise substring search, using the Two-Way algorithm.
6d1baf2
-   Copyright (C) 2008-2012 Free Software Foundation, Inc.
6d1baf2
+   Copyright (C) 2008, 2010 Free Software Foundation, Inc.
6d1baf2
    This file is part of the GNU C Library.
6d1baf2
    Written by Eric Blake <ebb9@byu.net>, 2008.
6d1baf2
 
6d1baf2
@@ -43,7 +43,6 @@
6d1baf2
 
6d1baf2
 #include <limits.h>
6d1baf2
 #include <stdint.h>
6d1baf2
-#include <sys/param.h>                  /* Defines MAX.  */
6d1baf2
 
6d1baf2
 /* We use the Two-Way string matching algorithm, which guarantees
6d1baf2
    linear complexity with constant space.  Additionally, for long
6d1baf2
@@ -68,6 +67,10 @@
6d1baf2
 # define LONG_NEEDLE_THRESHOLD SIZE_MAX
6d1baf2
 #endif
6d1baf2
 
6d1baf2
+#ifndef MAX
6d1baf2
+# define MAX(a, b) ((a < b) ? (b) : (a))
6d1baf2
+#endif
6d1baf2
+
6d1baf2
 #ifndef CANON_ELEMENT
6d1baf2
 # define CANON_ELEMENT(c) c
6d1baf2
 #endif
6d1baf2
@@ -75,19 +78,6 @@
6d1baf2
 # define CMP_FUNC memcmp
6d1baf2
 #endif
6d1baf2
 
6d1baf2
-#ifndef AVAILABLE1
6d1baf2
-# define AVAILABLE1(h, h_l, j, n_l) AVAILABLE (h, h_l, j, n_l)
6d1baf2
-#endif
6d1baf2
-#ifndef AVAILABLE2
6d1baf2
-# define AVAILABLE2(h, h_l, j, n_l) (1)
6d1baf2
-#endif
6d1baf2
-#ifndef RET0_IF_0
6d1baf2
-# define RET0_IF_0(a) /* nothing */
6d1baf2
-#endif
6d1baf2
-#ifndef AVAILABLE1_USES_J
6d1baf2
-# define AVAILABLE1_USES_J (1)
6d1baf2
-#endif
6d1baf2
-
6d1baf2
 /* Perform a critical factorization of NEEDLE, of length NEEDLE_LEN.
6d1baf2
    Return the index of the first byte in the right half, and set
6d1baf2
    *PERIOD to the global period of the right half.
6d1baf2
@@ -243,24 +233,17 @@ two_way_short_needle (const unsigned cha
6d1baf2
       j = 0;
6d1baf2
       while (AVAILABLE (haystack, haystack_len, j, needle_len))
6d1baf2
 	{
6d1baf2
-	  const unsigned char *pneedle;
6d1baf2
-	  const unsigned char *phaystack;
6d1baf2
-
6d1baf2
 	  /* Scan for matches in right half.  */
6d1baf2
 	  i = MAX (suffix, memory);
6d1baf2
-	  pneedle = &needle[i];
6d1baf2
-	  phaystack = &haystack[i + j];
6d1baf2
-	  while (i < needle_len && (CANON_ELEMENT (*pneedle++)
6d1baf2
-				    == CANON_ELEMENT (*phaystack++)))
6d1baf2
+	  while (i < needle_len && (CANON_ELEMENT (needle[i])
6d1baf2
+				    == CANON_ELEMENT (haystack[i + j])))
6d1baf2
 	    ++i;
6d1baf2
 	  if (needle_len <= i)
6d1baf2
 	    {
6d1baf2
 	      /* Scan for matches in left half.  */
6d1baf2
 	      i = suffix - 1;
6d1baf2
-	      pneedle = &needle[i];
6d1baf2
-	      phaystack = &haystack[i + j];
6d1baf2
-	      while (memory < i + 1 && (CANON_ELEMENT (*pneedle--)
6d1baf2
-					== CANON_ELEMENT (*phaystack--)))
6d1baf2
+	      while (memory < i + 1 && (CANON_ELEMENT (needle[i])
6d1baf2
+					== CANON_ELEMENT (haystack[i + j])))
6d1baf2
 		--i;
6d1baf2
 	      if (i + 1 < memory + 1)
6d1baf2
 		return (RETURN_TYPE) (haystack + j);
6d1baf2
@@ -278,81 +261,32 @@ two_way_short_needle (const unsigned cha
6d1baf2
     }
6d1baf2
   else
6d1baf2
     {
6d1baf2
-      const unsigned char *phaystack = &haystack[suffix];
6d1baf2
-      /* The comparison always starts from needle[suffix], so cache it
6d1baf2
-	 and use an optimized first-character loop.  */
6d1baf2
-      unsigned char needle_suffix = CANON_ELEMENT (needle[suffix]);
6d1baf2
-
6d1baf2
       /* The two halves of needle are distinct; no extra memory is
6d1baf2
 	 required, and any mismatch results in a maximal shift.  */
6d1baf2
       period = MAX (suffix, needle_len - suffix) + 1;
6d1baf2
       j = 0;
6d1baf2
-      while (AVAILABLE1 (haystack, haystack_len, j, needle_len))
6d1baf2
+      while (AVAILABLE (haystack, haystack_len, j, needle_len))
6d1baf2
 	{
6d1baf2
-	  unsigned char haystack_char;
6d1baf2
-	  const unsigned char *pneedle;
6d1baf2
-
6d1baf2
-	  /* TODO: The first-character loop can be sped up by adapting
6d1baf2
-	     longword-at-a-time implementation of memchr/strchr.  */
6d1baf2
-	  if (needle_suffix
6d1baf2
-	      != (haystack_char = CANON_ELEMENT (*phaystack++)))
6d1baf2
-	    {
6d1baf2
-	      RET0_IF_0 (haystack_char);
6d1baf2
-#if AVAILABLE1_USES_J
6d1baf2
-	      ++j;
6d1baf2
-#endif
6d1baf2
-	      continue;
6d1baf2
-	    }
6d1baf2
-
6d1baf2
-#if !AVAILABLE1_USES_J
6d1baf2
-	  /* Calculate J if it wasn't kept up-to-date in the first-character
6d1baf2
-	     loop.  */
6d1baf2
-	  j = phaystack - &haystack[suffix] - 1;
6d1baf2
-#endif
6d1baf2
-
6d1baf2
 	  /* Scan for matches in right half.  */
6d1baf2
-	  i = suffix + 1;
6d1baf2
-	  pneedle = &needle[i];
6d1baf2
-	  while (i < needle_len)
6d1baf2
-	    {
6d1baf2
-	      if (CANON_ELEMENT (*pneedle++)
6d1baf2
-		  != (haystack_char = CANON_ELEMENT (*phaystack++)))
6d1baf2
-		{
6d1baf2
-		  RET0_IF_0 (haystack_char);
6d1baf2
-		  break;
6d1baf2
-		}
6d1baf2
-	      ++i;
6d1baf2
-	    }
6d1baf2
+	  i = suffix;
6d1baf2
+	  while (i < needle_len && (CANON_ELEMENT (needle[i])
6d1baf2
+				    == CANON_ELEMENT (haystack[i + j])))
6d1baf2
+	    ++i;
6d1baf2
 	  if (needle_len <= i)
6d1baf2
 	    {
6d1baf2
 	      /* Scan for matches in left half.  */
6d1baf2
 	      i = suffix - 1;
6d1baf2
-	      pneedle = &needle[i];
6d1baf2
-	      phaystack = &haystack[i + j];
6d1baf2
-	      while (i != SIZE_MAX)
6d1baf2
-		{
6d1baf2
-		  if (CANON_ELEMENT (*pneedle--)
6d1baf2
-		      != (haystack_char = CANON_ELEMENT (*phaystack--)))
6d1baf2
-		    {
6d1baf2
-		      RET0_IF_0 (haystack_char);
6d1baf2
-		      break;
6d1baf2
-		    }
6d1baf2
-		  --i;
6d1baf2
-		}
6d1baf2
+	      while (i != SIZE_MAX && (CANON_ELEMENT (needle[i])
6d1baf2
+				       == CANON_ELEMENT (haystack[i + j])))
6d1baf2
+		--i;
6d1baf2
 	      if (i == SIZE_MAX)
6d1baf2
 		return (RETURN_TYPE) (haystack + j);
6d1baf2
 	      j += period;
6d1baf2
 	    }
6d1baf2
 	  else
6d1baf2
 	    j += i - suffix + 1;
6d1baf2
-
6d1baf2
-	  if (!AVAILABLE2 (haystack, haystack_len, j, needle_len))
6d1baf2
-	    break;
6d1baf2
-
6d1baf2
-	  phaystack = &haystack[suffix + j];
6d1baf2
 	}
6d1baf2
     }
6d1baf2
- ret0: __attribute__ ((unused))
6d1baf2
   return NULL;
6d1baf2
 }
6d1baf2
 
6d1baf2
@@ -404,9 +338,6 @@ two_way_long_needle (const unsigned char
6d1baf2
       j = 0;
6d1baf2
       while (AVAILABLE (haystack, haystack_len, j, needle_len))
6d1baf2
 	{
6d1baf2
-	  const unsigned char *pneedle;
6d1baf2
-	  const unsigned char *phaystack;
6d1baf2
-
6d1baf2
 	  /* Check the last byte first; if it does not match, then
6d1baf2
 	     shift to the next possible match location.  */
6d1baf2
 	  shift = shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])];
6d1baf2
@@ -426,19 +357,15 @@ two_way_long_needle (const unsigned char
6d1baf2
 	  /* Scan for matches in right half.  The last byte has
6d1baf2
 	     already been matched, by virtue of the shift table.  */
6d1baf2
 	  i = MAX (suffix, memory);
6d1baf2
-	  pneedle = &needle[i];
6d1baf2
-	  phaystack = &haystack[i + j];
6d1baf2
-	  while (i < needle_len - 1 && (CANON_ELEMENT (*pneedle++)
6d1baf2
-					== CANON_ELEMENT (*phaystack++)))
6d1baf2
+	  while (i < needle_len - 1 && (CANON_ELEMENT (needle[i])
6d1baf2
+					== CANON_ELEMENT (haystack[i + j])))
6d1baf2
 	    ++i;
6d1baf2
 	  if (needle_len - 1 <= i)
6d1baf2
 	    {
6d1baf2
 	      /* Scan for matches in left half.  */
6d1baf2
 	      i = suffix - 1;
6d1baf2
-	      pneedle = &needle[i];
6d1baf2
-	      phaystack = &haystack[i + j];
6d1baf2
-	      while (memory < i + 1 && (CANON_ELEMENT (*pneedle--)
6d1baf2
-					== CANON_ELEMENT (*phaystack--)))
6d1baf2
+	      while (memory < i + 1 && (CANON_ELEMENT (needle[i])
6d1baf2
+					== CANON_ELEMENT (haystack[i + j])))
6d1baf2
 		--i;
6d1baf2
 	      if (i + 1 < memory + 1)
6d1baf2
 		return (RETURN_TYPE) (haystack + j);
6d1baf2
@@ -463,9 +390,6 @@ two_way_long_needle (const unsigned char
6d1baf2
       j = 0;
6d1baf2
       while (AVAILABLE (haystack, haystack_len, j, needle_len))
6d1baf2
 	{
6d1baf2
-	  const unsigned char *pneedle;
6d1baf2
-	  const unsigned char *phaystack;
6d1baf2
-
6d1baf2
 	  /* Check the last byte first; if it does not match, then
6d1baf2
 	     shift to the next possible match location.  */
6d1baf2
 	  shift = shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])];
6d1baf2
@@ -477,19 +401,15 @@ two_way_long_needle (const unsigned char
6d1baf2
 	  /* Scan for matches in right half.  The last byte has
6d1baf2
 	     already been matched, by virtue of the shift table.  */
6d1baf2
 	  i = suffix;
6d1baf2
-	  pneedle = &needle[i];
6d1baf2
-	  phaystack = &haystack[i + j];
6d1baf2
-	  while (i < needle_len - 1 && (CANON_ELEMENT (*pneedle++)
6d1baf2
-					== CANON_ELEMENT (*phaystack++)))
6d1baf2
+	  while (i < needle_len - 1 && (CANON_ELEMENT (needle[i])
6d1baf2
+					== CANON_ELEMENT (haystack[i + j])))
6d1baf2
 	    ++i;
6d1baf2
 	  if (needle_len - 1 <= i)
6d1baf2
 	    {
6d1baf2
 	      /* Scan for matches in left half.  */
6d1baf2
 	      i = suffix - 1;
6d1baf2
-	      pneedle = &needle[i];
6d1baf2
-	      phaystack = &haystack[i + j];
6d1baf2
-	      while (i != SIZE_MAX && (CANON_ELEMENT (*pneedle--)
6d1baf2
-				       == CANON_ELEMENT (*phaystack--)))
6d1baf2
+	      while (i != SIZE_MAX && (CANON_ELEMENT (needle[i])
6d1baf2
+				       == CANON_ELEMENT (haystack[i + j])))
6d1baf2
 		--i;
6d1baf2
 	      if (i == SIZE_MAX)
6d1baf2
 		return (RETURN_TYPE) (haystack + j);
6d1baf2
@@ -503,10 +423,6 @@ two_way_long_needle (const unsigned char
6d1baf2
 }
6d1baf2
 
6d1baf2
 #undef AVAILABLE
6d1baf2
-#undef AVAILABLE1
6d1baf2
-#undef AVAILABLE2
6d1baf2
-#undef AVAILABLE1_USES_J
6d1baf2
 #undef CANON_ELEMENT
6d1baf2
 #undef CMP_FUNC
6d1baf2
-#undef RET0_IF_0
6d1baf2
 #undef RETURN_TYPE
6d1baf2
diff -Nrup a/string/strcasestr.c b/string/strcasestr.c
6d1baf2
--- a/string/strcasestr.c	2012-09-14 14:31:29.000000000 -0600
6d1baf2
+++ b/string/strcasestr.c	2012-09-20 15:41:41.709311245 -0600
6d1baf2
@@ -1,5 +1,6 @@
6d1baf2
 /* Return the offset of one string within another.
6d1baf2
-   Copyright (C) 1994-2012 Free Software Foundation, Inc.
6d1baf2
+   Copyright (C) 1994, 1996-2000, 2004, 2008, 2009, 2010
6d1baf2
+   Free Software Foundation, Inc.
6d1baf2
    This file is part of the GNU C Library.
6d1baf2
 
6d1baf2
    The GNU C Library is free software; you can redistribute it and/or
6d1baf2
@@ -36,17 +37,13 @@
6d1baf2
 #include <stdbool.h>
6d1baf2
 #include <strings.h>
6d1baf2
 
6d1baf2
-#define TOLOWER(Ch) tolower (Ch)
6d1baf2
+#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
6d1baf2
 
6d1baf2
 /* Two-Way algorithm.  */
6d1baf2
 #define RETURN_TYPE char *
6d1baf2
 #define AVAILABLE(h, h_l, j, n_l)			\
6d1baf2
   (!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l))	\
6d1baf2
    && ((h_l) = (j) + (n_l)))
6d1baf2
-#define AVAILABLE1(h, h_l, j, n_l) (true)
6d1baf2
-#define AVAILABLE2(h, h_l, j, n_l) AVAILABLE (h, h_l, j, n_l)
6d1baf2
-#define RET0_IF_0(a) if (!a) goto ret0
6d1baf2
-#define AVAILABLE1_USES_J (0)
6d1baf2
 #define CANON_ELEMENT(c) TOLOWER (c)
6d1baf2
 #define CMP_FUNC(p1, p2, l)				\
6d1baf2
   __strncasecmp ((const char *) (p1), (const char *) (p2), l)
6d1baf2
diff -Nrup a/string/strstr.c b/string/strstr.c
6d1baf2
--- a/string/strstr.c	2012-09-14 14:31:29.000000000 -0600
6d1baf2
+++ b/string/strstr.c	2012-09-20 15:42:15.661162080 -0600
6d1baf2
@@ -1,5 +1,6 @@
6d1baf2
 /* Return the offset of one string within another.
6d1baf2
-   Copyright (C) 1994-2012 Free Software Foundation, Inc.
6d1baf2
+   Copyright (C) 1994,1996,1997,2000,2001,2003,2008,2009
6d1baf2
+   Free Software Foundation, Inc.
6d1baf2
    This file is part of the GNU C Library.
6d1baf2
 
6d1baf2
    The GNU C Library is free software; you can redistribute it and/or
6d1baf2
@@ -35,10 +36,6 @@
6d1baf2
 #define AVAILABLE(h, h_l, j, n_l)			\
6d1baf2
   (!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l))	\
6d1baf2
    && ((h_l) = (j) + (n_l)))
6d1baf2
-#define AVAILABLE1(h, h_l, j, n_l) (true)
6d1baf2
-#define AVAILABLE2(h, h_l, j, n_l) AVAILABLE (h, h_l, j, n_l)
6d1baf2
-#define RET0_IF_0(a) if (!a) goto ret0
6d1baf2
-#define AVAILABLE1_USES_J (0)
6d1baf2
 #include "str-two-way.h"
6d1baf2
 
6d1baf2
 #undef strstr