mirror of https://github.com/OpenTTD/OpenTTD
(svn r15371) -Codechange: add an implementation of strcasestr for when _GNU_SOURCE isn't defined.
parent
ba3d7e70f2
commit
35c5da08c5
|
@ -362,4 +362,18 @@ char *strndup(const char *s, size_t len)
|
||||||
memcpy(tmp, s, len);
|
memcpy(tmp, s, len);
|
||||||
return tmp;
|
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 */
|
#endif /* !_GNU_SOURCE */
|
||||||
|
|
|
@ -234,8 +234,9 @@ static inline bool IsWhitespace(WChar c)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _GNU_SOURCE
|
#ifndef _GNU_SOURCE
|
||||||
/* strndup is a GNU extension */
|
/* strndup and strcasestr are GNU extensions */
|
||||||
char *strndup(const char *s, size_t len);
|
char *strndup(const char *s, size_t len);
|
||||||
|
const char *strcasestr(const char *haystack, const char *needle);
|
||||||
#endif /* !_GNU_SOURCE */
|
#endif /* !_GNU_SOURCE */
|
||||||
|
|
||||||
#endif /* STRING_FUNC_H */
|
#endif /* STRING_FUNC_H */
|
||||||
|
|
Loading…
Reference in New Issue