Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2095309pxp; Fri, 18 Mar 2022 03:10:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzv7bmhLl5Iwr6asn9s+ueOoSsXqiBY7gkjfoYAigmek5vkeSvLpf2hnzcarvcPCBd+7sW/ X-Received: by 2002:a17:906:fad5:b0:6ce:e056:5918 with SMTP id lu21-20020a170906fad500b006cee0565918mr8252997ejb.562.1647598224508; Fri, 18 Mar 2022 03:10:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647598224; cv=none; d=google.com; s=arc-20160816; b=zbnzRjajaizWzH/jETqdI6En/aaj2h17A6EMx5xfd8TMlacP7gNPZ7md5+d0i7L5PU VolVYS04i9nMxUIafxYyLL3TYvM1NrnL4w8tn8iU1jUc5BTK64tFn96ZS4Yl2o6JY857 6m9jOhHyFcLnYbTOP89x0FoN7brIngUiMqMVgGlqzlPep+8xseMn+STHIUwZND3kqnvV W+YZ2BPk/OGkkD/E1q8IgjfB7kxAzOfVOiogvnYWLHGjFWaKbHvr+xAWKw324WYVVJEE +Ys49dzKF6u+Xu75ltofRjMt6Y37/Y/vLad+TgzyD2JCrnfCEk+ndArOq8/5ZG/bCnyT 47Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jScCfI4+l1j0yh8dxr8MjCYtRTxONVJGC6Dnrd85Gss=; b=MySdC+cGiaK0nlMiM9KhT1yVtb1M1043NlWJZDS/j1XZoh0I9o8CmOhNi80lWwJGmy dBObrI35MWhkS5fIa6DXcRMtu1SVXhW0Zql9tntPYz5mQCHxWPXKVZHtDyQHnG6nOPTA f1rw1vIVtzgMq5Hxglo4ltimpE1QIw8PANsOa/zaTjPz3MvbyEiQmcZFdKbS9AbuDoPX OaXHfFGXp7U1Fgdxx5+71NSpvYktnrHfHxbWC6FyLFZrvaWH3AvHc5H3+yTgY6+x3XDM bDq0iSJxpdBrzaDPhQrP+Fr/0CXdsl7X4lpyCbd/rYqbH6XefgqO7mpWBByo/gnUJAPD YADg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 13-20020a170906028d00b006df76385d66si1051665ejf.518.2022.03.18.03.09.58; Fri, 18 Mar 2022 03:10:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234277AbiCRJOf (ORCPT + 99 others); Fri, 18 Mar 2022 05:14:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234272AbiCRJOd (ORCPT ); Fri, 18 Mar 2022 05:14:33 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B676070063; Fri, 18 Mar 2022 02:13:13 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KKdYV3ZhjzfYrD; Fri, 18 Mar 2022 17:11:42 +0800 (CST) Received: from localhost.localdomain (10.175.103.91) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 18 Mar 2022 17:13:11 +0800 From: Wei Li To: , , , , CC: , , , Subject: [PATCH RESEND 1/2] perf string: Add strcmp_prefix() Date: Fri, 18 Mar 2022 17:22:44 +0800 Message-ID: <20220318092245.2700489-2-liwei391@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220318092245.2700489-1-liwei391@huawei.com> References: <20220318092245.2700489-1-liwei391@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a helper to check whether a string has the given prefix. This function is stolen from fs/xattr.c Signed-off-by: Wei Li --- tools/perf/util/string.c | 17 +++++++++++++++++ tools/perf/util/string2.h | 1 + 2 files changed, 18 insertions(+) diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c index f6d90cdd9225..0ed3e2d0b70f 100644 --- a/tools/perf/util/string.c +++ b/tools/perf/util/string.c @@ -209,6 +209,23 @@ int strtailcmp(const char *s1, const char *s2) return 0; } +/** + * strcmp_prefix - check string for given prefix + * @str: the target string to check + * @prefix: the given prefix to match + * + * Return the rest string in @str if @str has the given @prefix, return NULL + * otherwise. + */ +const char *strcmp_prefix(const char *str, const char *prefix) +{ + while (*prefix && *str == *prefix) { + str++; + prefix++; + } + return *prefix ? NULL : str; +} + char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints) { /* diff --git a/tools/perf/util/string2.h b/tools/perf/util/string2.h index 56c30fef9682..58929ad928f7 100644 --- a/tools/perf/util/string2.h +++ b/tools/perf/util/string2.h @@ -20,6 +20,7 @@ static inline bool strisglob(const char *str) return strpbrk(str, "*?[") != NULL; } int strtailcmp(const char *s1, const char *s2); +const char *strcmp_prefix(const char *str, const char *prefix); char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints); -- 2.25.1