Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1999298imu; Sat, 22 Dec 2018 09:49:53 -0800 (PST) X-Google-Smtp-Source: ALg8bN6FCgumL0lqot2tKj+mugj0AXtgoYIH7fbhpdu8dWqYgGSa9VQb2ZxrMCdf9HAwcfEi9yac X-Received: by 2002:a17:902:a5ca:: with SMTP id t10mr7192381plq.139.1545500993135; Sat, 22 Dec 2018 09:49:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545500993; cv=none; d=google.com; s=arc-20160816; b=RvL3/fXarXnHaPNRpymsdA0MTg33gtihLSl86XOb/YTZyCddJRoy0D6EhNHN7iNznS cHAccAACBqjl3chnhqeSQCddQUpUaYfIyr9e7hFP+fSlj9WY/gFjZv7DJnotQPWPXXJ3 NfJt8YA0fkPYNjQaQZbOiu1LwDBee78jsG+ejDlubO+kXa9HGwbh9R5HPb+GYlEPOAmK DY4IjSY1uDTxsUReM9iOCiLwJzqLR+YiluZMR+ssT3Dsvs9DSWuNNtC5oF8p2EZTrQXZ KQm0lvoGlmCOLnwhBf7/yOqkBSjiFz8jdWDav+oFIHuJGeXByjukUXpC0vEuvcSs51Cy TGGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=DWYuq09W+cPswlufrGPfd2/aMs5RuugAcQZUzRznAFY=; b=kRTjh2iMCzq42pr+skpfr0PLqMKk99Y6o1fcN/FYnzhfG+e9Rb4pSFHOKXG9cT1qDf J+s6Be3SWSkkp+8siyF9HuIOVfDOu6SZ2ql0XlMt5AfsnBSv1dm5wQuDLoQciQ33tCQG TvbUQq5U2CRMIiy0akMbUhBmGJiQDlMxiSPnIAVkudsBr0ikTlZqhOMqEVMUhZJzCItM Pj/efNsjzz9ZwSRbalZ74XySeTTUSAz1BaXMH3h+/hKAW5lLXnFhdU79Udg57mCs8a/G XjrdYQNuGtU28oVPaMVau5gfn6kxCzv5/MYMnj+vDhBBEeMYbb2dizBDGaVU+Qua+xd8 LRkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a12si19943929pgk.291.2018.12.22.09.49.37; Sat, 22 Dec 2018 09:49:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391852AbeLUUyj (ORCPT + 99 others); Fri, 21 Dec 2018 15:54:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:60040 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730307AbeLUUyi (ORCPT ); Fri, 21 Dec 2018 15:54:38 -0500 Received: from gandalf.local.home (cpe-66-24-56-78.stny.res.rr.com [66.24.56.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3B8F121929; Fri, 21 Dec 2018 20:54:37 +0000 (UTC) Date: Fri, 21 Dec 2018 15:54:35 -0500 From: Steven Rostedt To: Joe Perches Cc: Linus Torvalds , Linux List Kernel Mailing , Ingo Molnar , Andrew Morton , Namhyung Kim , Masami Hiramatsu , Tom Zanussi , Greg Kroah-Hartman Subject: Re: [for-next][PATCH 23/24] string.h: Add strncmp_prefix() helper macro Message-ID: <20181221155435.38a9a221@gandalf.local.home> In-Reply-To: <077eeb8b09baebe78822819b5f15d671b738a2b2.camel@perches.com> References: <20181221175618.968519903@goodmis.org> <20181221175659.208858193@goodmis.org> <20181221144054.20bdeb33@gandalf.local.home> <20181221153526.5e6055ca@gandalf.local.home> <077eeb8b09baebe78822819b5f15d671b738a2b2.camel@perches.com> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 21 Dec 2018 12:46:47 -0800 Joe Perches wrote: > > @@ -14,6 +14,28 @@ extern void *memdup_user(const void __user *, size_t); > > extern void *vmemdup_user(const void __user *, size_t); > > extern void *memdup_user_nul(const void __user *, size_t); > > > > +/** > > + * have_prefix - Test if a string has a given prefix > > There is a naming mismatch of have/has here > and has_prefix is probably too generic a name. > > How about str_has_prefix? Sure. > > > + * @str: The string to test > > + * @prefix: The string to see if @str starts with > > + * > > + * A common way to test a prefix of a string is to do: > > + * strncmp(str, prefix, sizeof(prefix) - 1) > > + * > > + * But this can lead to bugs due to typos, or if prefix is a pointer > > + * and not a constant. Instead use has_prefix(). > > + * > > + * Returns: 0 if @str does not start with @prefix > > + strlen(@prefix) if @str does start with @prefix > > + */ > > +#define has_prefix(str, prefix) \ > > + ({ \ > > + const char *____prefix____ = (const char *)(prefix); \ > > + int ____len____ = strlen(____prefix____); \ > > + strncmp(str, ____prefix____, ____len____) == 0 ? \ > > + ____len____ : 0; \ > > + }) > > I think all the underscores are unnecessary and confusing. > Well, perhaps I can just remove the ending ones. I get paranoid with macro variables, and tend to over do it so that there's no question. I don't find them confusing ;-) But I tend to use a lot of macros. -- Steve