Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2154579pxb; Fri, 25 Mar 2022 12:04:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyge9UCab5oIeH7fgMaIZsFwhF4nvQnADUXREvYZuVTt836I7HP7J8KKAjQ9xCcRnKu7pim X-Received: by 2002:a05:6a00:2181:b0:4f6:f1b1:1ba7 with SMTP id h1-20020a056a00218100b004f6f1b11ba7mr11603526pfi.73.1648235047416; Fri, 25 Mar 2022 12:04:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648235047; cv=none; d=google.com; s=arc-20160816; b=KhL9ZH2bAfxDc1B5UEysBE9zawVLNMthpgSR853UL6dHdUlR6vty++dCh8MsPCIn6D XLqykMpy8WU4Ml4M8NcCgZr77HZBtF3YZZe1PdF8YW5vn2PjxZfpnzBMlJAqXoaGw5Ur u3EG8YlvAvGhF76cjDf7Tw9xIY7u1JHJsTbXMCALJ7eAwPPkmF4fXNaEljctElRNURIi 56iK9vpYyhyrvuwZqZOwzpYQVsN6qfCBg32W44oeJR6IY/oemvpgLSMEWFQ9ozWMne29 2+NLkZ6YV6xL8Gm2VjFiJMFAyMrel/pDiWp2XwOVDiwqfEMUtFIegoGJ+AcRGnw83HO+ l9fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=RJd0m6J6qesloAhnGlEsS0074rm6PVya78vpRI0V4Vg=; b=nhx8xUclQzFOTp8ShnpWNP152q+ZOeVWm1GwIRBBEUTQVUc7AU7FIbI3t58U+QaIZ1 A6a2ryvTBR4tDrI2xy5ej0sDUg3SspNk9yaQM7S+6KXGCR/o3CBoiMLsi7j/oIRqs0hX DgIgnecyo9bF7bNfHwy/NgQI0gdQzqSTENcV/uGp0deHTvSHL2E9UxijIDjYyWRYTY5r 7qg5V9pp8QzMhd79rAFvQQyuRiIVPzgvUVEuTIKPCY+zJLjcLj2A0j6it7ylocHov8jr 9aEJwUXX8DKJvZUpFhHpLIRTW6TB0S2B0a51c88ezbqZva2JyeE1rXt4UV8bTuEZ4NLS TBAw== 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:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 85-20020a621858000000b004faac3a73f6si3531164pfy.79.2022.03.25.12.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 12:04:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 776FE1D67CA; Fri, 25 Mar 2022 11:12:36 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357732AbiCYCME (ORCPT + 99 others); Thu, 24 Mar 2022 22:12:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357703AbiCYCLv (ORCPT ); Thu, 24 Mar 2022 22:11:51 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0602FA6E3F; Thu, 24 Mar 2022 19:06:49 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KPlm92dXVzfZmJ; Fri, 25 Mar 2022 10:05:13 +0800 (CST) Received: from [10.174.179.211] (10.174.179.211) 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, 25 Mar 2022 10:06:47 +0800 Subject: Re: [PATCH RESEND 1/2] perf string: Add strcmp_prefix() To: Arnaldo Carvalho de Melo CC: , , , , , , , References: <20220318092245.2700489-1-liwei391@huawei.com> <20220318092245.2700489-2-liwei391@huawei.com> From: "liwei (GF)" Message-ID: Date: Fri, 25 Mar 2022 10:06:47 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="gbk" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.211] 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=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On 2022/3/23 5:22, Arnaldo Carvalho de Melo wrote: > Em Fri, Mar 18, 2022 at 05:22:44PM +0800, Wei Li escreveu: >> Add a helper to check whether a string has the given prefix. >> This function is stolen from fs/xattr.c > > Can't you use strstarts()? See tools/include/linux/string.h. > Sorry, i haven't known that before, will use strstarts() in v2. Thanks, Wei > >> 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 >