aboutsummaryrefslogtreecommitdiffstats
path: root/strrncasestr.c
diff options
context:
space:
mode:
Diffstat (limited to 'strrncasestr.c')
-rw-r--r--strrncasestr.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/strrncasestr.c b/strrncasestr.c
new file mode 100644
index 0000000..8fb0778
--- /dev/null
+++ b/strrncasestr.c
@@ -0,0 +1,23 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+
+
+char *
+libsimple_strrncasestr(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 (!strncasecmp(h, n, nn))
+ return h;
+ if (!strncasecmp(h, n, nn))
+ return h;
+ return NULL;
+}