From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by dpdk.org (Postfix) with ESMTP id 8318E1BED9 for ; Thu, 5 Jul 2018 13:49:15 +0200 (CEST) Received: by mail-wm0-f68.google.com with SMTP id b188-v6so10645864wme.3 for ; Thu, 05 Jul 2018 04:49:15 -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; bh=ro5b/V/df5FS4FmkLaHb19yi4/xQrxaDntciNRLw1E8=; b=IPlNdmKKQ0NcBfpyjoTjvaFsLVt3D9XpD/HDv9Fgwv+TF1Cdkhn+7sydHKBIkX5Eo9 z+yDBRUGWvL8ovkgsMuwnh4tZ0TxZ/XfccAfPXG6h2SJqo+kP6j2FhKNLXHp87oZ8u7n SnYCYCaHuNqGLNO6hSnG4scSDn+7Jt6QSKmmVYsbapui6ilVOPX03/l6TnrV0dbNdka7 farKGuXP8hq5XYzz+q/wewiKElXk1++vFG+tybNb8tmX7wR3yeKLmzXGKho9ec+OoyIS rSNJxhFWvK+o0LdH1JR9D0TZS943Oiqe11pE5jXiKhAM0jznKcYoWD4eysAO+hLfmJqR c9WA== 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; bh=ro5b/V/df5FS4FmkLaHb19yi4/xQrxaDntciNRLw1E8=; b=RwiRjixHVHj9BpNCRMxf2ujnUFehUJDr9jN0fDbTRCjQ/NRdIN4O3y2KXDZtNuPhvc Z7g3PJBYi6Y8KSUwFnbyi0hFGAW1NSVgqqPintsUeI6oPgoXC8QzYgRh/mjzjNVMpNla V0j9RujtUpQolSpMAFYbtwJ0/X0MvEYiQDsGCtm/xRlYzqdQnfdVQmMufOP+MfQqBHl7 oYVrpfHZHax02rQwDMKXIsMfUisk7AwPglQcpcumetLzgwR4B0GcQecIW8tg0MX8MvFC J5QkNhrFaHD+goqy1OlUXFk3YiwDFLogmRIu5VWOON1avFkfJNC0IJVLIHMW8Pi9CKBQ vSLA== X-Gm-Message-State: APt69E3y5ImNIxeocjX6E/Q05eICcis3hazIkMv2IAAJlpL2htYT81MK n9tjqXp82gajmdKupabBBaxJNhFj X-Google-Smtp-Source: AAOMgpc/tU2iYETThxUzt342PxMcrZdZfANdoQ93yHftNScPSk9H1foPReiYf/366V807vVRXI7/ZQ== X-Received: by 2002:a1c:894f:: with SMTP id l76-v6mr3817662wmd.103.1530791354813; Thu, 05 Jul 2018 04:49:14 -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 o42-v6sm15809183wrc.50.2018.07.05.04.49.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Jul 2018 04:49:13 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 5 Jul 2018 13:48:21 +0200 Message-Id: X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v10 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: Thu, 05 Jul 2018 11:49:15 -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.18.0