Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAL3m8eCJfkbdR84sN7-HTkQbWkFHfvKKZAKpO8ajCDeh5wv00w@mail.gmail.com>
Date: Thu, 21 Feb 2013 10:40:38 -0500
From: Strake <strake888@...il.com>
To: musl <musl@...ts.openwall.com>
Subject: [PATCH] write strcasestr

>From 6a228eaf8bc2b3830c56bd2c8caa2ffa44245531 Mon Sep 17 00:00:00 2001
From: Strake <strake888@...il.com>
Date: Thu, 21 Feb 2013 10:41:09 -0500
Subject: [PATCH] write strcasestr

---
 src/string/strcasestr.c | 36 ++++++++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/src/string/strcasestr.c b/src/string/strcasestr.c
index f1cb0e8..c67c606 100644
--- a/src/string/strcasestr.c
+++ b/src/string/strcasestr.c
@@ -1,7 +1,35 @@
+#include <stdlib.h>
 #include <string.h>
+#include <wchar.h>
+#include <stdio.h>

-char *strcasestr(const char *h, const char *n)
-{
-	//FIXME!
-	return strstr(h, n);
+static void mbstolower (char *s) {
+	mbstate_t mbst;
+	wchar_t wx;
+	
+	while (*s) {
+		memset (&mbst, 0, sizeof (mbstate_t));
+		if (mbrtowc (&wx, s, MB_CUR_MAX, &mbst) < 0) break;
+		wx = towlower (wx);
+		memset (&mbst, 0, sizeof (mbstate_t));
+		s += wcrtomb (s, wx, &mbst);
+	}
+}
+
+char *strcasestr (const char *s, const char *t) {
+	char *x, *y, *z;
+	
+	x = strdup (s); if (!x) return 0;
+	y = strdup (t); if (!y) return 0;
+
+	mbstolower (x);
+	mbstolower (y);
+	
+	z = strstr (x, y);
+	if (z) s += z - x; else s = 0;
+	
+	free (x);
+	free (y);
+	
+	return s;
 }
-- 
1.7.11.3

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.