From e93388417c1ecc6d69b155045cabb994cb8687fd Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Fri, 19 Mar 2021 17:39:24 +1030 Subject: Provide an inline startswith function in bfd.h bfd/ * bfd-in.h (startswith): New inline. (CONST_STRNEQ): Use startswith. * bfd-in2.h: Regenerate. gdbsupport/ * common-utils.h (startswith): Delete version now supplied by bfd.h. libctf/ * ctf-impl.h: Include string.h. --- bfd/bfd-in2.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'bfd/bfd-in2.h') diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 54c1c9a..c8bf687 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -72,7 +72,6 @@ extern "C" { definition of strncmp is provided here. Note - these macros do NOT work if STR2 is not a constant string. */ -#define CONST_STRNEQ(STR1,STR2) (strncmp ((STR1), (STR2), sizeof (STR2) - 1) == 0) /* strcpy() can have a similar problem, but since we know we are copying a constant string, we can use memcpy which will be faster since there is no need to check for a NUL byte inside STR. We @@ -571,6 +570,15 @@ struct ecoff_debug_swap; struct ecoff_extr; struct bfd_link_info; struct bfd_link_hash_entry; + +/* Return TRUE if the start of STR matches PREFIX, FALSE otherwise. */ + +static inline bfd_boolean +startswith (const char *str, const char *prefix) +{ + return strncmp (str, prefix, strlen (prefix)) == 0; +} +#define CONST_STRNEQ(STR1,STR2) startswith (STR1, STR2) /* Extracted from init.c. */ unsigned int bfd_init (void); -- cgit v1.1