[FFmpeg-cvslog] dict: add AV_DICT_APPEND flag.

Anton Khirnov git at videolan.org
Sat Jun 18 05:18:40 CEST 2011


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sat Jun  4 18:43:05 2011 +0200| [1b9b37b8a416e77b4c6425dcdcee21cf8a1f5d67] | committer: Anton Khirnov

dict: add AV_DICT_APPEND flag.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1b9b37b8a416e77b4c6425dcdcee21cf8a1f5d67
---

 libavutil/dict.c |   13 ++++++++++++-
 libavutil/dict.h |    2 ++
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/libavutil/dict.c b/libavutil/dict.c
index 56f1513..3ea7e55 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++;
diff --git a/libavutil/dict.h b/libavutil/dict.h
index bfd7f26..ff24b36 100644
--- a/libavutil/dict.h
+++ b/libavutil/dict.h
@@ -29,6 +29,8 @@
 #define AV_DICT_DONT_STRDUP_KEY 4
 #define AV_DICT_DONT_STRDUP_VAL 8
 #define AV_DICT_DONT_OVERWRITE 16   ///< Don't overwrite existing entries.
+#define AV_DICT_APPEND         32   /**< If the entry already exists, append to it.  Note that no
+                                      delimiter is added, the strings are simply concatenated. */
 
 typedef struct {
     char *key;



More information about the ffmpeg-cvslog mailing list