http-parser.c

Small C library to parse HTTP requests
Log | Files | Refs | README | LICENSE

commit c76974f3f16f063f554a5bed0f734933029c6c3e
parent 515fd9168d936d6ae630482d8ef3293be6f61728
Author: finwo <finwo@pm.me>
Date:   Sun, 13 Aug 2023 21:43:49 +0200

Move strnstr into dedicated package

Diffstat:
Mpackage.ini | 1+
Msrc/http-parser.c | 25+------------------------
2 files changed, 2 insertions(+), 24 deletions(-)

diff --git a/package.ini b/package.ini @@ -1,4 +1,5 @@ [dependencies] +finwo/str_extra=https://github.com/finwo/c-strextra/archive/refs/tags/edge.tar.gz tidwall/buf=https://raw.githubusercontent.com/finwo/dep-repository/main/tidwall/buf/package.ini [export] config.mk=config.mk diff --git a/src/http-parser.c b/src/http-parser.c @@ -7,6 +7,7 @@ extern "C" { #include <string.h> #include <strings.h> +#include "finwo/strnstr.h" #include "tidwall/buf.h" #include "http-parser.h" @@ -47,30 +48,6 @@ int xtoi(char *str) { return sign * i; } - -// Origin: https://stackoverflow.com/a/25705264/2928176 -// Author: Chris Dodd (https://stackoverflow.com/users/16406/chris-dodd) -char *strnstr(const char *haystack, const char *needle, size_t len) { - int i; - size_t needle_len; - - if (0 == (needle_len = strnlen(needle, len))) { - return NULL; - } - - for (i=0; i<=(int)(len-needle_len); i++) { - if ( - (haystack[0] == needle[0]) && - (0 == strncmp(haystack, needle, needle_len)) - ) { - return (char *)haystack; - } - haystack++; - } - - return NULL; -} - /** * Frees everything in a header that was malloc'd by http-parser */