aboutsummaryrefslogtreecommitdiffstats
path: root/strncasestr.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-08-19 00:27:04 +0200
committerMattias Andrée <maandree@kth.se>2018-08-19 00:27:04 +0200
commitbf3440c6c9a26644d77d2ebf0d24ac1583588ab7 (patch)
tree9b55597e3456efb17512c3cb8d3e250334d994b9 /strncasestr.c
parentFix and run tests (diff)
downloadlibsimple-bf3440c6c9a26644d77d2ebf0d24ac1583588ab7.tar.gz
libsimple-bf3440c6c9a26644d77d2ebf0d24ac1583588ab7.tar.bz2
libsimple-bf3440c6c9a26644d77d2ebf0d24ac1583588ab7.tar.xz
Add str[r]n[case]str and str[n][case]cmpnul
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--strncasestr.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/strncasestr.c b/strncasestr.c
new file mode 100644
index 0000000..cd7fd8a
--- /dev/null
+++ b/strncasestr.c
@@ -0,0 +1,17 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+
+
+char *
+libsimple_strncasestr(const char *h_, const char *n, size_t len)
+{
+ char *h = *(char **)(void *)&h_;
+ size_t nn = strlen(n);
+ nn = MIN(nn, len);
+ if (!nn)
+ return h;
+ for (; *h && len--; h++)
+ if (!strncasecmp(h, n, nn))
+ return h;
+ return NULL;
+}