summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-02-06 11:58:52 +0000
committerrubidium <rubidium@openttd.org>2009-02-06 11:58:52 +0000
commit35c5da08c5417c73fdad4d5602ba3f112759e25b (patch)
tree92ebbd45ce250d7e2bab43cb459aa838e68ab0b1
parentba3d7e70f2b9961c8094a23b9decf28ef8111e7c (diff)
downloadopenttd-35c5da08c5417c73fdad4d5602ba3f112759e25b.tar.xz
(svn r15371) -Codechange: add an implementation of strcasestr for when _GNU_SOURCE isn't defined.
-rw-r--r--src/string.cpp14
-rw-r--r--src/string_func.h3
2 files changed, 16 insertions, 1 deletions
diff --git a/src/string.cpp b/src/string.cpp
index 8b22937ae..289031cfc 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -362,4 +362,18 @@ char *strndup(const char *s, size_t len)
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 */
diff --git a/src/string_func.h b/src/string_func.h
index bf7159751..c63fc6719 100644
--- a/src/string_func.h
+++ b/src/string_func.h
@@ -234,8 +234,9 @@ static inline bool IsWhitespace(WChar c)
}
#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 */