diff options
author | Mattias Andrée <maandree@kth.se> | 2018-08-19 00:27:04 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2018-08-19 00:27:04 +0200 |
commit | bf3440c6c9a26644d77d2ebf0d24ac1583588ab7 (patch) | |
tree | 9b55597e3456efb17512c3cb8d3e250334d994b9 /strncasestr.c | |
parent | Fix and run tests (diff) | |
download | libsimple-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.c | 17 |
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; +} |