From: Olivier Matz Date: Tue, 28 Jan 2014 16:06:43 +0000 (+0100) Subject: kvargs: make the NULL key to match all entries X-Git-Tag: spdx-start~10962 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=38a901702fdfde778d50b2f123c562a66c394f87;p=dpdk.git kvargs: make the NULL key to match all entries In rte_kvargs_process() and rte_kvargs_count(), if the key_match argument is NULL, process all entries. Signed-off-by: Olivier Matz Acked-by: Bruce Richardson --- diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c index c41a01688e..a7586a3166 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 94003e20d6..71c9630d9d 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