[dpdk-dev] [PATCH 10/11] kvargs: make the NULL key to match all entries
Olivier Matz
olivier.matz at 6wind.com
Tue Jan 28 17:06:43 CET 2014
In rte_kvargs_process() and rte_kvargs_count(), if the key_match
argument is NULL, process all entries.
Signed-off-by: Olivier Matz <olivier.matz at 6wind.com>
---
lib/librte_kvargs/rte_kvargs.c | 4 ++--
lib/librte_kvargs/rte_kvargs.h | 5 +++--
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c
index 1ff7056..3d65437 100644
--- a/lib/librte_kvargs/rte_kvargs.c
+++ b/lib/librte_kvargs/rte_kvargs.c
@@ -139,7 +139,7 @@ rte_kvargs_count(const struct rte_kvargs *kvlist, const char *key_match)
ret = 0;
for (i = 0; i < kvlist->count; i++) {
pair = &kvlist->pairs[i];
- if (strcmp(pair->key, key_match) == 0)
+ if (key_match == NULL || strcmp(pair->key, key_match) == 0)
ret++;
}
@@ -160,7 +160,7 @@ rte_kvargs_process(const struct rte_kvargs *kvlist,
for (i = 0; i < kvlist->count; i++) {
pair = &kvlist->pairs[i];
- if (strcmp(pair->key, key_match) == 0) {
+ if (key_match == NULL || strcmp(pair->key, key_match) == 0) {
if ((*handler)(pair->key, pair->value, opaque_arg) < 0)
return -1;
}
diff --git a/lib/librte_kvargs/rte_kvargs.h b/lib/librte_kvargs/rte_kvargs.h
index c080c06..e375547 100644
--- a/lib/librte_kvargs/rte_kvargs.h
+++ b/lib/librte_kvargs/rte_kvargs.h
@@ -120,7 +120,8 @@ void rte_kvargs_free(struct rte_kvargs *kvlist);
* @param kvlist
* The rte_kvargs structure
* @param key_match
- * The key on which the handler should be called
+ * The key on which the handler should be called, or NULL to process handler
+ * on all associations
* @param handler
* The function to call for each matching key
* @param opaque_arg
@@ -139,7 +140,7 @@ int rte_kvargs_process(const struct rte_kvargs *kvlist,
* @param kvlist
* The rte_kvargs structure
* @param key_match
- * The key that should match
+ * The key that should match, or NULL to count all associations
* @return
* The number of entries
--
1.8.4.rc3
More information about the dev
mailing list