From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 45629 invoked by alias); 3 Mar 2015 16:06:45 -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 45617 invoked by uid 89); 3 Mar 2015 16:06:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 03 Mar 2015 16:06:42 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 04495116506; Tue, 3 Mar 2015 11:06:41 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 8b6mPngNHJpv; Tue, 3 Mar 2015 11:06:40 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id D33871164E1; Tue, 3 Mar 2015 11:06:40 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id DB80740EAD; Tue, 3 Mar 2015 08:06:39 -0800 (PST) Date: Tue, 03 Mar 2015 16:06:00 -0000 From: Joel Brobecker To: Gary Benson Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] New common function "startswith" Message-ID: <20150303160639.GB3243@adacore.com> References: <1425388224-8146-1-git-send-email-gbenson@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1425388224-8146-1-git-send-email-gbenson@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-SW-Source: 2015-03/txt/msg00096.txt.bz2 > 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. > > Ok to commit? > > Cheers, > Gary > > -- > 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. > 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... ;-) 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 only skimmed through the patch, but it otherwise looks good to me. -- Joel