summaryrefslogtreecommitdiff
path: root/lib/librte_kvargs
diff options
context:
space:
mode:
authorGaetan Rivet <gaetan.rivet@6wind.com>2018-07-11 23:44:55 +0200
committerThomas Monjalon <thomas@monjalon.net>2018-07-15 23:42:22 +0200
commit5d6af85ab00c23f41429f335e462482093994b6e (patch)
tree544f16eabcd635e14669bf62264dd75d584f98f5 /lib/librte_kvargs
parent092ee516496dc8183c0944280484a6e5d923c7f3 (diff)
downloaddpdk-5d6af85ab00c23f41429f335e462482093994b6e.zip
dpdk-5d6af85ab00c23f41429f335e462482093994b6e.tar.gz
dpdk-5d6af85ab00c23f41429f335e462482093994b6e.tar.xz
kvargs: introduce a more flexible parsing function
This function permits defining additional terminating characters, ending the parsing to arbitrary delimiters. Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com> Acked-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
Diffstat (limited to 'lib/librte_kvargs')
-rw-r--r--lib/librte_kvargs/meson.build2
-rw-r--r--lib/librte_kvargs/rte_kvargs.c25
-rw-r--r--lib/librte_kvargs/rte_kvargs.h32
-rw-r--r--lib/librte_kvargs/rte_kvargs_version.map7
4 files changed, 66 insertions, 0 deletions
diff --git a/lib/librte_kvargs/meson.build b/lib/librte_kvargs/meson.build
index 0a81e8d..a1c7249 100644
--- a/lib/librte_kvargs/meson.build
+++ b/lib/librte_kvargs/meson.build
@@ -7,3 +7,5 @@ includes += include_directories('../../../lib/librte_eal/common/include')
version = 1
sources = files('rte_kvargs.c')
headers = files('rte_kvargs.h')
+
+deps += 'compat'
diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c
index 747f149..52262fe 100644
--- a/lib/librte_kvargs/rte_kvargs.c
+++ b/lib/librte_kvargs/rte_kvargs.c
@@ -168,3 +168,28 @@ rte_kvargs_parse(const char *args, const char * const valid_keys[])
return kvlist;
}
+
+__rte_experimental
+struct rte_kvargs *
+rte_kvargs_parse_delim(const char *args, const char * const valid_keys[],
+ const char *valid_ends)
+{
+ struct rte_kvargs *kvlist = NULL;
+ char *copy;
+ size_t len;
+
+ if (valid_ends == NULL)
+ return rte_kvargs_parse(args, valid_keys);
+
+ copy = strdup(args);
+ if (copy == NULL)
+ return NULL;
+
+ len = strcspn(copy, valid_ends);
+ copy[len] = '\0';
+
+ kvlist = rte_kvargs_parse(copy, valid_keys);
+
+ free(copy);
+ return kvlist;
+}
diff --git a/lib/librte_kvargs/rte_kvargs.h b/lib/librte_kvargs/rte_kvargs.h
index 51b8120..7f32fd1 100644
--- a/lib/librte_kvargs/rte_kvargs.h
+++ b/lib/librte_kvargs/rte_kvargs.h
@@ -25,6 +25,8 @@
extern "C" {
#endif
+#include <rte_compat.h>
+
/** Maximum number of key/value associations */
#define RTE_KVARGS_MAX 32
@@ -72,6 +74,36 @@ struct rte_kvargs *rte_kvargs_parse(const char *args,
const char *const valid_keys[]);
/**
+ * Allocate a rte_kvargs and store key/value associations from a string.
+ * This version will consider any byte from valid_ends as a possible
+ * terminating character, and will not parse beyond any of their occurrence.
+ *
+ * The function allocates and fills an rte_kvargs structure from a given
+ * string whose format is key1=value1,key2=value2,...
+ *
+ * The structure can be freed with rte_kvargs_free().
+ *
+ * @param args
+ * The input string containing the key/value associations
+ *
+ * @param valid_keys
+ * A list of valid keys (table of const char *, the last must be NULL).
+ * This argument is ignored if NULL
+ *
+ * @param valid_ends
+ * Acceptable terminating characters.
+ * If NULL, the behavior is the same as ``rte_kvargs_parse``.
+ *
+ * @return
+ * - A pointer to an allocated rte_kvargs structure on success
+ * - NULL on error
+ */
+__rte_experimental
+struct rte_kvargs *rte_kvargs_parse_delim(const char *args,
+ const char *const valid_keys[],
+ const char *valid_ends);
+
+/**
* Free a rte_kvargs structure
*
* Free a rte_kvargs structure previously allocated with
diff --git a/lib/librte_kvargs/rte_kvargs_version.map b/lib/librte_kvargs/rte_kvargs_version.map
index 2030ec4..afce125 100644
--- a/lib/librte_kvargs/rte_kvargs_version.map
+++ b/lib/librte_kvargs/rte_kvargs_version.map
@@ -8,3 +8,10 @@ DPDK_2.0 {
local: *;
};
+
+EXPERIMENTAL {
+ global:
+
+ rte_kvargs_parse_delim;
+
+} DPDK_2.0;