From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by dpdk.org (Postfix) with ESMTP id 80DB21B590 for ; Wed, 11 Jul 2018 23:45:53 +0200 (CEST) Received: by mail-wm0-f66.google.com with SMTP id b188-v6so3719873wme.3 for ; Wed, 11 Jul 2018 14:45: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; bh=FCiWZCW6CR4FN7hgRxpm6MaGb4vrkQDcX+s25dOVhXA=; b=NO1j9T646oF7j7Z/+2KTasUqzCVhScyhNid18OzP+r37/GJwhKZCJJ7Aiqz5gYPPQV LVEslGvPI5v45Oe6I+9FI1xLle3zecLbsJEHFlYEPNzorEqn8sFJohE8QdlKL0vEjGab cSze+wIv0Gjww/DC0eMY0bk6aSY7WHAPms9f+dBokjAtr1UW18/doUa0K87RbRvQngO7 9m+vGc/JDNS/aw1SXuuCeb/6bBmzaYRIPs9qdnL+ZE15aJRUASovWoy8TMY0u1B5bGjv QNxEBflw6yDtRC/kM0ojrj5thdC4ORV+AWlLlUSLb/UDwNh3xL8ipHE8tY7j8ZIk4hhM GFUQ== 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=FCiWZCW6CR4FN7hgRxpm6MaGb4vrkQDcX+s25dOVhXA=; b=YHsewUSxmSG4J8p3z2CTm3oLAAOv/xwYBzs8OTGF2TjgMrYRsapsUA9kSudl2DCQWN pCYU76FEInL6GLo+VR1Guwkr4qkwbVsGGfx/aGYx6atB7YVbNB29zVJ/15dfduLvQok8 pRZEZv0ONhzhWhBOjjhL/FKzXQVtQOZlVWPYnGsaTIRPoJyOdH4qGqo2b8ztCeljZX9b e1uJ6DYIIvUI2FYAFlqB4zi6Ixfxv5RkJfUOd6+0SrRXrs3MgY1/Ss2VlEQehw/ozScX 2YJkvKilxRU9fzUoL2RFwqaYSWUMjH8Oc04kxr8hFFDlSrX1t0gQecnqLDKOBA0JrJif 9MMA== X-Gm-Message-State: AOUpUlFbOM4gnZBsJn8YStE1OYbQduqW6Ut8sokZDy+LF7vbnFyMHGAm gLmgIuijVD+tQqvFll+K7i6oxWEi X-Google-Smtp-Source: AAOMgpdFq9ujjFytjV9w+y90/+nCcdDKhfTFBqs12SNKHvigKWAOCeO7dD5e6tXICrDTzwR8VZsLIA== X-Received: by 2002:a1c:2208:: with SMTP id i8-v6mr121062wmi.105.1531345552740; Wed, 11 Jul 2018 14:45: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 h5-v6sm10550936wrr.19.2018.07.11.14.45.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 14:45:51 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Wed, 11 Jul 2018 23:45:02 +0200 Message-Id: X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v11 12/25] 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: Wed, 11 Jul 2018 21:45:54 -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 | 26 ++++++++++++++++++++++++ lib/librte_kvargs/rte_kvargs_version.map | 1 + 3 files changed, 37 insertions(+) diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c index 52262fe54..a28f76945 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 7f32fd1f6..fc041956e 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 afce125a9..8f4b4e3f8 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; -- 2.18.0