aboutsummaryrefslogtreecommitdiffstats
path: root/strnstr.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 /strnstr.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 'strnstr.c')
-rw-r--r--strnstr.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/strnstr.c b/strnstr.c
new file mode 100644
index 0000000..df8708b
--- /dev/null
+++ b/strnstr.c
@@ -0,0 +1,17 @@
+/* See LICENSE file for copyright and license details. */
+#include "libsimple.h"
+
+
+char *
+libsimple_strnstr(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 (!strncmp(h, n, nn))
+ return h;
+ return NULL;
+}