add bencode_string(_len)?_dup functions

remotes/origin/HEAD
Richard Fuchs 12 years ago
parent 16b33debeb
commit 3ef68b85e6

@ -212,6 +212,14 @@ static bencode_item_t *__bencode_string_alloc(bencode_buffer_t *buf, const void
return ret;
}
bencode_item_t *bencode_string_len_dup(bencode_buffer_t *buf, const char *s, int len) {
char *sd = __bencode_alloc(buf, len);
if (!sd)
return NULL;
memcpy(sd, s, len);
return bencode_string_len(buf, sd, len);
}
bencode_item_t *bencode_string_len(bencode_buffer_t *buf, const char *s, int len) {
return __bencode_string_alloc(buf, s, len, len, 1, BENCODE_STRING);
}

@ -150,6 +150,11 @@ bencode_item_t *bencode_string_len(bencode_buffer_t *buf, const char *s, int len
* to bencode_string_len(). */
static inline bencode_item_t *bencode_string(bencode_buffer_t *buf, const char *s);
/* Identical to the above two functions, but copies the string into the bencode_buffer_t object.
* Thus, the given string doesn't have to remain valid and accessible afterwards. */
bencode_item_t *bencode_string_len_dup(bencode_buffer_t *buf, const char *s, int len);
static inline bencode_item_t *bencode_string_dup(bencode_buffer_t *buf, const char *s);
/* Creates a new byte-string object from a "str" object. The string does not have to be null-
* terminated. */
static inline bencode_item_t *bencode_str(bencode_buffer_t *buf, const str *s);
@ -336,6 +341,10 @@ static inline bencode_item_t *bencode_string(bencode_buffer_t *buf, const char *
return bencode_string_len(buf, s, strlen(s));
}
static inline bencode_item_t *bencode_string_dup(bencode_buffer_t *buf, const char *s) {
return bencode_string_len_dup(buf, s, strlen(s));
}
static inline bencode_item_t *bencode_str(bencode_buffer_t *buf, const str *s) {
return bencode_string_len(buf, s->s, s->len);
}

Loading…
Cancel
Save