From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pavel Vasilyev Subject: Re: [linux-pm] [PATCH] ACPI: replace strlen("string") with sizeof("string") -1 Date: Mon, 06 Aug 2012 20:00:41 +0400 Message-ID: <501FEA29.1030400@pavlinux.ru> References: Reply-To: pavel@pavlinux.ru Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org To: Alan Stern Cc: Pavel Machek , Len Brown , linux-acpi@vger.kernel.org, linux-pm@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Len Brown List-Id: linux-acpi@vger.kernel.org 06.08.2012 18:36, Alan Stern =D0=BF=D0=B8=D1=88=D0=B5=D1=82: > On Mon, 6 Aug 2012, Pavel Machek wrote: > >> On Thu 2012-07-26 21:39:38, Len Brown wrote: >>> ...both give the number of chars in the string >>> without the '\0', as strncmp() wants, >>> but sizeof() is compile-time. >> >> What about introducing something like streq() to do this >> automatically? This is ugly.... >> >> #define streq(a, b) ... if (_buildin_constant(b)) ... >> >> ? >> >>> - if (!strncmp(val, "enable", strlen("enable"))) { >>> + if (!strncmp(val, "enable", sizeof("enable") - 1)) { > > While you're at it, there's no point using strncmp when you know the > length of one of the strings beforehand. Just use memcmp, and don't > subtract 1 from the sizeof value. http://www.gossamer-threads.com/lists/engine?do=3Dpost_attachment;posta= tt_id=3D41157;list=3Dlinux :) --=20 Pavel.