summaryrefslogtreecommitdiff
path: root/libc/string/strstr.c
diff options
context:
space:
mode:
authorDavid McCullough <davidm@snapgear.com>2001-07-04 11:29:02 +0000
committerDavid McCullough <davidm@snapgear.com>2001-07-04 11:29:02 +0000
commitf5fc8d4321de6a8cd913bafde705993d96a5e820 (patch)
tree089bb21da63f63a76a4534cbc040aea854d10cb1 /libc/string/strstr.c
parent0d85794e9b8a873a44a373d4936c5c26e1a574c9 (diff)
Added stpcpy and strcasestr along with some code to test them.
Diffstat (limited to 'libc/string/strstr.c')
-rw-r--r--libc/string/strstr.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/libc/string/strstr.c b/libc/string/strstr.c
index b1890559b..6742e69cb 100644
--- a/libc/string/strstr.c
+++ b/libc/string/strstr.c
@@ -25,6 +25,7 @@
* as much fun trying to understand it, as I had to write it :-).
*
* Stephen R. van den Berg, berg@pool.informatik.rwth-aachen.de */
+/* added strcasestr support, davidm@lineo.com */
#if HAVE_CONFIG_H
# include <config.h>
@@ -36,9 +37,26 @@
typedef unsigned chartype;
+#if defined(L_strstr)
+
+#define VAL(x) (x)
+#define FUNC strstr
#undef strstr
-char *strstr( const char *phaystack, const char *pneedle)
+#elif defined(L_strcasestr)
+
+#include <ctype.h>
+#define VAL(x) tolower(x)
+#define FUNC strcasestr
+#undef strcasestr
+
+#else
+
+#error "No target function defined."
+
+#endif
+
+char * FUNC ( const char *phaystack, const char *pneedle)
{
register const unsigned char *haystack, *needle;
register chartype b, c;
@@ -54,7 +72,7 @@ char *strstr( const char *phaystack, const char *pneedle)
if (c == '\0')
goto ret0;
}
- while (c != b);
+ while (VAL(c) != VAL(b));
c = *++needle;
if (c == '\0')
@@ -70,39 +88,39 @@ char *strstr( const char *phaystack, const char *pneedle)
a = *++haystack;
if (a == '\0')
goto ret0;
- if (a == b)
+ if (VAL(a) == VAL(b))
break;
a = *++haystack;
if (a == '\0')
goto ret0;
shloop:}
- while (a != b);
+ while (VAL(a) != VAL(b));
jin:a = *++haystack;
if (a == '\0')
goto ret0;
- if (a != c)
+ if (VAL(a) != VAL(c))
goto shloop;
rhaystack = haystack-- + 1;
rneedle = needle;
a = *rneedle;
- if (*rhaystack == a)
+ if (VAL(*rhaystack) == VAL(a))
do {
if (a == '\0')
goto foundneedle;
++rhaystack;
a = *++needle;
- if (*rhaystack != a)
+ if (VAL(*rhaystack) != VAL(a))
break;
if (a == '\0')
goto foundneedle;
++rhaystack;
a = *++needle;
}
- while (*rhaystack == a);
+ while (VAL(*rhaystack) == VAL(a));
needle = rneedle; /* took the register-poor approach */