Browse Source

add bencode_string(_len)?_dup functions

git.mgm/mediaproxy-ng/2.2
Richard Fuchs 13 years ago
parent
commit
3ef68b85e6
2 changed files with 17 additions and 0 deletions
  1. +8
    -0
      daemon/bencode.c
  2. +9
    -0
      daemon/bencode.h

+ 8
- 0
daemon/bencode.c View File

@ -212,6 +212,14 @@ static bencode_item_t *__bencode_string_alloc(bencode_buffer_t *buf, const void
return ret; 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) { 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); return __bencode_string_alloc(buf, s, len, len, 1, BENCODE_STRING);
} }


+ 9
- 0
daemon/bencode.h View File

@ -150,6 +150,11 @@ bencode_item_t *bencode_string_len(bencode_buffer_t *buf, const char *s, int len
* to bencode_string_len(). */ * to bencode_string_len(). */
static inline bencode_item_t *bencode_string(bencode_buffer_t *buf, const char *s); 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- /* Creates a new byte-string object from a "str" object. The string does not have to be null-
* terminated. */ * terminated. */
static inline bencode_item_t *bencode_str(bencode_buffer_t *buf, const str *s); 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)); 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) { static inline bencode_item_t *bencode_str(bencode_buffer_t *buf, const str *s) {
return bencode_string_len(buf, s->s, s->len); return bencode_string_len(buf, s->s, s->len);
} }


Loading…
Cancel
Save