summaryrefslogtreecommitdiff
path: root/libavutil/dict.c
diff options
context:
space:
mode:
authorMarvin Scholz <epirat07@gmail.com>2022-09-24 16:36:55 +0200
committerAnton Khirnov <anton@khirnov.net>2022-11-06 08:26:48 +0100
commit9dad2379283cbf5842cff14c0e34b97958698201 (patch)
tree341872e33a014c5af126bc3e5bd1fc3532194eff /libavutil/dict.c
parentaa3d98227e88f316f56aa73a5c6356e3949e9808 (diff)
downloadffmpeg-9dad2379283cbf5842cff14c0e34b97958698201.tar.gz
avutil/dict: Add av_dict_iterate
This is a more explicit iteration API rather than using the "magic" av_dict_get(d, "", t, AV_DICT_IGNORE_SUFFIX) which is not really trivial to grasp what it does when casually reading through code. Signed-off-by: Anton Khirnov <anton@khirnov.net>
Diffstat (limited to 'libavutil/dict.c')
-rw-r--r--libavutil/dict.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/libavutil/dict.c b/libavutil/dict.c
index 14ad780a79..ee059d712c 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -20,6 +20,7 @@
#include <string.h>
+#include "avassert.h"
#include "avstring.h"
#include "dict.h"
#include "dict_internal.h"
@@ -38,6 +39,24 @@ int av_dict_count(const AVDictionary *m)
return m ? m->count : 0;
}
+const AVDictionaryEntry *av_dict_iterate(const AVDictionary *m,
+ const AVDictionaryEntry *prev)
+{
+ int i = 0;
+
+ if (!m)
+ return NULL;
+
+ if (prev)
+ i = prev - m->elems + 1;
+
+ av_assert2(i >= 0);
+ if (i >= m->count)
+ return NULL;
+
+ return &m->elems[i];
+}
+
AVDictionaryEntry *av_dict_get(const AVDictionary *m, const char *key,
const AVDictionaryEntry *prev, int flags)
{