--------------------- PatchSet 6195 Date: 2004/04/06 13:04:37 Author: rhorstmann Branch: icap-2_5 Tag: (none) Log: added configure/Makefile check for strcasestr function. if not available, lib/strcasestr.c is used (copied from glibc) Members: include/util.h:1.10.30.1->1.10.30.2 lib/Makefile.am:1.4.26.1->1.4.26.2 lib/strcasestr.c:1.1->1.1.2.1 Index: squid/include/util.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/util.h,v retrieving revision 1.10.30.1 retrieving revision 1.10.30.2 diff -u -r1.10.30.1 -r1.10.30.2 --- squid/include/util.h 17 Oct 2003 19:53:10 -0000 1.10.30.1 +++ squid/include/util.h 6 Apr 2004 13:04:37 -0000 1.10.30.2 @@ -1,5 +1,5 @@ /* - * $Id: util.h,v 1.10.30.1 2003/10/17 19:53:10 dwsquid Exp $ + * $Id: util.h,v 1.10.30.2 2004/04/06 13:04:37 rhorstmann Exp $ * * AUTHOR: Harvest Derived * @@ -136,4 +136,8 @@ extern char *strnstr(const char *haystack, const char *needle, size_t haystacklen); #endif +#ifndef HAVE_STRCASESTR +extern char *strcasestr(const char *haystack, const char *needle); +#endif + #endif /* SQUID_UTIL_H */ Index: squid/lib/Makefile.am =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/Makefile.am,v retrieving revision 1.4.26.1 retrieving revision 1.4.26.2 diff -u -r1.4.26.1 -r1.4.26.2 --- squid/lib/Makefile.am 17 Oct 2003 19:53:10 -0000 1.4.26.1 +++ squid/lib/Makefile.am 6 Apr 2004 13:04:38 -0000 1.4.26.2 @@ -15,6 +15,12 @@ STRNSTRSOURCE= endif +if NEED_OWN_STRCASESTR +STRCASESTRSOURCE=strcasestr.c +else +STRCASESTRSOURCE= +endif + if NEED_OWN_MD5 MD5SOURCE=md5.c else @@ -51,6 +57,7 @@ splay.c \ Stack.c \ $(STRNSTRSOURCE) \ + $(STRCASESTRSOURCE) \ stub_memaccount.c \ util.c \ uudecode.c --- /dev/null Wed Feb 14 01:09:44 2007 +++ squid/lib/strcasestr.c Wed Feb 14 01:09:46 2007 @@ -0,0 +1,126 @@ +/* Return the offset of one string within another. + Copyright (C) 1994,1996,1997,1998,1999,2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* + * My personal strstr() implementation that beats most other algorithms. + * Until someone tells me otherwise, I assume that this is the + * fastest implementation of strstr() in C. + * I deliberately chose not to comment it. You should have at least + * as much fun trying to understand it, as I had to write it :-). + * + * Stephen R. van den Berg, berg@pool.informatik.rwth-aachen.de */ + +/* + * modified to work outside of glibc (rhorstmann, 06/04/2004) + */ + +#include "config.h" +#ifndef HAVE_STRCASESTR +#include + +typedef unsigned chartype; + +char * +strcasestr (phaystack, pneedle) + const char *phaystack; + const char *pneedle; +{ + register const unsigned char *haystack, *needle; + register chartype b, c; + + haystack = (const unsigned char *) phaystack; + needle = (const unsigned char *) pneedle; + + b = tolower (*needle); + if (b != '\0') + { + haystack--; /* possible ANSI violation */ + do + { + c = *++haystack; + if (c == '\0') + goto ret0; + } + while (tolower (c) != (int) b); + + c = tolower (*++needle); + if (c == '\0') + goto foundneedle; + ++needle; + goto jin; + + for (;;) + { + register chartype a; + register const unsigned char *rhaystack, *rneedle; + + do + { + a = *++haystack; + if (a == '\0') + goto ret0; + if (tolower (a) == (int) b) + break; + a = *++haystack; + if (a == '\0') + goto ret0; +shloop: + ; + } + while (tolower (a) != (int) b); + +jin: a = *++haystack; + if (a == '\0') + goto ret0; + + if (tolower (a) != (int) c) + goto shloop; + + rhaystack = haystack-- + 1; + rneedle = needle; + a = tolower (*rneedle); + + if (tolower (*rhaystack) == (int) a) + do + { + if (a == '\0') + goto foundneedle; + ++rhaystack; + a = tolower (*++needle); + if (tolower (*rhaystack) != (int) a) + break; + if (a == '\0') + goto foundneedle; + ++rhaystack; + a = tolower (*++needle); + } + while (tolower (*rhaystack) == (int) a); + + needle = rneedle; /* took the register-poor approach */ + + if (a == '\0') + break; + } + } +foundneedle: + return (char*) haystack; +ret0: + return 0; +} +#endif