summary refs log tree commit diff stats
path: root/include/qapi/util.h
diff options
context:
space:
mode:
authorSteve Sistare <steven.sistare@oracle.com>2024-02-27 16:33:19 +0100
committerMarkus Armbruster <armbru@redhat.com>2024-03-04 07:12:40 +0100
commit745736ae0cbe48dd7d58456baf084dc106320a87 (patch)
tree11ba3ad141f0b0c773a1c7450635918786ff64e3 /include/qapi/util.h
parent8a62ef7bd97c40e9f112d6c808898f907b11f65e (diff)
downloadfocaccia-qemu-745736ae0cbe48dd7d58456baf084dc106320a87.tar.gz
focaccia-qemu-745736ae0cbe48dd7d58456baf084dc106320a87.zip
qapi: New QAPI_LIST_LENGTH()
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20240227153321.467343-2-armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'include/qapi/util.h')
-rw-r--r--include/qapi/util.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/qapi/util.h b/include/qapi/util.h
index 81a2b13a33..20dfea8a54 100644
--- a/include/qapi/util.h
+++ b/include/qapi/util.h
@@ -56,4 +56,17 @@ int parse_qapi_name(const char *name, bool complete);
     (tail) = &(*(tail))->next; \
 } while (0)
 
+/*
+ * For any GenericList @list, return its length.
+ */
+#define QAPI_LIST_LENGTH(list)                                      \
+    ({                                                              \
+        size_t _len = 0;                                            \
+        typeof(list) _tail;                                         \
+        for (_tail = list; _tail != NULL; _tail = _tail->next) {    \
+            _len++;                                                 \
+        }                                                           \
+        _len;                                                       \
+    })
+
 #endif