diff options
author | José Bollo <jose.bollo@iot.bzh> | 2018-10-23 16:34:46 +0200 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2018-10-24 11:24:55 +0000 |
commit | bdf7d8570f73564ad2513c29c577c4d35d70b32b (patch) | |
tree | 7846553033dfdb5a408112b145f16dfb92d124db | |
parent | cd4d1ca0f47d934b683a0246163ef486cbb61ace (diff) |
curl-wrap: Tiny optimization
Breaks the dependency to asprintf.
Change-Id: I60fae81e0052b430a69277069907ec6b7ede8048
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r-- | src/curl-wrap.c | 14 |
1 files changed, 10 insertions, 4 deletions
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; } |