[v1,5/7] kvargs: add get by key function
Checks
Commit Message
Adds a new function to get value of a specific key from kvargs list.
Signed-off-by: Xueming Li <xuemingl@nvidia.com>
---
lib/librte_kvargs/rte_kvargs.c | 20 ++++++++++++++++++++
lib/librte_kvargs/rte_kvargs.h | 14 ++++++++++++++
lib/librte_kvargs/version.map | 1 +
3 files changed, 35 insertions(+)
@@ -160,6 +160,26 @@ rte_kvargs_free(struct rte_kvargs *kvlist)
free(kvlist);
}
+/* lookup the rte_kvargs structure by key */
+const char *
+rte_kvargs_get(struct rte_kvargs *kvlist, const char *key)
+{
+ unsigned int i;
+
+ if (!kvlist)
+ return NULL;
+ for (i = 0; i < kvlist->count; ++i) {
+ /* Allows key to be NULL. */
+ if (!key && !kvlist->pairs[i].key)
+ return kvlist->pairs[i].value;
+ if (!key || !kvlist->pairs[i].key)
+ continue;
+ if (!strcmp(kvlist->pairs[i].key, key))
+ return kvlist->pairs[i].value;
+ }
+ return NULL;
+}
+
/*
* Parse the arguments "key=value,key=value,..." string and return
* an allocated structure that contains a key/value list. Also
@@ -114,6 +114,20 @@ struct rte_kvargs *rte_kvargs_parse_delim(const char *args,
*/
void rte_kvargs_free(struct rte_kvargs *kvlist);
+/**
+ * Get the value matching the given key
+ *
+ * @param kvlist
+ * The rte_kvargs structure
+ * @param key
+ * The key that should match
+
+ * @return
+ * The value that match, NULL if not found.
+ */
+__rte_experimental
+const char *rte_kvargs_get(struct rte_kvargs *kvlist, const char *key);
+
/**
* Call a handler function for each key/value matching the key
*
@@ -14,5 +14,6 @@ EXPERIMENTAL {
rte_kvargs_parse_delim;
rte_kvargs_strcmp;
+ rte_kvargs_get;
};