From bf3440c6c9a26644d77d2ebf0d24ac1583588ab7 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 19 Aug 2018 00:27:04 +0200 Subject: Add str[r]n[case]str and str[n][case]cmpnul MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- strrnstr.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 strrnstr.c (limited to 'strrnstr.c') diff --git a/strrnstr.c b/strrnstr.c new file mode 100644 index 0000000..6a7b06e --- /dev/null +++ b/strrnstr.c @@ -0,0 +1,23 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsimple.h" + + +char * +libsimple_strrnstr(const char *h_, const char *n, size_t len) +{ + char *h = *(char **)(void *)&h_; + size_t hn = strlen(h); + size_t nn = strlen(n); + hn = MIN(hn, len); + nn = MIN(nn, len); + if (!nn) + return &h[hn]; + if (hn < nn) + return NULL; + for (h += hn -= nn; hn--; h--) + if (!strncmp(h, n, nn)) + return h; + if (!strncmp(h, n, nn)) + return h; + return NULL; +} -- cgit v1.2.3-70-g09d2