From 113ae25a3c3594e023e41dc3a48861089daea47f Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 14 Jan 2025 11:25:41 -0400 Subject: [PATCH] MT#55283 add extra bencode_strdup* primitives Change-Id: I54e108d276ebdb449227902efdaaf996d6c799a0 --- include/bencode.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/bencode.h b/include/bencode.h index c77cf58bd..8c60b2725 100644 --- a/include/bencode.h +++ b/include/bencode.h @@ -377,6 +377,21 @@ INLINE str bencode_strdup_str(bencode_buffer_t *buf, const char *s) { return o; } +INLINE str bencode_str_strdup(bencode_buffer_t *buf, const str *s) { + str o = *s; + o.s = bencode_buffer_alloc(buf, o.len); + memcpy(o.s, s->s, o.len); + return o; +} + +INLINE str *bencode_str_str_dup(bencode_buffer_t *buf, const str *s) { + str *o = bencode_buffer_alloc(buf, sizeof(*o)); + *o = *s; + o->s = bencode_buffer_alloc(buf, o->len); + memcpy(o->s, s->s, o->len); + return o; +} + INLINE bencode_item_t *bencode_dictionary_add(bencode_item_t *dict, const char *key, bencode_item_t *val) { if (!key) return NULL;