strcasestr.c.patch   [plain text]


--- strcasestr.c.bsdnew	2009-11-18 18:24:33.000000000 -0800
+++ strcasestr.c	2009-11-18 18:24:33.000000000 -0800
@@ -33,6 +33,8 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD: src/lib/libc/string/strcasestr.c,v 1.5 2009/02/03 17:58:20 danger Exp $");
 
+#include "xlocale_private.h"
+
 #include <ctype.h>
 #include <string.h>
 
@@ -40,21 +42,30 @@ __FBSDID("$FreeBSD: src/lib/libc/string/
  * Find the first occurrence of find in s, ignore case.
  */
 char *
-strcasestr(const char *s, const char *find)
+strcasestr_l(s, find, loc)
+	const char *s, *find;
+	locale_t loc;
 {
 	char c, sc;
 	size_t len;
 
+	NORMALIZE_LOCALE(loc);
 	if ((c = *find++) != 0) {
-		c = tolower((unsigned char)c);
+		c = tolower_l((unsigned char)c, loc);
 		len = strlen(find);
 		do {
 			do {
 				if ((sc = *s++) == 0)
 					return (NULL);
-			} while ((char)tolower((unsigned char)sc) != c);
-		} while (strncasecmp(s, find, len) != 0);
+			} while ((char)tolower_l((unsigned char)sc, loc) != c);
+		} while (strncasecmp_l(s, find, len, loc) != 0);
 		s--;
 	}
 	return ((char *)s);
 }
+
+char *
+strcasestr(const char *s, const char *find)
+{
+	return strcasestr_l(s, find, __current_locale());
+}