From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17934 invoked by alias); 3 Mar 2015 17:16:19 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 17925 invoked by uid 89); 3 Mar 2015 17:16:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 03 Mar 2015 17:16:18 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t23HGEQa022341 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 3 Mar 2015 12:16:14 -0500 Received: from blade.nx (ovpn-116-78.ams2.redhat.com [10.36.116.78]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t23HGDc6014875; Tue, 3 Mar 2015 12:16:14 -0500 Received: by blade.nx (Postfix, from userid 1000) id 02F6D265054; Tue, 3 Mar 2015 17:16:12 +0000 (GMT) Date: Tue, 03 Mar 2015 17:16:00 -0000 From: Gary Benson To: Joel Brobecker Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] New common function "startswith" Message-ID: <20150303171612.GA7569@blade.nx> References: <1425388224-8146-1-git-send-email-gbenson@redhat.com> <20150303160639.GB3243@adacore.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150303160639.GB3243@adacore.com> X-IsSubscribed: yes X-SW-Source: 2015-03/txt/msg00105.txt.bz2 Joel Brobecker wrote: > > This patch introduces a new common function "startswith" which > > takes two string arguments and returns nonzero if the first string > > starts with the second. It also updates the 180 places where this > > logic was written out longhand to use the new function. > > > > I almost pushed this as obvious, but I hesitated because of its > > size. > > > > -- > > gdb/ChangeLog: > > > > * common/common-utils.h (startswith): New declaration. > > * common/common-utils.c (startswith): New Function. > > All places where this logic was used updated to use the above. > > Given the obvious errors in remote.c that you just fixed, I'd say > this is going to be a very useful function. Yeah, that's what prompted it :) > > diff --git a/gdb/common/common-utils.c b/gdb/common/common-utils.c > > index 2925dd5..5fb4af1 100644 > > --- a/gdb/common/common-utils.c > > +++ b/gdb/common/common-utils.c > > @@ -151,3 +151,11 @@ savestring (const char *ptr, size_t len) > > p[len] = 0; > > return p; > > } > > + > > +/* See common-utils.h. */ > > + > > +int > > +startswith (const char *s1, const char *s2) > > +{ > > + return startswith (s1, s2); > > +} > > As pointed out by Andreas... ;-) So the automated find and replace thing I wrote found and replaced that one... > Also, how about we rename the parameters to something like "str" > instead of "s1" and "pattern" for s2. It makes it faster, IMO, to > figure out the parameter order without having to read the function's > documentation, and therefore makes it's use a little less > error-prone. I can do that. I also found some more, with the pattern strncmp (string, "something", sizeof ("something") -1) so I'll update the patch to include those too. > I only skimmed through the patch, but it otherwise looks good to me. Cool, thanks for reviewing. Cheers, Gary -- http://gbenson.net/