summaryrefslogtreecommitdiff
path: root/reftable/basics.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-10-02 12:55:30 +0200
committerJunio C Hamano <gitster@pobox.com>2024-10-02 07:53:51 -0700
commit7f0969febf974f017b92e7152a17c98105583167 (patch)
tree0895b55445927f523398528c8c152d2564652317 /reftable/basics.c
parenta5a15a4514f45c4ba8e901675951bfe551d77fae (diff)
reftable: introduce `reftable_strdup()`
The reftable library provides the ability to swap out allocators. There is a gap here though, because we continue to use `xstrdup()` even in the case where all the other allocators have been swapped out. Introduce `reftable_strdup()` that uses `reftable_malloc()` to do the allocation. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'reftable/basics.c')
-rw-r--r--reftable/basics.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/reftable/basics.c b/reftable/basics.c
index cf072935c8..4adc98cf5d 100644
--- a/reftable/basics.c
+++ b/reftable/basics.c
@@ -43,6 +43,16 @@ void *reftable_calloc(size_t nelem, size_t elsize)
return p;
}
+char *reftable_strdup(const char *str)
+{
+ size_t len = strlen(str);
+ char *result = reftable_malloc(len + 1);
+ if (!result)
+ return NULL;
+ memcpy(result, str, len + 1);
+ return result;
+}
+
void reftable_set_alloc(void *(*malloc)(size_t),
void *(*realloc)(void *, size_t), void (*free)(void *))
{