commit 65c8c8d536348fdda19b9e931f1a0412c2118242
parent bd9f907d88b706c05c9e1e0e3958f8625b5b26cb
Author: Kris Maglione <kris@suckless.org>
Date: Tue, 10 Aug 2010 05:46:00 -0400
Fix strcasestr.
Diffstat:
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/include/stuff/util.h b/include/stuff/util.h
@@ -151,5 +151,5 @@ void vector_##c##push(Vector_##nam*, type); \
VECTOR(long, long, l)
VECTOR(Rectangle, rect, r)
VECTOR(void*, ptr, p)
-#undef VECTOR
+#undef VECTOR
diff --git a/lib/libstuff/util/strcasestr.c b/lib/libstuff/util/strcasestr.c
@@ -9,17 +9,17 @@
/* TODO: Make this UTF-8 compliant. */
char*
strcasestr(const char *dst, const char *src) {
- int dc, sc;
- int len;
+ int len, dc, sc;
+
+ if(src[0] == '\0')
+ return (char*)(uintptr_t)dst;
len = strlen(src) - 1;
- for(; (sc = *src) && *dst; src++) {
- sc = tolower(dc);
- for(; (dc = *dst); dst++) {
- dc = tolower(dc);
- if(sc == dc && !strncasecmp(dst+1, src+1, len))
- return (char*)(uintptr_t)dst;
- }
+ sc = tolower(src[0]);
+ for(; (dc = *dst); dst++) {
+ dc = tolower(dc);
+ if(sc == dc && (len == 0 || !strncasecmp(dst+1, src+1, len)))
+ return (char*)(uintptr_t)dst;
}
return nil;
}