From bdf7d8570f73564ad2513c29c577c4d35d70b32b Mon Sep 17 00:00:00 2001 From: José Bollo Date: Tue, 23 Oct 2018 16:34:46 +0200 Subject: curl-wrap: Tiny optimization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Breaks the dependency to asprintf. Change-Id: I60fae81e0052b430a69277069907ec6b7ede8048 Signed-off-by: José Bollo --- src/curl-wrap.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/curl-wrap.c b/src/curl-wrap.c index 3c566a3..9f010fb 100644 --- a/src/curl-wrap.c +++ b/src/curl-wrap.c @@ -170,10 +170,16 @@ int curl_wrap_add_header_value(CURL *curl, const char *name, const char *value) { char *h; int rc; - - rc = asprintf(&h, "%s: %s", name, value); - rc = rc < 0 ? 0 : curl_wrap_add_header(curl, h); - free(h); + size_t sname, svalue; + + sname = strlen(name); + svalue = strlen(value); + h = alloca(sname + svalue + 3); + memcpy(h, name, sname); + h[sname] = ':'; + h[sname + 1] = ' '; + memcpy(h + sname + 2, value, svalue + 1); + rc = curl_wrap_add_header(curl, h); return rc; } -- cgit 1.2.3-korg