changeset 11031:8c0c440e51c6 draft

(svn r15371) -Codechange: add an implementation of strcasestr for when _GNU_SOURCE isn't defined.
author rubidium <rubidium@openttd.org>
date Fri, 06 Feb 2009 11:58:52 +0000
parents 8ea72967ad79
children 7726de732236
files src/string.cpp src/string_func.h
diffstat 2 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -362,4 +362,18 @@
 	memcpy(tmp, s, len);
 	return tmp;
 }
+
+const char *strcasestr(const char *haystack, const char *needle)
+{
+	size_t hay_len = strlen(haystack);
+	size_t needle_len = strlen(needle);
+	while (hay_len >= needle_len) {
+		if (strncasecmp(haystack, needle, needle_len) == 0) return haystack;
+
+		haystack++;
+		hay_len--;
+	}
+
+	return NULL;
+}
 #endif /* !_GNU_SOURCE */
--- a/src/string_func.h
+++ b/src/string_func.h
@@ -234,8 +234,9 @@
 }
 
 #ifndef _GNU_SOURCE
-/* strndup is a GNU extension */
+/* strndup and strcasestr are GNU extensions */
 char *strndup(const char *s, size_t len);
+const char *strcasestr(const char *haystack, const char *needle);
 #endif /* !_GNU_SOURCE */
 
 #endif /* STRING_FUNC_H */