This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] New common function "startswith"


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]