summaryrefslogtreecommitdiff
path: root/libavutil/dict.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2011-06-04 18:43:05 +0200
committerAnton Khirnov <anton@khirnov.net>2011-06-16 20:24:56 +0200
commit1b9b37b8a416e77b4c6425dcdcee21cf8a1f5d67 (patch)
tree5c6bf4eb04ef6c8a74cce412b8f2c5196d787aee /libavutil/dict.c
parent25de5958c8fd727777ebf8c4f7a9df6f9b8eb82d (diff)
dict: add AV_DICT_APPEND flag.
Diffstat (limited to 'libavutil/dict.c')
-rw-r--r--libavutil/dict.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/libavutil/dict.c b/libavutil/dict.c
index 56f1513d32..3ea7e55b30 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -19,6 +19,7 @@
*/
#include <strings.h>
+#include "avstring.h"
#include "dict.h"
#include "internal.h"
#include "mem.h"
@@ -51,6 +52,7 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags
{
AVDictionary *m = *pm;
AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);
+ char *oldval = NULL;
if(!m)
m = *pm = av_mallocz(sizeof(*m));
@@ -58,7 +60,10 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags
if(tag) {
if (flags & AV_DICT_DONT_OVERWRITE)
return 0;
- av_free(tag->value);
+ if (flags & AV_DICT_APPEND)
+ oldval = tag->value;
+ else
+ av_free(tag->value);
av_free(tag->key);
*tag = m->elems[--m->count];
} else {
@@ -75,6 +80,12 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags
m->elems[m->count].key = av_strdup(key );
if (flags & AV_DICT_DONT_STRDUP_VAL) {
m->elems[m->count].value = value;
+ } else if (oldval && flags & AV_DICT_APPEND) {
+ int len = strlen(oldval) + strlen(value) + 1;
+ if (!(oldval = av_realloc(oldval, len)))
+ return AVERROR(ENOMEM);
+ av_strlcat(oldval, value, len);
+ m->elems[m->count].value = oldval;
} else
m->elems[m->count].value = av_strdup(value);
m->count++;