http-parser.c

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

commit 1bf7e72b573aaf8355a5037577b832ad839f5eec
parent c76974f3f16f063f554a5bed0f734933029c6c3e
Author: finwo <finwo@pm.me>
Date:   Tue, 24 Oct 2023 00:12:16 +0200

Added polyfill for asprintf when _GNU_SOURCE is not defined

Diffstat:
Msrc/http-parser.c | 14++++++++++++++
1 file changed, 14 insertions(+), 0 deletions(-)

diff --git a/src/http-parser.c b/src/http-parser.c @@ -2,6 +2,7 @@ extern "C" { #endif +#include <stdarg.h> #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -48,6 +49,19 @@ int xtoi(char *str) { return sign * i; } +#ifndef _GNU_SOURCE +// Polyfill asprintf, comes from stdio when _GNU_SOURCE is defined +char * asprintf(char **restrict strp, const char *restrict fmt, ...) { + va_list argptr; + va_start(argptr, fmt); + int size = vsnprintf(NULL, 0, fmt, argptr); + char *output = calloc(1, size + 1); + vsnprintf(output, size + 1, fmt, argptr); + va_end(argptr); + return output; +} +#endif + /** * Frees everything in a header that was malloc'd by http-parser */