From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com [209.85.128.196]) by dpdk.org (Postfix) with ESMTP id 3A3111BE8A for ; Wed, 4 Jul 2018 00:15:53 +0200 (CEST) Received: by mail-wr0-f196.google.com with SMTP id f16-v6so3389823wrm.3 for ; Tue, 03 Jul 2018 15:15:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=jGyq3YX/SpzlLJhCRUQjjB5lz8oMEzUUbU6w4qfpCyY=; b=hhplUCRLut3htZGNt8+wwv++IPsFxCSt16owVaVQpddyntwxeht3izSc2iteTNDw72 040sCvCfJ/Sv3N7dWbrE/QHvKrvMEvsRP00LpvMPqR2M/QD8IDB9ibmAKtqNJtCSgx/Y MHByeltflWjWD/CNgHoe+KqiY6wZFN1t8sClFwmWP+mtMzte0w5EZJSKGmHS/3UDXQxV KZz/IOY7s5L0p2TtVqfJtcq6wqnSifAZGu2UwxqJVUJvhgcpcHPWBkxAlSvVYw8ijP5l g4XNTiPOFRjh6JEWzrIUiarg5Y0YSAuAHJt4MSEIClNZoag+IZ1lnCOAV/sHBPATLYz8 zv8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=jGyq3YX/SpzlLJhCRUQjjB5lz8oMEzUUbU6w4qfpCyY=; b=UNOW72dNruM0QMzMyLrqqaDIkLWgOJDG69/JFtB1Qi+AK59XDrt2lmoiozSM+z1MYI zM2X7KNN876cGOkG3KJm8nWXsT2Cid/rLHpQZolQsKU3am7+ZG5c/Qbij/9T8cSXZ+0r nNWlZJFvOH38qaJdZ6OyAYrooxh1tRT7no8IX9MXX7MHmi9vT8sytDfylX1qkRVL32bE foC5+COTfyslUqZx3aSvRCGeOnPIvfRBtYTBuvYZp43zcBrYQBJWZSb5OUIcfGSlZvl/ D2LNMMy9lARz51u7MfRXmDT0p/pigVDSoYPKrH7LYPBNGS2C60oJErzCXld2QHam9aKI 8t3g== X-Gm-Message-State: APt69E3j9egjUgtokkMAUtOsnGpXFlNky8kQTBOlFTUpWCFDPRA0mkFT EYWleJ/J6zR+dwWhQIMRxgTFTQ5g X-Google-Smtp-Source: AAOMgpeqifw12A3F8S8VZGvqEPVV09FwSFPFZrGepjHipEGIgNS3RRK1LZIE0ogmrlNEOJ6wUnDL9g== X-Received: by 2002:adf:ff49:: with SMTP id u9-v6mr6777255wrs.15.1530656152526; Tue, 03 Jul 2018 15:15:52 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id i190-v6sm3771084wmd.33.2018.07.03.15.15.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Jul 2018 15:15:51 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Wed, 4 Jul 2018 00:14:57 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v9 14/27] kvargs: add generic string matching callback X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Jul 2018 22:15:53 -0000 This function can be used as a callback to rte_kvargs_process. This should reduce code duplication. Signed-off-by: Gaetan Rivet --- lib/librte_kvargs/rte_kvargs.c | 10 ++++++++++ lib/librte_kvargs/rte_kvargs.h | 28 ++++++++++++++++++++++++++++ lib/librte_kvargs/rte_kvargs_version.map | 1 + 3 files changed, 39 insertions(+) diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c index 519f77679..8270d2939 100644 --- a/lib/librte_kvargs/rte_kvargs.c +++ b/lib/librte_kvargs/rte_kvargs.c @@ -193,3 +193,13 @@ rte_kvargs_parse2(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 98c4ed1bf..ac2999ef3 100644 --- a/lib/librte_kvargs/rte_kvargs.h +++ b/lib/librte_kvargs/rte_kvargs.h @@ -25,6 +25,8 @@ extern "C" { #endif +#include + /** Maximum number of key/value associations */ #define RTE_KVARGS_MAX 32 @@ -151,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 b9fe44b98..6a41a6b65 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_parse2; + rte_kvargs_strcmp; } DPDK_2.0; -- 2.11.0