From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC1CFC433E0 for ; Tue, 2 Feb 2021 10:37:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D87564EDA for ; Tue, 2 Feb 2021 10:37:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229986AbhBBKhC (ORCPT ); Tue, 2 Feb 2021 05:37:02 -0500 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:7257 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229643AbhBBKg7 (ORCPT ); Tue, 2 Feb 2021 05:36:59 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Tue, 02 Feb 2021 02:35:39 -0800 Received: from sw-mtx-036.mtx.labs.mlnx (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 2 Feb 2021 10:35:38 +0000 From: Parav Pandit To: , , , , , CC: Parav Pandit Subject: [PATCH iproute2-next v3 4/5] utils: Add helper to map string to unsigned int Date: Tue, 2 Feb 2021 12:35:17 +0200 Message-ID: <20210202103518.3858-5-parav@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210202103518.3858-1-parav@nvidia.com> References: <20210122112654.9593-3-parav@nvidia.com> <20210202103518.3858-1-parav@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1612262139; bh=wb+dkpPaTiWpTz3BlBWkumEuJWVmUA/mgN3gQd43q88=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=hZsuxxZvFFv6nQ0NHttPB3MW7sY+Kuh8g8EbFQlDzXKJ8JQZiDYGwzANt3ZYL9qBC ck1xSWTOfqFKn8PtQZ8dko/s/9OSYZz5nUn5PabKmwHbGMRyGPcEdjNp61xU55oI/W ueVFqnS9SEzAsUAzu1IQ+OuQ8hB9Uv5bibB8zafoGkE9Yegty88zWzbPnpGm4Ii+ky DzfxXurEcYeaVNJBn5NpEbRQcFo0tZzdo7jhurna+vnkuXf+5k/HREu/UlkIQ87I0c qRgDwcRHp70GFYEyN7Z561Mgfkc+AOy3y5A5fxMI1JGNgz/cAGYlUdhBqZ0iEF1j4T lpvlX36noyJGA== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In subsequent patch need to map a string to a unsigned int. Hence, add an API to map a string to unsigned int. Signed-off-by: Parav Pandit --- changelog: v2->v3: - new patch to reuse string to unsigned int mapping --- include/utils.h | 4 +++- lib/utils.c | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/utils.h b/include/utils.h index 9b76c92a..b29c3798 100644 --- a/include/utils.h +++ b/include/utils.h @@ -342,10 +342,12 @@ int parse_mapping(int *argcp, char ***argvp, bool all= ow_all, =20 struct str_num_map { const char *str; - int num; + unsigned int num; }; =20 int str_map_lookup_str(const struct str_num_map *map, const char *needle); +const char *str_map_lookup_uint(const struct str_num_map *map, + unsigned int val); const char *str_map_lookup_u16(const struct str_num_map *map, uint16_t val= ); const char *str_map_lookup_u8(const struct str_num_map *map, uint8_t val); =20 diff --git a/lib/utils.c b/lib/utils.c index cc6d0e34..633f6359 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -1953,9 +1953,22 @@ int str_map_lookup_str(const struct str_num_map *map= , const char *needle) return -EINVAL; } =20 +const char *str_map_lookup_uint(const struct str_num_map *map, unsigned in= t val) +{ + unsigned int num =3D val; + + while (map && map->str) { + if (num =3D=3D map->num) + return map->str; + + map++; + } + return NULL; +} + const char *str_map_lookup_u16(const struct str_num_map *map, uint16_t val= ) { - int num =3D val; + unsigned int num =3D val; =20 while (map && map->str) { if (num =3D=3D map->num) @@ -1968,7 +1981,7 @@ const char *str_map_lookup_u16(const struct str_num_m= ap *map, uint16_t val) =20 const char *str_map_lookup_u8(const struct str_num_map *map, uint8_t val) { - int num =3D val; + unsigned int num =3D val; =20 while (map && map->str) { if (num =3D=3D map->num) --=20 2.26.2 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8997C433E6 for ; Tue, 2 Feb 2021 10:35:43 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6838A64F58 for ; Tue, 2 Feb 2021 10:35:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6838A64F58 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=virtualization-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 24A9886679; Tue, 2 Feb 2021 10:35:43 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fFDBNC9FsTOV; Tue, 2 Feb 2021 10:35:41 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id E482086688; Tue, 2 Feb 2021 10:35:41 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id CFDD7C0FA7; Tue, 2 Feb 2021 10:35:41 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id B5816C013A for ; Tue, 2 Feb 2021 10:35:40 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 9803284549 for ; Tue, 2 Feb 2021 10:35:40 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fDisnOwQ2MpP for ; Tue, 2 Feb 2021 10:35:40 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from hqnvemgate24.nvidia.com (hqnvemgate24.nvidia.com [216.228.121.143]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 1BFDE850AD for ; Tue, 2 Feb 2021 10:35:40 +0000 (UTC) Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Tue, 02 Feb 2021 02:35:39 -0800 Received: from sw-mtx-036.mtx.labs.mlnx (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 2 Feb 2021 10:35:38 +0000 From: Parav Pandit To: , , , , , Subject: [PATCH iproute2-next v3 4/5] utils: Add helper to map string to unsigned int Date: Tue, 2 Feb 2021 12:35:17 +0200 Message-ID: <20210202103518.3858-5-parav@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210202103518.3858-1-parav@nvidia.com> References: <20210122112654.9593-3-parav@nvidia.com> <20210202103518.3858-1-parav@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1612262139; bh=wb+dkpPaTiWpTz3BlBWkumEuJWVmUA/mgN3gQd43q88=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=hZsuxxZvFFv6nQ0NHttPB3MW7sY+Kuh8g8EbFQlDzXKJ8JQZiDYGwzANt3ZYL9qBC ck1xSWTOfqFKn8PtQZ8dko/s/9OSYZz5nUn5PabKmwHbGMRyGPcEdjNp61xU55oI/W ueVFqnS9SEzAsUAzu1IQ+OuQ8hB9Uv5bibB8zafoGkE9Yegty88zWzbPnpGm4Ii+ky DzfxXurEcYeaVNJBn5NpEbRQcFo0tZzdo7jhurna+vnkuXf+5k/HREu/UlkIQ87I0c qRgDwcRHp70GFYEyN7Z561Mgfkc+AOy3y5A5fxMI1JGNgz/cAGYlUdhBqZ0iEF1j4T lpvlX36noyJGA== X-BeenThere: virtualization@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux virtualization List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: virtualization-bounces@lists.linux-foundation.org Sender: "Virtualization" In subsequent patch need to map a string to a unsigned int. Hence, add an API to map a string to unsigned int. Signed-off-by: Parav Pandit --- changelog: v2->v3: - new patch to reuse string to unsigned int mapping --- include/utils.h | 4 +++- lib/utils.c | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/utils.h b/include/utils.h index 9b76c92a..b29c3798 100644 --- a/include/utils.h +++ b/include/utils.h @@ -342,10 +342,12 @@ int parse_mapping(int *argcp, char ***argvp, bool allow_all, struct str_num_map { const char *str; - int num; + unsigned int num; }; int str_map_lookup_str(const struct str_num_map *map, const char *needle); +const char *str_map_lookup_uint(const struct str_num_map *map, + unsigned int val); const char *str_map_lookup_u16(const struct str_num_map *map, uint16_t val); const char *str_map_lookup_u8(const struct str_num_map *map, uint8_t val); diff --git a/lib/utils.c b/lib/utils.c index cc6d0e34..633f6359 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -1953,9 +1953,22 @@ int str_map_lookup_str(const struct str_num_map *map, const char *needle) return -EINVAL; } +const char *str_map_lookup_uint(const struct str_num_map *map, unsigned int val) +{ + unsigned int num = val; + + while (map && map->str) { + if (num == map->num) + return map->str; + + map++; + } + return NULL; +} + const char *str_map_lookup_u16(const struct str_num_map *map, uint16_t val) { - int num = val; + unsigned int num = val; while (map && map->str) { if (num == map->num) @@ -1968,7 +1981,7 @@ const char *str_map_lookup_u16(const struct str_num_map *map, uint16_t val) const char *str_map_lookup_u8(const struct str_num_map *map, uint8_t val) { - int num = val; + unsigned int num = val; while (map && map->str) { if (num == map->num) -- 2.26.2 _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization