summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2020-09-22 23:29:24 +0200
committerDaniel Stenberg <daniel@haxx.se>2020-09-22 23:29:24 +0200
commit7df932f42c808d470cb227f3e9fe04252f83f6e0 (patch)
treec8d3f43c696bfbf512c9bcb96d435b7eda898c5d
parenta04956105836c3d05e763d0089f559b476d47464 (diff)
downloadcurl-bagder/dyn_addf-less-malloc.tar.gz
fixup provide the old solution for the tool codebagder/dyn_addf-less-malloc
... since it doesn't have access to the printf() internal function.
-rw-r--r--lib/dynbuf.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/dynbuf.c b/lib/dynbuf.c
index 152fac0d0..2dace3428 100644
--- a/lib/dynbuf.c
+++ b/lib/dynbuf.c
@@ -182,6 +182,7 @@ CURLcode Curl_dyn_add(struct dynbuf *s, const char *str)
CURLcode Curl_dyn_addf(struct dynbuf *s, const char *fmt, ...)
{
va_list ap;
+#ifdef BUILDING_LIBCURL
int rc;
va_start(ap, fmt);
rc = Curl_dyn_vprintf(s, fmt, ap);
@@ -189,10 +190,25 @@ CURLcode Curl_dyn_addf(struct dynbuf *s, const char *fmt, ...)
if(!rc)
return CURLE_OK;
+#else
+ char *str;
+ va_start(ap, fmt);
+ str = vaprintf(fmt, ap); /* this allocs a new string to append */
+ va_end(ap);
+ if(str) {
+ CURLcode result = dyn_nappend(s, (unsigned char *)str, strlen(str));
+ free(str);
+ return result;
+ }
+ /* If we failed, we cleanup the whole buffer and return error */
+ Curl_dyn_free(s);
+#endif
return CURLE_OUT_OF_MEMORY;
}
+
+
/*
* Returns a pointer to the buffer.
*/