]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/dict.c
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libavutil / dict.c
index 56f1513d32283224cc9377670a133682b823b588..74301fbf11205a94f83c9b6a7c6a46f8d1141882 100644 (file)
@@ -1,24 +1,25 @@
 /*
  * copyright (c) 2009 Michael Niedermayer
  *
- * This file is part of Libav.
+ * This file is part of FFmpeg.
  *
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #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++;