summaryrefslogtreecommitdiff
path: root/src/libposixplz
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-09-22 15:28:36 +0000
committerLaurent Bercot <ska@appnovation.com>2023-09-22 15:28:36 +0000
commit753ceac3272a8c4f150ace8b4695991a85345c3c (patch)
treef9e62f7d544f634bc6e8b13b194f10182c980d91 /src/libposixplz
parentaebe8604605b41803c43c1def87549569b821b27 (diff)
downloadskalibs-753ceac3272a8c4f150ace8b4695991a85345c3c.tar.xz
Revamp case functions, add strcasestr() fallback
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libposixplz')
-rw-r--r--src/libposixplz/strcasestr.c28
1 files changed, 28 insertions, 0 deletions
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 <skalibs/sysdeps.h>
+
+#ifndef SKALIBS_HASSTRCASESTR
+
+#include <string.h>
+
+#include <skalibs/bytestr.h>
+
+ /* 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