From 753ceac3272a8c4f150ace8b4695991a85345c3c Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 22 Sep 2023 15:28:36 +0000 Subject: Revamp case functions, add strcasestr() fallback Signed-off-by: Laurent Bercot --- src/libposixplz/strcasestr.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/libposixplz/strcasestr.c (limited to 'src/libposixplz/strcasestr.c') diff --git a/src/libposixplz/strcasestr.c b/src/libposixplz/strcasestr.c new file mode 100644 index 0000000..2347267 --- /dev/null +++ b/src/libposixplz/strcasestr.c @@ -0,0 +1,28 @@ +/* ISC license. */ + +#include + +#ifndef SKALIBS_HASSTRCASESTR + +#include + +#include + + /* XXX: copies strings on the stack, careful with long strings */ + +char *strcasestr (char const *haystack, char const *needle) +{ + size_t nlen = strlen(needle) ; + size_t hlen = strlen(haystack) ; + char *p ; + char lneedle[nlen + 1] ; + char lhaystack[hlen + 1] ; + memcpy(lneedle, needle, nlen + 1) ; + memcpy(lhaystack, haystack, hlen + 1) ; + case_lowerb(lneedle, nlen) ; + case_lowerb(lhaystack, hlen) ; + p = strstr(lhaystack, lneedle) ; + return p ? haystack + (p - lhaystack) : 0 ; +} + +#endif -- cgit v1.3.1