summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2020-09-09 15:41:05 +0200
committerDaniel Stenberg <daniel@haxx.se>2020-09-14 08:32:35 +0200
commitc4ea71ae3235cca8c6837f48664d587e52eb32d2 (patch)
tree82c0afc9373001c9386f1c6ec66fc080c8bfd501
parent9fffe925d2049d925dbc4b52beda5b35c7b3aaa5 (diff)
downloadcurl-c4ea71ae3235cca8c6837f48664d587e52eb32d2.tar.gz
dynbuf: provide curlx_ names for reuse by the curl tool
Closes #5946
-rw-r--r--lib/dynbuf.c13
-rw-r--r--lib/dynbuf.h16
2 files changed, 24 insertions, 5 deletions
diff --git a/lib/dynbuf.c b/lib/dynbuf.c
index 265a769e8..5e15040bb 100644
--- a/lib/dynbuf.c
+++ b/lib/dynbuf.c
@@ -21,12 +21,11 @@
***************************************************************************/
#include "curl_setup.h"
-#include "strdup.h"
#include "dynbuf.h"
-
-/* The last 3 #include files should be in this order */
#include "curl_printf.h"
+#ifdef BUILDING_LIBCURL
#include "curl_memory.h"
+#endif
#include "memdebug.h"
#define MIN_FIRST_ALLOC 32
@@ -94,11 +93,15 @@ static CURLcode dyn_nappend(struct dynbuf *s,
}
if(a != s->allc) {
- s->bufr = Curl_saferealloc(s->bufr, a);
- if(!s->bufr) {
+ /* this logic is not using Curl_saferealloc() to make the tool not have to
+ include that as well when it uses this code */
+ void *p = realloc(s->bufr, a);
+ if(!p) {
+ Curl_safefree(s->bufr);
s->leng = s->allc = 0;
return CURLE_OUT_OF_MEMORY;
}
+ s->bufr = p;
s->allc = a;
}
diff --git a/lib/dynbuf.h b/lib/dynbuf.h
index ecc995755..1360dd432 100644
--- a/lib/dynbuf.h
+++ b/lib/dynbuf.h
@@ -22,6 +22,22 @@
*
***************************************************************************/
+#ifndef BUILDING_LIBCURL
+/* this renames the functions so that the tool code can use the same code
+ without getting symbol collisions */
+#define Curl_dyn_init(a,b) curlx_dyn_init(a,b)
+#define Curl_dyn_add(a,b) curlx_dyn_add(a,b)
+#define Curl_dyn_addn(a,b,c) curlx_dyn_addn(a,b,c)
+#define Curl_dyn_addf curlx_dyn_addf
+#define Curl_dyn_free(a) curlx_dyn_free(a)
+#define Curl_dyn_ptr(a) curlx_dyn_ptr(a)
+#define Curl_dyn_uptr(a) curlx_dyn_uptr(a)
+#define Curl_dyn_len(a) curlx_dyn_len(a)
+#define Curl_dyn_reset(a) curlx_dyn_reset(a)
+#define Curl_dyn_tail(a,b) curlx_dyn_tail(a,b)
+#define curlx_dynbuf dynbuf /* for the struct name */
+#endif
+
struct dynbuf {
char *bufr; /* point to a null-terminated allocated buffer */
size_t leng; /* number of bytes *EXCLUDING* the zero terminator */