diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-09-22 15:28:36 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-09-22 15:28:36 +0000 |
commit | 753ceac3272a8c4f150ace8b4695991a85345c3c (patch) | |
tree | f9e62f7d544f634bc6e8b13b194f10182c980d91 /src/libposixplz/strcasestr.c | |
parent | aebe8604605b41803c43c1def87549569b821b27 (diff) | |
download | skalibs-753ceac3272a8c4f150ace8b4695991a85345c3c.tar.xz |
Revamp case functions, add strcasestr() fallback
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libposixplz/strcasestr.c')
-rw-r--r-- | src/libposixplz/strcasestr.c | 28 |
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 |