summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorVladimír Čunát <vladimir.cunat@nic.cz>2024-09-01 11:01:22 +0200
committerVladimír Čunát <vladimir.cunat@nic.cz>2024-09-06 12:26:37 +0200
commit9215892b5722e2ab42d93ea9f466c6fc2fd97414 (patch)
treeedea8e65acb07805395163b841f8d62432ec8a49 /lib
parentMerge !1602: daemon: remove -f/--forks (diff)
downloadknot-resolver-9215892b5722e2ab42d93ea9f466c6fc2fd97414.tar.xz
knot-resolver-9215892b5722e2ab42d93ea9f466c6fc2fd97414.zip
lib/utils: generalize kr_strcatdup() for mempools
It's trivial really, and I'd like to use it now.
Diffstat (limited to 'lib')
-rw-r--r--lib/utils.c4
-rw-r--r--lib/utils.h6
2 files changed, 6 insertions, 4 deletions
diff --git a/lib/utils.c b/lib/utils.c
index d04f5467..882aeb3e 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -107,7 +107,7 @@ static inline int u16tostr(uint8_t *dst, uint16_t num)
return 5;
}
-char* kr_strcatdup(unsigned n, ...)
+char* kr_strcatdup_pool(knot_mm_t *pool, unsigned n, ...)
{
if (n < 1) {
return NULL;
@@ -132,7 +132,7 @@ char* kr_strcatdup(unsigned n, ...)
char *result = NULL;
if (total_len > 0) {
if (unlikely(total_len == SIZE_MAX)) return NULL;
- result = malloc(total_len + 1);
+ result = mm_alloc(pool, total_len + 1);
}
if (result) {
char *stream = result;
diff --git a/lib/utils.h b/lib/utils.h
index e03b473d..e8122c99 100644
--- a/lib/utils.h
+++ b/lib/utils.h
@@ -170,9 +170,11 @@ typedef struct kr_http_header_array_entry {
/** Array of HTTP headers for DoH. */
typedef array_t(kr_http_header_array_entry_t) kr_http_header_array_t;
-/** Concatenate N strings. */
+/** Concatenate N strings and put the result into a mempool. */
KR_EXPORT
-char* kr_strcatdup(unsigned n, ...);
+char* kr_strcatdup_pool(knot_mm_t *pool, unsigned n, ...);
+/** Concatenate N strings. */
+#define kr_strcatdup(n, ...) kr_strcatdup_pool(NULL, n, ## __VA_ARGS__)
/** Construct absolute file path, without resolving symlinks.
* \return malloc-ed string or NULL (+errno in that case) */