From 50f09c33f521338ffad771b8e7c4f794114fe09d Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 30 Mar 2023 11:50:25 -0400 Subject: [PATCH] MT#56447 add bencode_strdup_str Change-Id: I89bd03a9a926a1c5d399fe13eda592b46951bcdb --- include/bencode.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/bencode.h b/include/bencode.h index 7bc6de11a..434036a86 100644 --- a/include/bencode.h +++ b/include/bencode.h @@ -89,6 +89,9 @@ INLINE bencode_buffer_t *bencode_item_buffer(bencode_item_t *); /* like strdup() but uses the bencode buffer to store the string */ INLINE char *bencode_strdup(bencode_buffer_t *, const char *); +/* ditto but inits a str object */ +INLINE void bencode_strdup_str(bencode_buffer_t *, str *, const char *); + @@ -378,6 +381,12 @@ INLINE char *bencode_strdup(bencode_buffer_t *buf, const char *s) { return ret; } +INLINE void bencode_strdup_str(bencode_buffer_t *buf, str *o, const char *s) { + o->len = strlen(s); + o->s = bencode_buffer_alloc(buf, o->len); + memcpy(o->s, s, o->len); +} + INLINE bencode_item_t *bencode_dictionary_add(bencode_item_t *dict, const char *key, bencode_item_t *val) { if (!key) return NULL;