summaryrefslogtreecommitdiff
path: root/lib/librte_kvargs
diff options
context:
space:
mode:
authorGaetan Rivet <gaetan.rivet@6wind.com>2018-07-11 23:45:02 +0200
committerThomas Monjalon <thomas@monjalon.net>2018-07-15 23:44:22 +0200
commita3b85476c51ee54e7e5d228b09ba702d2b20e6fb (patch)
tree2cc7da25f488898a8196d8513ee73e9fa26057e8 /lib/librte_kvargs
parentac1a511eff3ff92bf2a2aef3cfb74d63ab1eeac8 (diff)
downloaddpdk-a3b85476c51ee54e7e5d228b09ba702d2b20e6fb.zip
dpdk-a3b85476c51ee54e7e5d228b09ba702d2b20e6fb.tar.gz
dpdk-a3b85476c51ee54e7e5d228b09ba702d2b20e6fb.tar.xz
kvargs: add generic string matching callback
This function can be used as a callback to rte_kvargs_process. This should reduce code duplication. Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
Diffstat (limited to 'lib/librte_kvargs')
-rw-r--r--lib/librte_kvargs/rte_kvargs.c10
-rw-r--r--lib/librte_kvargs/rte_kvargs.h26
-rw-r--r--lib/librte_kvargs/rte_kvargs_version.map1
3 files changed, 37 insertions, 0 deletions
diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c
index 52262fe..a28f769 100644
--- a/lib/librte_kvargs/rte_kvargs.c
+++ b/lib/librte_kvargs/rte_kvargs.c
@@ -193,3 +193,13 @@ rte_kvargs_parse_delim(const char *args, const char * const valid_keys[],
free(copy);
return kvlist;
}
+
+__rte_experimental
+int
+rte_kvargs_strcmp(const char *key __rte_unused,
+ const char *value, void *opaque)
+{
+ const char *str = opaque;
+
+ return -abs(strcmp(str, value));
+}
diff --git a/lib/librte_kvargs/rte_kvargs.h b/lib/librte_kvargs/rte_kvargs.h
index 7f32fd1..fc04195 100644
--- a/lib/librte_kvargs/rte_kvargs.h
+++ b/lib/librte_kvargs/rte_kvargs.h
@@ -153,6 +153,32 @@ int rte_kvargs_process(const struct rte_kvargs *kvlist,
unsigned rte_kvargs_count(const struct rte_kvargs *kvlist,
const char *key_match);
+/**
+ * Generic kvarg handler for string comparison.
+ *
+ * This function can be used for a generic string comparison processing
+ * on a list of kvargs.
+ *
+ * @param key
+ * kvarg pair key.
+ *
+ * @param value
+ * kvarg pair value.
+ *
+ * @param opaque
+ * Opaque pointer to a string.
+ *
+ * @return
+ * 0 if the strings match.
+ * !0 otherwise or on error.
+ *
+ * Unless strcmp, comparison ordering is not kept.
+ * In order for rte_kvargs_process to stop processing on match error,
+ * a negative value is returned even if strcmp had returned a positive one.
+ */
+__rte_experimental
+int rte_kvargs_strcmp(const char *key, const char *value, void *opaque);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/librte_kvargs/rte_kvargs_version.map b/lib/librte_kvargs/rte_kvargs_version.map
index afce125..8f4b4e3 100644
--- a/lib/librte_kvargs/rte_kvargs_version.map
+++ b/lib/librte_kvargs/rte_kvargs_version.map
@@ -13,5 +13,6 @@ EXPERIMENTAL {
global:
rte_kvargs_parse_delim;
+ rte_kvargs_strcmp;
} DPDK_2.0;