[PATCH] Add startswith function and use it instead of CONST_STRNEQ.

Tom Tromey tom@tromey.com
Wed Mar 31 20:18:30 GMT 2021

Hi.  I'm sorry about the delay on this.

Alan> But all of this horrible old code that likely hasn't been tested is
Alan> eons should simply disappear.

gdb has this issue to a lesser degree as well, where it checks for
headers that have not been missing in 20 years.  This kind of rot is one
of the downsides of the autoconf approach.

Alan> Instead binutils should be using the
Alan> gnulib import already available in the binutils-gdb repository to
Alan> support old systems.  I've had that project on my todo list for quite
Alan> a while.  We'd be able to include stdint.h and stdbool.h for example,
Alan> throwing away bfd_stdint.h and replacing bfd_boolean with bool.

We've had mixed experiences with gnulib in gdb.  Partly that's because
gdb is in C++; but also partly because gnulib is fairly opinionated
about some things, and if you want to be more flexible, it's difficult.

Anyway, I think it would be a good thing to try.  And, it's relatively
easy now that gnulib has moved to the top-level.  The main difficulty
that I would anticipate is that I think there are some gnulib modules
that can't be used for gdb; but if binutils needed these then we'd be in
a bit of a quandary.

I suppose though that the gnulib model is to patch things upstream and
so we could try to work out problems that way.

Alan> Meanwhile, this is a tidied version of the patch I sent you last
Alan> night, Tom.  If you already have one of your own then please ignore
Alan> this.

This looks good to me.  Thank you.

Alan> +#ifndef STR_UTIL_H
Alan> +#define STR_UTIL_H
Alan> +
Alan> +/* Return 1 if the start of STR matches PREFIX, 0 otherwise.  */
Alan> +
Alan> +static inline int
Alan> +startswith (const char *str, const char *prefix)
Alan> +{
Alan> +  return strncmp (str, prefix, strlen (prefix)) == 0;

In keeping with the above, I tend to think that adding a <string.h>
include in this file would be fine, and unlikely to break the build on
any real system.

If there is one, that would be interesting information.

Here's what gnulib has to say about string.h:


... if it were missing anywhere, I suppose I'd expect a bullet point to
that effect.


More information about the Binutils mailing list