aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2018-10-23 16:34:46 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2018-10-24 11:24:55 +0000
commitbdf7d8570f73564ad2513c29c577c4d35d70b32b (patch)
tree7846553033dfdb5a408112b145f16dfb92d124db
parentcd4d1ca0f47d934b683a0246163ef486cbb61ace (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.c14
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;
}