Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1999491imu; Sat, 22 Dec 2018 09:50:07 -0800 (PST) X-Google-Smtp-Source: ALg8bN62N1ODpAn1u4Oy+jpwNV7zl4aUuRn/YPUny6qHpO0RJ0FlUuMe/7d5TYfBEk9J2TMSCINR X-Received: by 2002:a63:4b25:: with SMTP id y37mr7049792pga.181.1545501007722; Sat, 22 Dec 2018 09:50:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545501007; cv=none; d=google.com; s=arc-20160816; b=qtJRpuI5DBAnXTOK5N/XBCgzwU4AqxwcKA+v6kT4AJ+bKETixkdYJc53xL36lN0fhG 9AWWyZDGOxU8rwfaCLEGqbeYfuf4l75jSCadIPHGkZ++GZkru3HuPXcPr3IZBkO3a9SE UjZZObAn6PGbsEoXvoOCo0IMhos0nan/vMQ5Zm6GQGvX6dfRz6Ix2Ao/5spcuZhlVoq1 utxgGc3eN+W5zBsexlVFdtSvRL66aQVVN75IfFxdpkZsn49eqLgt4yGlUhms6gqJSFgy +t1E82P4PyXv+0cK0HAQ+tsyidQJi6wvDtWv3mzmcAafVM2bIn87bdI3qbDt3vAtV7oy nL2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from; bh=mIiZrjO7eJDMS35U7umACugaRjtg4vTRHk2z9rQGPTI=; b=mh3mW2crqyuLn1jZEiH80EPaaAhLmeafnz6GBvuZQrLDKwLHiVGVD3wjXvoPmiy55N Pat2yZOnvG/19Bn9FaMQVLUFhk7SJceZtgY1gtSUyYJr/EWIXpzrdv9bP2LQXRLAXVOK x5rW0NIETyQjxh173tAK5yGVce6nrKUtF+g2yqjfBovT7XR+UkDST0HlHdJOo0U+6pN+ /RyWGca2F3r3yj8p22A9TKcVGeFDTMXDgycRljShHXMWr0KtZY2qGAEuCjGblG07lJWZ h4whXyK5W/UPqxvaLIzlwEPeiyDC5Qz4ewwQ/hAf42DQIok8iGeVLRp+MwcUq8qhIS21 og3w== 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 q127si27985781pfq.19.2018.12.22.09.49.52; Sat, 22 Dec 2018 09:50:07 -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 S2391924AbeLUU6h (ORCPT + 99 others); Fri, 21 Dec 2018 15:58:37 -0500 Received: from mail-out.m-online.net ([212.18.0.10]:36147 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390266AbeLUU6h (ORCPT ); Fri, 21 Dec 2018 15:58:37 -0500 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 43M1F64Y1Hz1qtG8; Fri, 21 Dec 2018 21:58:34 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 43M1F61F6pz1qsJj; Fri, 21 Dec 2018 21:58:34 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id ISVDhN9rwaSS; Fri, 21 Dec 2018 21:58:33 +0100 (CET) X-Auth-Info: x0K/q70BaPsUJ9pjJPT7z2D6e+2O9auz10V58Cibf3gOEF9Bs/RcXdzkc2De367U Received: from igel.home (ppp-188-174-150-84.dynamic.mnet-online.de [188.174.150.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Fri, 21 Dec 2018 21:58:33 +0100 (CET) Received: by igel.home (Postfix, from userid 1000) id 4BBAD2C25D9; Fri, 21 Dec 2018 21:58:32 +0100 (CET) From: Andreas Schwab To: Steven Rostedt Cc: Joe Perches , 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 References: <20181221175618.968519903@goodmis.org> <20181221175659.208858193@goodmis.org> <20181221144054.20bdeb33@gandalf.local.home> <20181221153526.5e6055ca@gandalf.local.home> <077eeb8b09baebe78822819b5f15d671b738a2b2.camel@perches.com> <20181221155435.38a9a221@gandalf.local.home> X-Yow: My CODE of ETHICS is vacationing at famed SCHROON LAKE in upstate New York!! Date: Fri, 21 Dec 2018 21:58:32 +0100 In-Reply-To: <20181221155435.38a9a221@gandalf.local.home> (Steven Rostedt's message of "Fri, 21 Dec 2018 15:54:35 -0500") Message-ID: <871s6ad2br.fsf@igel.home> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.90 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Dez 21 2018, Steven Rostedt wrote: > On Fri, 21 Dec 2018 12:46:47 -0800 > Joe Perches wrote: > >> > + * @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. Why not make it an inline function? Andreas. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."