From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7F2B2A0A03; Mon, 18 Jan 2021 16:17:15 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 00388140F43; Mon, 18 Jan 2021 16:16:56 +0100 (CET) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by mails.dpdk.org (Postfix) with ESMTP id 9C485140F20 for ; Mon, 18 Jan 2021 16:16:50 +0100 (CET) Received: from Internal Mail-Server by MTLPINE1 (envelope-from xuemingl@nvidia.com) with SMTP; 18 Jan 2021 17:16:49 +0200 Received: from nvidia.com (pegasus05.mtr.labs.mlnx [10.210.16.100]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 10IFGmBo002238; Mon, 18 Jan 2021 17:16:49 +0200 From: Xueming Li To: Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko , Olivier Matz Cc: dev@dpdk.org, Viacheslav Ovsiienko , xuemingl@nvidia.com, Asaf Penso Date: Mon, 18 Jan 2021 15:16:40 +0000 Message-Id: <1610983002-7630-4-git-send-email-xuemingl@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1610983002-7630-1-git-send-email-xuemingl@nvidia.com> References: <1610983002-7630-1-git-send-email-xuemingl@nvidia.com> In-Reply-To: <1608304614-13908-2-git-send-email-xuemingl@nvidia.com> References: <1608304614-13908-2-git-send-email-xuemingl@nvidia.com> Subject: [dpdk-dev] [PATCH v2 3/5] kvargs: add get by key function X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Adds a new function to get value of a specific key from kvargs list. Signed-off-by: Xueming Li --- 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(+) diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c index 285081c86c..bc734915f9 100644 --- a/lib/librte_kvargs/rte_kvargs.c +++ b/lib/librte_kvargs/rte_kvargs.c @@ -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 diff --git a/lib/librte_kvargs/rte_kvargs.h b/lib/librte_kvargs/rte_kvargs.h index eff598e08b..6d426241ea 100644 --- a/lib/librte_kvargs/rte_kvargs.h +++ b/lib/librte_kvargs/rte_kvargs.h @@ -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 * diff --git a/lib/librte_kvargs/version.map b/lib/librte_kvargs/version.map index ed375bf4a3..d6cde16f30 100644 --- a/lib/librte_kvargs/version.map +++ b/lib/librte_kvargs/version.map @@ -14,5 +14,6 @@ EXPERIMENTAL { rte_kvargs_parse_delim; rte_kvargs_strcmp; + rte_kvargs_get; }; -- 2.25.1