[PATCH] New common function "startswith"

Gary Benson
2015-03-03T13:10:35Z

Hi all,

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.
---
gdb/ChangeLog | 6 +++++
gdb/ada-lang.c | 26 ++++++++++----------
gdb/amd64-windows-tdep.c | 4 +-
gdb/amd64obsd-tdep.c | 4 +-
gdb/arm-tdep.c | 12 +++++-----
gdb/arm-wince-tdep.c | 2 +-
gdb/breakpoint.c | 2 +-
gdb/c-typeprint.c | 6 ++--
gdb/cli/cli-dump.c | 2 +-
gdb/cli/cli-script.c | 2 +-
gdb/coffread.c | 4 +-
gdb/common/common-utils.c | 8 ++++++
gdb/common/common-utils.h | 5 ++++
gdb/compile/compile.c | 2 +-
gdb/dbxread.c | 2 +-
gdb/dictionary.c | 2 +-
gdb/dwarf2-frame.c | 2 +-
gdb/gdbserver/hostio.c | 12 +++++-----
gdb/gdbserver/linux-low.c | 4 +-
gdb/gdbserver/linux-x86-low.c | 2 +-
gdb/gdbserver/notif.c | 2 +-
gdb/gdbserver/remote-utils.c | 6 ++--
gdb/gdbserver/server.c | 43 +++++++++++++++++-----------------
gdb/gdbserver/tracepoint.c | 51 ++++++++++++++++++++---------------------
gdb/gdbserver/win32-low.c | 2 +-
gdb/gdbtypes.c | 2 +-
gdb/gnu-v2-abi.c | 6 ++--
gdb/gnu-v3-abi.c | 4 +-
gdb/go-lang.c | 4 +-
gdb/i386-tdep.c | 4 +-
gdb/i386obsd-tdep.c | 6 ++--
gdb/linespec.c | 8 +++---
gdb/linux-nat.c | 8 +++---
gdb/machoread.c | 2 +-
gdb/microblaze-rom.c | 4 +-
gdb/minsyms.c | 2 +-
gdb/mips-sde-tdep.c | 2 +-
gdb/mips-tdep.c | 19 +++++++--------
gdb/msp430-tdep.c | 3 +-
gdb/nat/linux-procfs.c | 2 +-
gdb/nbsd-tdep.c | 2 +-
gdb/p-typeprint.c | 8 +++---
gdb/regcache.c | 2 +-
gdb/remote-m32r-sdi.c | 4 +-
gdb/remote-notif.c | 2 +-
gdb/remote.c | 18 +++++++-------
gdb/reverse.c | 6 ++--
gdb/ser-tcp.c | 4 +-
gdb/serial.c | 4 +-
gdb/somread.c | 4 +-
gdb/symtab.c | 2 +-
gdb/tracefile-tfile.c | 8 +++---
gdb/tracepoint.c | 6 ++--
gdb/tui/tui-data.c | 2 +-
gdb/utils.c | 5 +--
gdb/valops.c | 12 +++++-----
gdb/windows-nat.c | 5 +--
gdb/xcoffread.c | 2 +-
58 files changed, 199 insertions(+), 186 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index b016723..9a0165f 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -1156,7 +1156,7 @@ ada_decode (const char *encoded)
/* The name of the Ada main procedure starts with "_ada_".
This prefix is not part of the decoded name, so skip this part
if we see this prefix. */
- if (strncmp (encoded, "_ada_", 5) == 0)
+ if (startswith (encoded, "_ada_"))
encoded += 5;

/* If the name starts with '_', then it is not a properly encoded
@@ -1467,7 +1467,7 @@ match_name (const char *sym_name, const char *name, int wild)

return (strncmp (sym_name, name, len_name) == 0
&& is_name_suffix (sym_name + len_name))
- || (strncmp (sym_name, "_ada_", 5) == 0
+ || (startswith (sym_name, "_ada_")
&& strncmp (sym_name + 5, name, len_name) == 0
&& is_name_suffix (sym_name + len_name + 5));
}
@@ -5028,11 +5028,11 @@ old_renaming_is_invisible (const struct symbol *sym, const char *function_name)
a library-level function. Strip this prefix before doing the
comparison, as the encoding for the renaming does not contain
this prefix. */
- if (strncmp (function_name, "_ada_", 5) == 0)
+ if (startswith (function_name, "_ada_"))
function_name += 5;

{
- int is_invisible = strncmp (function_name, scope, strlen (scope)) != 0;
+ int is_invisible = !startswith (function_name, scope);

do_cleanups (old_chain);
return is_invisible;
@@ -5830,7 +5830,7 @@ advance_wild_match (const char **namep, const char *name0, int target0)
if ((t1 >= 'a' && t1 <= 'z') || (t1 >= '0' && t1 <= '9'))
{
name += 1;
- if (name == name0 + 5 && strncmp (name0, "_ada", 4) == 0)
+ if (name == name0 + 5 && startswith (name0, "_ada"))
break;
else
name += 1;
@@ -6371,7 +6371,7 @@ ada_is_ignored_field (struct type *type, int field_num)
for tagged types, and it contains the components inherited from
the parent type. This field should not be printed as is, but
should not be ignored either. */
- if (name[0] == '_' && strncmp (name, "_parent", 7) != 0)
+ if (name[0] == '_' && !startswith (name, "_parent"))
return 1;
}

@@ -6698,8 +6698,8 @@ ada_is_parent_field (struct type *type, int field_num)
const char *name = TYPE_FIELD_NAME (ada_check_typedef (type), field_num);

return (name != NULL
- && (strncmp (name, "PARENT", 6) == 0
- || strncmp (name, "_parent", 7) == 0));
+ && (startswith (name, "PARENT")
+ || startswith (name, "_parent")));
}

/* True iff field number FIELD_NUM of structure type TYPE is a
@@ -6714,9 +6714,9 @@ ada_is_wrapper_field (struct type *type, int field_num)
const char *name = TYPE_FIELD_NAME (type, field_num);

return (name != NULL
- && (strncmp (name, "PARENT", 6) == 0
+ && (startswith (name, "PARENT")
|| strcmp (name, "REP") == 0
- || strncmp (name, "_parent", 7) == 0
+ || startswith (name, "_parent")
|| name[0] == 'S' || name[0] == 'R' || name[0] == 'O'));
}

@@ -6787,7 +6787,7 @@ ada_variant_discrim_name (struct type *type0)
for (discrim_end = name + strlen (name) - 6; discrim_end != name;
discrim_end -= 1)
{
- if (strncmp (discrim_end, "___XVN", 6) == 0)
+ if (startswith (discrim_end, "___XVN"))
break;
}
if (discrim_end == name)
@@ -12475,7 +12475,7 @@ catch_ada_exception_command_split (char *args,
/* Check to see if we have a condition. */

args = skip_spaces (args);
- if (strncmp (args, "if", 2) == 0
+ if (startswith (args, "if")
&& (isspace (args[2]) || args[2] == '\0'))
{
args += 2;
@@ -12736,7 +12736,7 @@ catch_ada_assert_command_split (char *args, char **cond_string)
args = skip_spaces (args);

/* Check whether a condition was provided. */
- if (strncmp (args, "if", 2) == 0
+ if (startswith (args, "if")
&& (isspace (args[2]) || args[2] == '\0'))
{
args += 2;
diff --git a/gdb/amd64-windows-tdep.c b/gdb/amd64-windows-tdep.c
index 2aa10a1..de5d8c7 100644
--- a/gdb/amd64-windows-tdep.c
+++ b/gdb/amd64-windows-tdep.c
@@ -1157,8 +1157,8 @@ amd64_windows_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)

if (symname)
{
- if (strncmp (symname, "__imp_", 6) == 0
- || strncmp (symname, "_imp_", 5) == 0)
+ if (startswith (symname, "__imp_")
+ || startswith (symname, "_imp_"))
destination
= read_memory_unsigned_integer (indirect_addr, 8, byte_order);
}
diff --git a/gdb/amd64obsd-tdep.c b/gdb/amd64obsd-tdep.c
index 04cd31f..d6c7e90 100644
--- a/gdb/amd64obsd-tdep.c
+++ b/gdb/amd64obsd-tdep.c
@@ -372,7 +372,7 @@ amd64obsd_trapframe_cache (struct frame_info *this_frame, void **this_cache)
sp = get_frame_register_unsigned (this_frame, AMD64_RSP_REGNUM);

find_pc_partial_function (func, &name, NULL, NULL);
- if (name && strncmp (name, "Xintr", 5) == 0)
+ if (name && startswith (name, "Xintr"))
addr = sp + 8; /* It's an interrupt frame. */
else
addr = sp;
@@ -436,7 +436,7 @@ amd64obsd_trapframe_sniffer (const struct frame_unwind *self,
return (name && ((strcmp (name, "calltrap") == 0)
|| (strcmp (name, "osyscall1") == 0)
|| (strcmp (name, "Xsyscall") == 0)
- || (strncmp (name, "Xintr", 5) == 0)));
+ || (startswith (name, "Xintr"))));
}

static const struct frame_unwind amd64obsd_trapframe_unwind = {
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index d7cd6e5..57be2eb 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -484,15 +484,15 @@ skip_prologue_function (struct gdbarch *gdbarch, CORE_ADDR pc, int is_thumb)
/* On soft-float targets, __truncdfsf2 is called to convert promoted
arguments to their argument types in non-prototyped
functions. */
- if (strncmp (name, "__truncdfsf2", strlen ("__truncdfsf2")) == 0)
+ if (startswith (name, "__truncdfsf2"))
return 1;
- if (strncmp (name, "__aeabi_d2f", strlen ("__aeabi_d2f")) == 0)
+ if (startswith (name, "__aeabi_d2f"))
return 1;

/* Internal functions related to thread-local storage. */
- if (strncmp (name, "__tls_get_addr", strlen ("__tls_get_addr")) == 0)
+ if (startswith (name, "__tls_get_addr"))
return 1;
- if (strncmp (name, "__aeabi_read_tp", strlen ("__aeabi_read_tp")) == 0)
+ if (startswith (name, "__aeabi_read_tp"))
return 1;
}
else
@@ -9315,8 +9315,8 @@ arm_skip_stub (struct frame_info *frame, CORE_ADDR pc)
_call_via_xx, where x is the register name. The possible names
are r0-r9, sl, fp, ip, sp, and lr. ARM RealView has similar
functions, named __ARM_call_via_r[0-7]. */
- if (strncmp (name, "_call_via_", 10) == 0
- || strncmp (name, "__ARM_call_via_", strlen ("__ARM_call_via_")) == 0)
+ if (startswith (name, "_call_via_")
+ || startswith (name, "__ARM_call_via_"))
{
/* Use the name suffix to determine which register contains the
target PC. */
diff --git a/gdb/arm-wince-tdep.c b/gdb/arm-wince-tdep.c
index 206ff4f..72295ba 100644
--- a/gdb/arm-wince-tdep.c
+++ b/gdb/arm-wince-tdep.c
@@ -66,7 +66,7 @@ arm_pe_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
return 0;

symname = MSYMBOL_LINKAGE_NAME (indsym.minsym);
- if (symname == NULL || strncmp (symname, "__imp_", 6) != 0)
+ if (symname == NULL || !startswith (symname, "__imp_"))
return 0;

next_pc = read_memory_unsigned_integer (indirect, 4, byte_order);
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index db4b872..d5225eb 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -15462,7 +15462,7 @@ strace_command (char *arg, int from_tty)

/* Decide if we are dealing with a static tracepoint marker (`-m'),
or with a normal static tracepoint. */
- if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
+ if (arg && startswith (arg, "-m") && isspace (arg[2]))
ops = &strace_marker_breakpoint_ops;
else
ops = &tracepoint_breakpoint_ops;
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 64279c8..94a13a0 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -544,7 +544,7 @@ is_type_conversion_operator (struct type *type, int i, int j)
some other way, feel free to rewrite this function. */
const char *name = TYPE_FN_FIELDLIST_NAME (type, i);

- if (strncmp (name, "operator", 8) != 0)
+ if (!startswith (name, "operator"))
return 0;

name += 8;
@@ -560,9 +560,9 @@ is_type_conversion_operator (struct type *type, int i, int j)
/* If this doesn't look like the start of an identifier, then it
isn't a type conversion operator. */
return 0;
- else if (strncmp (name, "new", 3) == 0)
+ else if (startswith (name, "new"))
name += 3;
- else if (strncmp (name, "delete", 6) == 0)
+ else if (startswith (name, "delete"))
name += 6;
else
/* If it doesn't look like new or delete, it's a type conversion
diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c
index 481c3a2..0f9485f 100644
--- a/gdb/cli/cli-dump.c
+++ b/gdb/cli/cli-dump.c
@@ -575,7 +575,7 @@ restore_command (char *args_in, int from_tty)
char *binary_string = "binary";

/* Look for optional "binary" flag. */
- if (strncmp (args, binary_string, strlen (binary_string)) == 0)
+ if (startswith (args, binary_string))
{
binary_flag = 1;
args += strlen (binary_string);
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 65232da..acd27e6 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -800,7 +800,7 @@ locate_arg (char *p)
{
while ((p = strchr (p, '$')))
{
- if (strncmp (p, "$arg", 4) == 0
+ if (startswith (p, "$arg")
&& (isdigit (p[4]) || p[4] == 'c'))
return p;
p++;
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 366d828..e9053ad 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -672,8 +672,8 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags)
symbol in OBJFILE. Note that 'maintenance print msymbols'
shows that type of these "_imp_XXXX" symbols is mst_data. */
if (MSYMBOL_TYPE (msym) == mst_data
- && (strncmp (name, "__imp_", 6) == 0
- || strncmp (name, "_imp_", 5) == 0))
+ && (startswith (name, "__imp_")
+ || startswith (name, "_imp_")))
{
const char *name1 = (name[1] == '_' ? &name[7] : &name[6]);
struct bound_minimal_symbol found;
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);
+}
diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h
index 60aa030..c887b6b 100644
--- a/gdb/common/common-utils.h
+++ b/gdb/common/common-utils.h
@@ -68,4 +68,9 @@ char *savestring (const char *ptr, size_t len);

extern char *safe_strerror (int);

+/* Return nonzero if the first strlen(S2) bytes of S1 match S2, zero
+ otherwise. */
+
+extern int startswith (const char *s1, const char *s2);
+
#endif
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index c204a13..07c55ad 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -172,7 +172,7 @@ do_rmdir (void *arg)
char *zap;
int wstat;

- gdb_assert (strncmp (dir, TMP_PREFIX, strlen (TMP_PREFIX)) == 0);
+ gdb_assert (startswith (dir, TMP_PREFIX));
zap = concat ("rm -rf ", dir, (char *) NULL);
wstat = system (zap);
if (wstat == -1 || !WIFEXITED (wstat) || WEXITSTATUS (wstat) != 0)
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 4f60e10..e60595e 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -2547,7 +2547,7 @@ read_ofile_symtab (struct objfile *objfile, struct partial_symtab *pst)
processing_gcc_compilation = 2;
if (tempstring[0] == bfd_get_symbol_leading_char (symfile_bfd))
++tempstring;
- if (strncmp (tempstring, "__gnu_compiled", 14) == 0)
+ if (startswith (tempstring, "__gnu_compiled"))
processing_gcc_compilation = 2;
}
}
diff --git a/gdb/dictionary.c b/gdb/dictionary.c
index 2c81182..a16955a 100644
--- a/gdb/dictionary.c
+++ b/gdb/dictionary.c
@@ -806,7 +806,7 @@ dict_hash (const char *string0)
string = string0;
if (*string == '_')
{
- if (strncmp (string, "_ada_", 5) == 0)
+ if (startswith (string, "_ada_"))
string += 5;
else
return msymbol_hash_iw (string0);
diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c
index 71e3f6b..ab6b09a 100644
--- a/gdb/dwarf2-frame.c
+++ b/gdb/dwarf2-frame.c
@@ -1935,7 +1935,7 @@ decode_frame_entry_1 (struct comp_unit *unit, const gdb_byte *start,

/* Ignore armcc augmentations. We only use them for quirks,
and that doesn't happen until later. */
- if (strncmp (augmentation, "armcc", 5) == 0)
+ if (startswith (augmentation, "armcc"))
augmentation += strlen (augmentation);

/* The GCC 2.x "eh" augmentation has a pointer immediately
diff --git a/gdb/gdbserver/hostio.c b/gdb/gdbserver/hostio.c
index e6b7754..ec29eb9 100644
--- a/gdb/gdbserver/hostio.c
+++ b/gdb/gdbserver/hostio.c
@@ -511,17 +511,17 @@ handle_readlink (char *own_buf, int *new_packet_len)
int
handle_vFile (char *own_buf, int packet_len, int *new_packet_len)
{
- if (strncmp (own_buf, "vFile:open:", 11) == 0)
+ if (startswith (own_buf, "vFile:open:"))
handle_open (own_buf);
- else if (strncmp (own_buf, "vFile:pread:", 12) == 0)
+ else if (startswith (own_buf, "vFile:pread:"))
handle_pread (own_buf, new_packet_len);
- else if (strncmp (own_buf, "vFile:pwrite:", 13) == 0)
+ else if (startswith (own_buf, "vFile:pwrite:"))
handle_pwrite (own_buf, packet_len);
- else if (strncmp (own_buf, "vFile:close:", 12) == 0)
+ else if (startswith (own_buf, "vFile:close:"))
handle_close (own_buf);
- else if (strncmp (own_buf, "vFile:unlink:", 13) == 0)
+ else if (startswith (own_buf, "vFile:unlink:"))
handle_unlink (own_buf);
- else if (strncmp (own_buf, "vFile:readlink:", 15) == 0)
+ else if (startswith (own_buf, "vFile:readlink:"))
handle_readlink (own_buf, new_packet_len);
else
return 0;
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 452d0fc..eee502e 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -5797,9 +5797,9 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf,
break;

len = sep - annex;
- if (len == 5 && strncmp (annex, "start", 5) == 0)
+ if (len == 5 && startswith (annex, "start"))
addrp = &lm_addr;
- else if (len == 4 && strncmp (annex, "prev", 4) == 0)
+ else if (len == 4 && startswith (annex, "prev"))
addrp = &lm_prev;
else
{
diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
index c376cab..f5adcb5 100644
--- a/gdb/gdbserver/linux-x86-low.c
+++ b/gdb/gdbserver/linux-x86-low.c
@@ -1523,7 +1523,7 @@ x86_linux_process_qsupported (const char *query)
with "i386" in qSupported query, it supports x86 XML target
descriptions. */
use_xml = 0;
- if (query != NULL && strncmp (query, "xmlRegisters=", 13) == 0)
+ if (query != NULL && startswith (query, "xmlRegisters="))
{
char *copy = xstrdup (query + 13);
char *p;
diff --git a/gdb/gdbserver/notif.c b/gdb/gdbserver/notif.c
index ba2af77..436c1b8 100644
--- a/gdb/gdbserver/notif.c
+++ b/gdb/gdbserver/notif.c
@@ -86,7 +86,7 @@ handle_notif_ack (char *own_buf, int packet_len)
{
const char *ack_name = notifs[i]->ack_name;

- if (strncmp (own_buf, ack_name, strlen (ack_name)) == 0
+ if (startswith (own_buf, ack_name)
&& packet_len == strlen (ack_name))
break;
}
diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c
index 8854c4c..48dc6e5 100644
--- a/gdb/gdbserver/remote-utils.c
+++ b/gdb/gdbserver/remote-utils.c
@@ -531,7 +531,7 @@ hex_or_minus_one (char *buf, char **obuf)
{
ULONGEST ret;

- if (strncmp (buf, "-1", 2) == 0)
+ if (startswith (buf, "-1"))
{
ret = (ULONGEST) -1;
buf += 2;
@@ -1437,7 +1437,7 @@ look_up_one_symbol (const char *name, CORE_ADDR *addrp, int may_ask_gdb)
return -1;
}

- if (strncmp (own_buf, "qSymbol:", strlen ("qSymbol:")) != 0)
+ if (!startswith (own_buf, "qSymbol:"))
{
warning ("Malformed response to qSymbol, ignoring: %s\n", own_buf);
return -1;
@@ -1546,7 +1546,7 @@ relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc)
return -1;
}

- if (strncmp (own_buf, "qRelocInsn:", strlen ("qRelocInsn:")) != 0)
+ if (!startswith (own_buf, "qRelocInsn:"))
{
warning ("Malformed response to qRelocInsn, ignoring: %s\n",
own_buf);
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 156fcc8..120b8ed 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -427,7 +427,7 @@ handle_btrace_general_set (char *own_buf)
const char *err;
char *op;

- if (strncmp ("Qbtrace:", own_buf, strlen ("Qbtrace:")) != 0)
+ if (!startswith (own_buf, "Qbtrace:"))
return 0;

op = own_buf + strlen ("Qbtrace:");
@@ -471,7 +471,7 @@ handle_btrace_conf_general_set (char *own_buf)
struct thread_info *thread;
char *op;

- if (strncmp ("Qbtrace-conf:", own_buf, strlen ("Qbtrace-conf:")) != 0)
+ if (!startswith (own_buf, "Qbtrace-conf:"))
return 0;

op = own_buf + strlen ("Qbtrace-conf:");
@@ -490,7 +490,7 @@ handle_btrace_conf_general_set (char *own_buf)
return -1;
}

- if (strncmp (op, "bts:size=", strlen ("bts:size=")) == 0)
+ if (startswith (op, "bts:size="))
{
unsigned long size;
char *endp = NULL;
@@ -520,7 +520,7 @@ handle_btrace_conf_general_set (char *own_buf)
static void
handle_general_set (char *own_buf)
{
- if (strncmp ("QPassSignals:", own_buf, strlen ("QPassSignals:")) == 0)
+ if (startswith (own_buf, "QPassSignals:"))
{
int numsigs = (int) GDB_SIGNAL_LAST, i;
const char *p = own_buf + strlen ("QPassSignals:");
@@ -545,7 +545,7 @@ handle_general_set (char *own_buf)
return;
}

- if (strncmp ("QProgramSignals:", own_buf, strlen ("QProgramSignals:")) == 0)
+ if (startswith (own_buf, "QProgramSignals:"))
{
int numsigs = (int) GDB_SIGNAL_LAST, i;
const char *p = own_buf + strlen ("QProgramSignals:");
@@ -585,7 +585,7 @@ handle_general_set (char *own_buf)
return;
}

- if (strncmp (own_buf, "QNonStop:", 9) == 0)
+ if (startswith (own_buf, "QNonStop:"))
{
char *mode = own_buf + 9;
int req = -1;
@@ -622,8 +622,7 @@ handle_general_set (char *own_buf)
return;
}

- if (strncmp ("QDisableRandomization:", own_buf,
- strlen ("QDisableRandomization:")) == 0)
+ if (startswith (own_buf, "QDisableRandomization:"))
{
char *packet = own_buf + strlen ("QDisableRandomization:");
ULONGEST setting;
@@ -647,7 +646,7 @@ handle_general_set (char *own_buf)
&& handle_tracepoint_general_set (own_buf))
return;

- if (strncmp ("QAgent:", own_buf, strlen ("QAgent:")) == 0)
+ if (startswith (own_buf, "QAgent:"))
{
char *mode = own_buf + strlen ("QAgent:");
int req = 0;
@@ -1659,7 +1658,7 @@ handle_qxfer (char *own_buf, int packet_len, int *new_packet_len_p)
char *annex;
char *offset;

- if (strncmp (own_buf, "qXfer:", 6) != 0)
+ if (!startswith (own_buf, "qXfer:"))
return 0;

/* Grab the object, r/w and annex. */
@@ -1933,7 +1932,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
}

/* Protocol features query. */
- if (strncmp ("qSupported", own_buf, 10) == 0
+ if (startswith (own_buf, "qSupported")
&& (own_buf[10] == ':' || own_buf[10] == '\0'))
{
char *p = &own_buf[10];
@@ -2066,7 +2065,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)

/* Thread-local storage support. */
if (the_target->get_tls_address != NULL
- && strncmp ("qGetTLSAddr:", own_buf, 12) == 0)
+ && startswith (own_buf, "qGetTLSAddr:"))
{
char *p = own_buf + 12;
CORE_ADDR parts[2], address = 0;
@@ -2131,7 +2130,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)

/* Windows OS Thread Information Block address support. */
if (the_target->get_tib_address != NULL
- && strncmp ("qGetTIBAddr:", own_buf, 12) == 0)
+ && startswith (own_buf, "qGetTIBAddr:"))
{
char *annex;
int n;
@@ -2153,7 +2152,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
}

/* Handle "monitor" commands. */
- if (strncmp ("qRcmd,", own_buf, 6) == 0)
+ if (startswith (own_buf, "qRcmd,"))
{
char *mon = malloc (PBUFSIZ);
int len = strlen (own_buf + 6);
@@ -2219,7 +2218,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
return;
}

- if (strncmp ("qCRC:", own_buf, 5) == 0)
+ if (startswith (own_buf, "qCRC:"))
{
/* CRC check (compare-section). */
char *comma;
@@ -2649,14 +2648,14 @@ handle_v_requests (char *own_buf, int packet_len, int *new_packet_len)
{
if (!disable_packet_vCont)
{
- if (strncmp (own_buf, "vCont;", 6) == 0)
+ if (startswith (own_buf, "vCont;"))
{
require_running (own_buf);
handle_v_cont (own_buf);
return;
}

- if (strncmp (own_buf, "vCont?", 6) == 0)
+ if (startswith (own_buf, "vCont?"))
{
strcpy (own_buf, "vCont;c;C;s;S;t");
if (target_supports_range_stepping ())
@@ -2668,11 +2667,11 @@ handle_v_requests (char *own_buf, int packet_len, int *new_packet_len)
}
}

- if (strncmp (own_buf, "vFile:", 6) == 0
+ if (startswith (own_buf, "vFile:")
&& handle_vFile (own_buf, packet_len, new_packet_len))
return;

- if (strncmp (own_buf, "vAttach;", 8) == 0)
+ if (startswith (own_buf, "vAttach;"))
{
if ((!extended_protocol || !multi_process) && target_running ())
{
@@ -2684,7 +2683,7 @@ handle_v_requests (char *own_buf, int packet_len, int *new_packet_len)
return;
}

- if (strncmp (own_buf, "vRun;", 5) == 0)
+ if (startswith (own_buf, "vRun;"))
{
if ((!extended_protocol || !multi_process) && target_running ())
{
@@ -2696,7 +2695,7 @@ handle_v_requests (char *own_buf, int packet_len, int *new_packet_len)
return;
}

- if (strncmp (own_buf, "vKill;", 6) == 0)
+ if (startswith (own_buf, "vKill;"))
{
if (!target_running ())
{
@@ -3508,7 +3507,7 @@ process_point_options (struct breakpoint *bp, char **packet)
if (!add_breakpoint_condition (bp, &dataptr))
skip_to_semicolon (&dataptr);
}
- else if (strncmp (dataptr, "cmds:", strlen ("cmds:")) == 0)
+ else if (startswith (dataptr, "cmds:"))
{
dataptr += strlen ("cmds:");
if (debug_threads)
diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c
index 6fcd0b0..a2fa411 100644
--- a/gdb/gdbserver/tracepoint.c
+++ b/gdb/gdbserver/tracepoint.c
@@ -3551,14 +3551,14 @@ cmd_qtframe (char *own_buf)

packet += strlen ("QTFrame:");

- if (strncmp (packet, "pc:", strlen ("pc:")) == 0)
+ if (startswith (packet, "pc:"))
{
packet += strlen ("pc:");
unpack_varlen_hex (packet, &pc);
trace_debug ("Want to find next traceframe at pc=0x%s", paddress (pc));
tframe = find_next_traceframe_in_range (pc, pc, 1, &tfnum);
}
- else if (strncmp (packet, "range:", strlen ("range:")) == 0)
+ else if (startswith (packet, "range:"))
{
packet += strlen ("range:");
packet = unpack_varlen_hex (packet, &lo);
@@ -3568,7 +3568,7 @@ cmd_qtframe (char *own_buf)
paddress (lo), paddress (hi));
tframe = find_next_traceframe_in_range (lo, hi, 1, &tfnum);
}
- else if (strncmp (packet, "outside:", strlen ("outside:")) == 0)
+ else if (startswith (packet, "outside:"))
{
packet += strlen ("outside:");
packet = unpack_varlen_hex (packet, &lo);
@@ -3579,7 +3579,7 @@ cmd_qtframe (char *own_buf)
paddress (lo), paddress (hi));
tframe = find_next_traceframe_in_range (lo, hi, 0, &tfnum);
}
- else if (strncmp (packet, "tdp:", strlen ("tdp:")) == 0)
+ else if (startswith (packet, "tdp:"))
{
packet += strlen ("tdp:");
unpack_varlen_hex (packet, &num);
@@ -3653,7 +3653,7 @@ cmd_qtstatus (char *packet)
/* The user visible error string in terror needs to be hex encoded.
We leave it as plain string in `tracing_stop_reason' to ease
debugging. */
- if (strncmp (stop_reason_rsp, "terror:", strlen ("terror:")) == 0)
+ if (startswith (stop_reason_rsp, "terror:"))
{
const char *result_name;
int hexstr_len;
@@ -4106,7 +4106,7 @@ cmd_qtnotes (char *own_buf)

while (*packet)
{
- if (strncmp ("user:", packet, strlen ("user:")) == 0)
+ if (startswith (packet, "user:"))
{
packet += strlen ("user:");
saved = packet;
@@ -4120,7 +4120,7 @@ cmd_qtnotes (char *own_buf)
xfree (tracing_user_name);
tracing_user_name = user;
}
- else if (strncmp ("notes:", packet, strlen ("notes:")) == 0)
+ else if (startswith (packet, "notes:"))
{
packet += strlen ("notes:");
saved = packet;
@@ -4134,7 +4134,7 @@ cmd_qtnotes (char *own_buf)
xfree (tracing_notes);
tracing_notes = notes;
}
- else if (strncmp ("tstop:", packet, strlen ("tstop:")) == 0)
+ else if (startswith (packet, "tstop:"))
{
packet += strlen ("tstop:");
saved = packet;
@@ -4163,32 +4163,32 @@ handle_tracepoint_general_set (char *packet)
cmd_qtinit (packet);
return 1;
}
- else if (strncmp ("QTDP:", packet, strlen ("QTDP:")) == 0)
+ else if (startswith (packet, "QTDP:"))
{
cmd_qtdp (packet);
return 1;
}
- else if (strncmp ("QTDPsrc:", packet, strlen ("QTDPsrc:")) == 0)
+ else if (startswith (packet, "QTDPsrc:"))
{
cmd_qtdpsrc (packet);
return 1;
}
- else if (strncmp ("QTEnable:", packet, strlen ("QTEnable:")) == 0)
+ else if (startswith (packet, "QTEnable:"))
{
cmd_qtenable_disable (packet, 1);
return 1;
}
- else if (strncmp ("QTDisable:", packet, strlen ("QTDisable:")) == 0)
+ else if (startswith (packet, "QTDisable:"))
{
cmd_qtenable_disable (packet, 0);
return 1;
}
- else if (strncmp ("QTDV:", packet, strlen ("QTDV:")) == 0)
+ else if (startswith (packet, "QTDV:"))
{
cmd_qtdv (packet);
return 1;
}
- else if (strncmp ("QTro:", packet, strlen ("QTro:")) == 0)
+ else if (startswith (packet, "QTro:"))
{
cmd_qtro (packet);
return 1;
@@ -4203,28 +4203,27 @@ handle_tracepoint_general_set (char *packet)
cmd_qtstop (packet);
return 1;
}
- else if (strncmp ("QTDisconnected:", packet,
- strlen ("QTDisconnected:")) == 0)
+ else if (startswith (packet, "QTDisconnected:"))
{
cmd_qtdisconnected (packet);
return 1;
}
- else if (strncmp ("QTFrame:", packet, strlen ("QTFrame:")) == 0)
+ else if (startswith (packet, "QTFrame:"))
{
cmd_qtframe (packet);
return 1;
}
- else if (strncmp ("QTBuffer:circular:", packet, strlen ("QTBuffer:circular:")) == 0)
+ else if (startswith (packet, "QTBuffer:circular:"))
{
cmd_bigqtbuffer_circular (packet);
return 1;
}
- else if (strncmp ("QTBuffer:size:", packet, strlen ("QTBuffer:size:")) == 0)
+ else if (startswith (packet, "QTBuffer:size:"))
{
cmd_bigqtbuffer_size (packet);
return 1;
}
- else if (strncmp ("QTNotes:", packet, strlen ("QTNotes:")) == 0)
+ else if (startswith (packet, "QTNotes:"))
{
cmd_qtnotes (packet);
return 1;
@@ -4241,7 +4240,7 @@ handle_tracepoint_query (char *packet)
cmd_qtstatus (packet);
return 1;
}
- else if (strncmp ("qTP:", packet, strlen ("qTP:")) == 0)
+ else if (startswith (packet, "qTP:"))
{
cmd_qtp (packet);
return 1;
@@ -4266,12 +4265,12 @@ handle_tracepoint_query (char *packet)
cmd_qtsv (packet);
return 1;
}
- else if (strncmp ("qTV:", packet, strlen ("qTV:")) == 0)
+ else if (startswith (packet, "qTV:"))
{
cmd_qtv (packet);
return 1;
}
- else if (strncmp ("qTBuffer:", packet, strlen ("qTBuffer:")) == 0)
+ else if (startswith (packet, "qTBuffer:"))
{
cmd_qtbuffer (packet);
return 1;
@@ -4286,7 +4285,7 @@ handle_tracepoint_query (char *packet)
cmd_qtsstm (packet);
return 1;
}
- else if (strncmp ("qTSTMat:", packet, strlen ("qTSTMat:")) == 0)
+ else if (startswith (packet, "qTSTMat:"))
{
cmd_qtstmat (packet);
return 1;
@@ -6123,7 +6122,7 @@ tracepoint_send_agent (struct tracepoint *tpoint)
if (ret)
return ret;

- if (strncmp (buf, "OK", 2) != 0)
+ if (!startswith (buf, "OK"))
return 1;

/* The value of tracepoint's target address is stored in BUF. */
@@ -7202,7 +7201,7 @@ gdb_agent_helper_thread (void *arg)

if (cmd_buf[0])
{
- if (strncmp ("close", cmd_buf, 5) == 0)
+ if (startswith (cmd_buf, "close"))
{
stop_loop = 1;
}
diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c
index e3fb618..d496456 100644
--- a/gdb/gdbserver/win32-low.c
+++ b/gdb/gdbserver/win32-low.c
@@ -778,7 +778,7 @@ handle_output_debug_string (struct target_waitstatus *ourstatus)
return;
}

- if (strncmp (s, "cYg", 3) != 0)
+ if (!startswith (s, "cYg"))
{
if (!server_waiting)
{
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 24f64be..5268dc8 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2376,7 +2376,7 @@ check_stub_method (struct type *type, int method_id, int signature_id)
}

/* If we read one argument and it was ``void'', don't count it. */
- if (strncmp (argtypetext, "(void)", 6) == 0)
+ if (startswith (argtypetext, "(void)"))
argcount -= 1;

/* We need one extra slot, for the THIS pointer. */
diff --git a/gdb/gnu-v2-abi.c b/gdb/gnu-v2-abi.c
index 5389374..68b734c 100644
--- a/gdb/gnu-v2-abi.c
+++ b/gdb/gnu-v2-abi.c
@@ -37,7 +37,7 @@ static enum dtor_kinds
gnuv2_is_destructor_name (const char *name)
{
if ((name[0] == '_' && is_cplus_marker (name[1]) && name[2] == '_')
- || strncmp (name, "__dt__", 6) == 0)
+ || startswith (name, "__dt__"))
return complete_object_dtor;
else
return 0;
@@ -48,7 +48,7 @@ gnuv2_is_constructor_name (const char *name)
{
if ((name[0] == '_' && name[1] == '_'
&& (isdigit (name[2]) || strchr ("Qt", name[2])))
- || strncmp (name, "__ct__", 6) == 0)
+ || startswith (name, "__ct__"))
return complete_object_ctor;
else
return 0;
@@ -68,7 +68,7 @@ gnuv2_is_vtable_name (const char *name)
static int
gnuv2_is_operator_name (const char *name)
{
- return strncmp (name, "operator", 8) == 0;
+ return startswith (name, "operator");
}

\f
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index 6a96d21..2240618 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -39,13 +39,13 @@ static struct gdbarch_data *std_type_info_gdbarch_data;
static int
gnuv3_is_vtable_name (const char *name)
{
- return strncmp (name, "_ZTV", 4) == 0;
+ return startswith (name, "_ZTV");
}

static int
gnuv3_is_operator_name (const char *name)
{
- return strncmp (name, "operator", 8) == 0;
+ return startswith (name, "operator");
}

diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 9bdc99a..b48467d 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -233,8 +233,8 @@ unpack_mangled_go_symbol (const char *mangled_name,
libgo_.*: used by gccgo's runtime

Thus we don't support -fgo-prefix (except as used by the runtime). */
- if (strncmp (mangled_name, "go.", 3) != 0
- && strncmp (mangled_name, "libgo_", 6) != 0)
+ if (!startswith (mangled_name, "go.")
+ && !startswith (mangled_name, "libgo_"))
return NULL;

/* Quick check for whether a search may be fruitful. */
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 8c08f8b..c08f6fc 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -3854,8 +3854,8 @@ i386_pe_skip_trampoline_code (struct frame_info *frame,

if (symname)
{
- if (strncmp (symname, "__imp_", 6) == 0
- || strncmp (symname, "_imp_", 5) == 0)
+ if (startswith (symname, "__imp_")
+ || startswith (symname, "_imp_"))
return name ? 1 :
read_memory_unsigned_integer (indirect, 4, byte_order);
}
diff --git a/gdb/i386obsd-tdep.c b/gdb/i386obsd-tdep.c
index 5e1d7f8..eae445c 100644
--- a/gdb/i386obsd-tdep.c
+++ b/gdb/i386obsd-tdep.c
@@ -357,7 +357,7 @@ i386obsd_trapframe_cache (struct frame_info *this_frame, void **this_cache)
sp = get_frame_register_unsigned (this_frame, I386_ESP_REGNUM);

find_pc_partial_function (func, &name, NULL, NULL);
- if (name && strncmp (name, "Xintr", 5) == 0)
+ if (name && startswith (name, "Xintr"))
addr = sp + 8; /* It's an interrupt frame. */
else
addr = sp;
@@ -420,8 +420,8 @@ i386obsd_trapframe_sniffer (const struct frame_unwind *self,
find_pc_partial_function (get_frame_pc (this_frame), &name, NULL, NULL);
return (name && (strcmp (name, "calltrap") == 0
|| strcmp (name, "syscall1") == 0
- || strncmp (name, "Xintr", 5) == 0
- || strncmp (name, "Xsoft", 5) == 0));
+ || startswith (name, "Xintr")
+ || startswith (name, "Xsoft")));
}

static const struct frame_unwind i386obsd_trapframe_unwind = {
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 0d012b4..36b59ac 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1122,9 +1122,9 @@ find_methods (struct type *t, const char *name,
const char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
char dem_opname[64];

- if (strncmp (method_name, "__", 2) == 0 ||
- strncmp (method_name, "op", 2) == 0 ||
- strncmp (method_name, "type", 4) == 0)
+ if (startswith (method_name, "__") ||
+ startswith (method_name, "op") ||
+ startswith (method_name, "type"))
{
if (cplus_demangle_opname (method_name, dem_opname, DMGL_ANSI))
method_name = dem_opname;
@@ -1210,7 +1210,7 @@ find_toplevel_string (const char *haystack, const char *needle)
if (s != NULL)
{
/* Found first char in HAYSTACK; check rest of string. */
- if (strncmp (s, needle, strlen (needle)) == 0)
+ if (startswith (s, needle))
return s;

/* Didn't find it; loop over HAYSTACK, looking for the next
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 2e1133d..b43ca55 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -4125,13 +4125,13 @@ linux_proc_pending_signals (int pid, sigset_t *pending,
Unfortunately some Red Hat kernels include the shared pending
queue but not the ShdPnd status field. */

- if (strncmp (buffer, "SigPnd:\t", 8) == 0)
+ if (startswith (buffer, "SigPnd:\t"))
add_line_to_sigset (buffer + 8, pending);
- else if (strncmp (buffer, "ShdPnd:\t", 8) == 0)
+ else if (startswith (buffer, "ShdPnd:\t"))
add_line_to_sigset (buffer + 8, pending);
- else if (strncmp (buffer, "SigBlk:\t", 8) == 0)
+ else if (startswith (buffer, "SigBlk:\t"))
add_line_to_sigset (buffer + 8, blocked);
- else if (strncmp (buffer, "SigIgn:\t", 8) == 0)
+ else if (startswith (buffer, "SigIgn:\t"))
add_line_to_sigset (buffer + 8, ignored);
}

diff --git a/gdb/machoread.c b/gdb/machoread.c
index 790f665..831bbcb 100644
--- a/gdb/machoread.c
+++ b/gdb/machoread.c
@@ -1004,7 +1004,7 @@ macho_symfile_offsets (struct objfile *objfile,
const char *bfd_sect_name = osect->the_bfd_section->name;
int sect_index = osect - objfile->sections;;

- if (strncmp (bfd_sect_name, "LC_SEGMENT.", 11) == 0)
+ if (startswith (bfd_sect_name, "LC_SEGMENT."))
bfd_sect_name += 11;
if (strcmp (bfd_sect_name, "__TEXT") == 0
|| strcmp (bfd_sect_name, "__TEXT.__text") == 0)
diff --git a/gdb/microblaze-rom.c b/gdb/microblaze-rom.c
index 66251db..beffadf 100644
--- a/gdb/microblaze-rom.c
+++ b/gdb/microblaze-rom.c
@@ -83,7 +83,7 @@ picobug_dumpregs (struct regcache *regcache)
if (strchr (p, '-'))
{
/* Got a range. Either r0-r7, r8-r15 or ss0-ss4. */
- if (strncmp (p, "r0", 2) == 0 || strncmp (p, "r8", 2) == 0)
+ if (startswith (p, "r0") || startswith (p, "r8"))
{
int rn = (p[1] == '0' ? 0 : 8);
int i = 0;
@@ -97,7 +97,7 @@ picobug_dumpregs (struct regcache *regcache)
i++;
}
}
- else if (strncmp (p, "ss", 2) == 0)
+ else if (startswith (p, "ss"))
{
/* Get the next five values, ignoring the first. */
int rn;
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index f8985e8..d7097a9 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -996,7 +996,7 @@ prim_record_minimal_symbol_full (const char *name, int name_len, int copy_name,
--name_len;
}

- if (ms_type == mst_file_text && strncmp (name, "__gnu_compiled", 14) == 0)
+ if (ms_type == mst_file_text && startswith (name, "__gnu_compiled"))
return (NULL);

if (msym_bunch_index == BUNCH_SIZE)
diff --git a/gdb/mips-sde-tdep.c b/gdb/mips-sde-tdep.c
index eb171bf..0246b27 100644
--- a/gdb/mips-sde-tdep.c
+++ b/gdb/mips-sde-tdep.c
@@ -212,7 +212,7 @@ mips_sde_elf_osabi_sniff_abi_tag_sections (bfd *abfd, asection *sect,

/* The presence of a section with a ".sde" prefix is indicative
of an SDE binary. */
- if (strncmp (name, ".sde", 4) == 0)
+ if (startswith (name, ".sde"))
*os_ident_ptr = GDB_OSABI_SDE;
}

diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index bd8faef..793606b 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -1345,14 +1345,13 @@ mips_in_frame_stub (CORE_ADDR pc)
return 0;

/* If the PC is in __mips16_call_stub_*, this is a call/return stub. */
- if (strncmp (name, mips_str_mips16_call_stub,
- strlen (mips_str_mips16_call_stub)) == 0)
+ if (startswith (name, mips_str_mips16_call_stub))
return 1;
/* If the PC is in __call_stub_*, this is a call/return or a call stub. */
- if (strncmp (name, mips_str_call_stub, strlen (mips_str_call_stub)) == 0)
+ if (startswith (name, mips_str_call_stub))
return 1;
/* If the PC is in __fn_stub_*, this is a call stub. */
- if (strncmp (name, mips_str_fn_stub, strlen (mips_str_fn_stub)) == 0)
+ if (startswith (name, mips_str_fn_stub))
return 1;

return 0; /* Not a stub. */
@@ -7846,8 +7845,8 @@ mips_skip_mips16_trampoline_code (struct frame_info *frame, CORE_ADDR pc)

/* If the PC is in __call_stub_* or __fn_stub*, this is one of the
compiler-generated call or call/return stubs. */
- if (strncmp (name, mips_str_fn_stub, strlen (mips_str_fn_stub)) == 0
- || strncmp (name, mips_str_call_stub, strlen (mips_str_call_stub)) == 0)
+ if (startswith (name, mips_str_fn_stub)
+ || startswith (name, mips_str_call_stub))
{
if (pc == start_addr)
/* This is the 'call' part of a call stub. Call this helper
@@ -8099,7 +8098,7 @@ mips_find_abi_section (bfd *abfd, asection *sect, void *obj)
if (*abip != MIPS_ABI_UNKNOWN)
return;

- if (strncmp (name, ".mdebug.", 8) != 0)
+ if (!startswith (name, ".mdebug."))
return;

if (strcmp (name, ".mdebug.abi32") == 0)
@@ -8124,11 +8123,11 @@ mips_find_long_section (bfd *abfd, asection *sect, void *obj)
int *lbp = (int *) obj;
const char *name = bfd_get_section_name (abfd, sect);

- if (strncmp (name, ".gcc_compiled_long32", 20) == 0)
+ if (startswith (name, ".gcc_compiled_long32"))
*lbp = 32;
- else if (strncmp (name, ".gcc_compiled_long64", 20) == 0)
+ else if (startswith (name, ".gcc_compiled_long64"))
*lbp = 64;
- else if (strncmp (name, ".gcc_compiled_long", 18) == 0)
+ else if (startswith (name, ".gcc_compiled_long"))
warning (_("unrecognized .gcc_compiled_longXX"));
}

diff --git a/gdb/msp430-tdep.c b/gdb/msp430-tdep.c
index f4ee41a..622ce55 100644
--- a/gdb/msp430-tdep.c
+++ b/gdb/msp430-tdep.c
@@ -834,8 +834,7 @@ msp430_in_return_stub (struct gdbarch *gdbarch, CORE_ADDR pc,
const char *name)
{
return (name != NULL
- && strncmp (msp430_epilog_name_prefix, name,
- strlen (msp430_epilog_name_prefix)) == 0);
+ && startswith (name, msp430_epilog_name_prefix));
}

/* Implement the "skip_trampoline_code" gdbarch method. */
diff --git a/gdb/nat/linux-procfs.c b/gdb/nat/linux-procfs.c
index 1e922b9..f149383 100644
--- a/gdb/nat/linux-procfs.c
+++ b/gdb/nat/linux-procfs.c
@@ -93,7 +93,7 @@ linux_proc_pid_get_state (pid_t pid, char *buffer, size_t buffer_size,

have_state = 0;
while (fgets (buffer, buffer_size, procfile) != NULL)
- if (strncmp (buffer, "State:", 6) == 0)
+ if (startswith (buffer, "State:"))
{
have_state = 1;
break;
diff --git a/gdb/nbsd-tdep.c b/gdb/nbsd-tdep.c
index 59d97d4..762d80f 100644
--- a/gdb/nbsd-tdep.c
+++ b/gdb/nbsd-tdep.c
@@ -45,5 +45,5 @@ nbsd_pc_in_sigtramp (CORE_ADDR pc, const char *func_name)
have function names which begin with "__sigtramp". */

return (func_name != NULL
- && strncmp (func_name, "__sigtramp", 10) == 0);
+ && startswith (func_name, "__sigtramp"));
}
diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c
index 5a7a887..7911ffd 100644
--- a/gdb/p-typeprint.c
+++ b/gdb/p-typeprint.c
@@ -154,8 +154,8 @@ void
pascal_type_print_method_args (const char *physname, const char *methodname,
struct ui_file *stream)
{
- int is_constructor = (strncmp (physname, "__ct__", 6) == 0);
- int is_destructor = (strncmp (physname, "__dt__", 6) == 0);
+ int is_constructor = (startswith (physname, "__ct__"));
+ int is_destructor = (startswith (physname, "__dt__"));

if (is_constructor || is_destructor)
{
@@ -643,8 +643,8 @@ pascal_type_print_base (struct type *type, struct ui_file *stream, int show,
{
const char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);

- int is_constructor = (strncmp (physname, "__ct__", 6) == 0);
- int is_destructor = (strncmp (physname, "__dt__", 6) == 0);
+ int is_constructor = (startswith (physname, "__ct__"));
+ int is_destructor = (startswith (physname, "__dt__"));

QUIT;
if (TYPE_FN_FIELD_PROTECTED (f, j))
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 9373ceb..366eba0 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -1342,7 +1342,7 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
t = n;
}
/* Chop a leading builtin_type. */
- if (strncmp (t, blt, strlen (blt)) == 0)
+ if (startswith (t, blt))
t += strlen (blt);
}
fprintf_unfiltered (file, " %-15s", t);
diff --git a/gdb/remote-m32r-sdi.c b/gdb/remote-m32r-sdi.c
index c55b75c..f7ea0b8 100644
--- a/gdb/remote-m32r-sdi.c
+++ b/gdb/remote-m32r-sdi.c
@@ -1265,9 +1265,9 @@ m32r_load (struct target_ops *self, const char *args, int from_tty)

if (*arg != '-')
filename = arg;
- else if (strncmp (arg, "-quiet", strlen (arg)) == 0)
+ else if (startswith ("-quiet", arg))
quiet = 1;
- else if (strncmp (arg, "-nostart", strlen (arg)) == 0)
+ else if (startswith ("-nostart", arg))
nostart = 1;
else
error (_("Unknown option `%s'"), arg);
diff --git a/gdb/remote-notif.c b/gdb/remote-notif.c
index 3e07fc7..2d24a9a 100644
--- a/gdb/remote-notif.c
+++ b/gdb/remote-notif.c
@@ -133,7 +133,7 @@ handle_notification (struct remote_notif_state *state, char *buf)
{
const char *name = notifs[i]->name;

- if (strncmp (buf, name, strlen (name)) == 0
+ if (startswith (buf, name)
&& buf[strlen (name)] == ':')
break;
}
diff --git a/gdb/remote.c b/gdb/remote.c
index 2a823eb..330a873 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -491,7 +491,7 @@ remote_get_noisy_reply (char **buf_p,
buf = *buf_p;
if (buf[0] == 'E')
trace_error (buf);
- else if (strncmp (buf, "qRelocInsn:", strlen ("qRelocInsn:")) == 0)
+ else if (startswith (buf, "qRelocInsn:"))
{
ULONGEST ul;
CORE_ADDR from, to, org_to;
@@ -3142,14 +3142,14 @@ get_offsets (void)
ptr = buf;
lose = 0;

- if (strncmp (ptr, "Text=", 5) == 0)
+ if (startswith (ptr, "Text="))
{
ptr += 5;
/* Don't use strtol, could lose on big values. */
while (*ptr && *ptr != ';')
text_addr = (text_addr << 4) + fromhex (*ptr++);

- if (strncmp (ptr, ";Data=", 6) == 0)
+ if (startswith (ptr, ";Data="))
{
ptr += 6;
while (*ptr && *ptr != ';')
@@ -3158,7 +3158,7 @@ get_offsets (void)
else
lose = 1;

- if (!lose && strncmp (ptr, ";Bss=", 5) == 0)
+ if (!lose && startswith (ptr, ";Bss="))
{
ptr += 5;
while (*ptr && *ptr != ';')
@@ -3170,7 +3170,7 @@ get_offsets (void)
else
lose = 1;
}
- else if (strncmp (ptr, "TextSeg=", 8) == 0)
+ else if (startswith (ptr, "TextSeg="))
{
ptr += 8;
/* Don't use strtol, could lose on big values. */
@@ -3178,7 +3178,7 @@ get_offsets (void)
text_addr = (text_addr << 4) + fromhex (*ptr++);
num_segments = 1;

- if (strncmp (ptr, ";DataSeg=", 9) == 0)
+ if (startswith (ptr, ";DataSeg="))
{
ptr += 9;
while (*ptr && *ptr != ';')
@@ -3785,7 +3785,7 @@ remote_check_symbols (void)
packet_ok (rs->buf, &remote_protocol_packets[PACKET_qSymbol]);
reply = rs->buf;

- while (strncmp (reply, "qSymbol:", 8) == 0)
+ while (startswith (reply, "qSymbol:"))
{
struct bound_minimal_symbol sym;

@@ -3825,7 +3825,7 @@ remote_serial_open (const char *name)
of in ser-tcp.c, because it is the remote protocol assuming that the
serial connection is reliable and not the serial connection promising
to be. */
- if (!udp_warning && strncmp (name, "udp:", 4) == 0)
+ if (!udp_warning && startswith (name, "udp:"))
{
warning (_("The remote protocol may be unreliable over UDP.\n"
"Some events may be lost, rendering further debugging "
@@ -4609,7 +4609,7 @@ remote_vcont_probe (struct remote_state *rs)
buf = rs->buf;

/* Make sure that the features we assume are supported. */
- if (strncmp (buf, "vCont", 5) == 0)
+ if (startswith (buf, "vCont"))
{
char *p = &buf[5];
int support_s, support_S, support_c, support_C;
diff --git a/gdb/reverse.c b/gdb/reverse.c
index e0946c8..ed55a3a 100644
--- a/gdb/reverse.c
+++ b/gdb/reverse.c
@@ -255,9 +255,9 @@ goto_bookmark_command (char *args, int from_tty)
if (args == NULL || args[0] == '\0')
error (_("Command requires an argument."));

- if (strncmp (args, "start", strlen ("start")) == 0
- || strncmp (args, "begin", strlen ("begin")) == 0
- || strncmp (args, "end", strlen ("end")) == 0)
+ if (startswith (args, "start")
+ || startswith (args, "begin")
+ || startswith (args, "end"))
{
/* Special case. Give target opportunity to handle. */
target_goto_bookmark ((gdb_byte *) args, from_tty);
diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c
index 3467b1f..9c3dcf4 100644
--- a/gdb/ser-tcp.c
+++ b/gdb/ser-tcp.c
@@ -168,12 +168,12 @@ net_open (struct serial *scb, const char *name)
unsigned int polls = 0;

use_udp = 0;
- if (strncmp (name, "udp:", 4) == 0)
+ if (startswith (name, "udp:"))
{
use_udp = 1;
name = name + 4;
}
- else if (strncmp (name, "tcp:", 4) == 0)
+ else if (startswith (name, "tcp:"))
name = name + 4;

port_str = strchr (name, ':');
diff --git a/gdb/serial.c b/gdb/serial.c
index 59bf7af..b7e620d 100644
--- a/gdb/serial.c
+++ b/gdb/serial.c
@@ -190,9 +190,9 @@ serial_open (const char *name)

if (strcmp (name, "pc") == 0)
ops = serial_interface_lookup ("pc");
- else if (strncmp (name, "lpt", 3) == 0)
+ else if (startswith (name, "lpt"))
ops = serial_interface_lookup ("parallel");
- else if (strncmp (name, "|", 1) == 0)
+ else if (startswith (name, "|"))
{
ops = serial_interface_lookup ("pipe");
/* Discard ``|'' and any space before the command itself. */
diff --git a/gdb/somread.c b/gdb/somread.c
index 2bee2b1..49cfe76 100644
--- a/gdb/somread.c
+++ b/gdb/somread.c
@@ -212,8 +212,8 @@ som_symtab_read (bfd *abfd, struct objfile *objfile,
if ((symname[0] == 'L' && symname[1] == '$')
|| (symname[0] == '$' && symname[strlen (symname) - 1] == '$')
|| (symname[0] == 'D' && symname[1] == '$')
- || (strncmp (symname, "L0\001", 3) == 0)
- || (strncmp (symname, "$PIC", 4) == 0))
+ || (startswith (symname, "L0\001"))
+ || (startswith (symname, "$PIC")))
continue;
break;

diff --git a/gdb/symtab.c b/gdb/symtab.c
index 12168cb..60e21fb 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -535,7 +535,7 @@ gdb_mangle_name (struct type *type, int method_id, int signature_id)
|| (newname && strcmp (field_name, newname) == 0);

if (!is_destructor)
- is_destructor = (strncmp (physname, "__dt", 4) == 0);
+ is_destructor = (startswith (physname, "__dt"));

if (is_destructor || is_full_physname_constructor)
{
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index 44c6189..692de29 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -510,22 +510,22 @@ tfile_interp_line (char *line, struct uploaded_tp **utpp,
{
char *p = line;

- if (strncmp (p, "R ", strlen ("R ")) == 0)
+ if (startswith (p, "R "))
{
p += strlen ("R ");
trace_regblock_size = strtol (p, &p, 16);
}
- else if (strncmp (p, "status ", strlen ("status ")) == 0)
+ else if (startswith (p, "status "))
{
p += strlen ("status ");
parse_trace_status (p, current_trace_status ());
}
- else if (strncmp (p, "tp ", strlen ("tp ")) == 0)
+ else if (startswith (p, "tp "))
{
p += strlen ("tp ");
parse_tracepoint_definition (p, utpp);
}
- else if (strncmp (p, "tsv ", strlen ("tsv ")) == 0)
+ else if (startswith (p, "tsv "))
{
p += strlen ("tsv ");
parse_tsv_definition (p, utsvp);
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 0774f5e..7c04ecb 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -3830,11 +3830,11 @@ parse_tracepoint_definition (char *line, struct uploaded_tp **utpp)
end = hex2bin (p, (gdb_byte *) buf, strlen (p) / 2);
buf[end] = '\0';

- if (strncmp (srctype, "at:", strlen ("at:")) == 0)
+ if (startswith (srctype, "at:"))
utp->at_string = xstrdup (buf);
- else if (strncmp (srctype, "cond:", strlen ("cond:")) == 0)
+ else if (startswith (srctype, "cond:"))
utp->cond_string = xstrdup (buf);
- else if (strncmp (srctype, "cmd:", strlen ("cmd:")) == 0)
+ else if (startswith (srctype, "cmd:"))
VEC_safe_push (char_ptr, utp->cmd_strings, xstrdup (buf));
}
else if (piece == 'V')
diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c
index 3eff9fd..43bcec2 100644
--- a/gdb/tui/tui-data.c
+++ b/gdb/tui/tui-data.c
@@ -391,7 +391,7 @@ tui_partial_win_by_name (char *name)
char *cur_name = tui_win_name (&tui_win_list[i]->generic);

if (strlen (name) <= strlen (cur_name)
- && strncmp (name, cur_name, strlen (name)) == 0)
+ && startswith (cur_name, name))
win_info = tui_win_list[i];
}
i++;
diff --git a/gdb/utils.c b/gdb/utils.c
index 4f9f4f0..7172bba 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -2663,8 +2663,7 @@ subset_compare (char *string_to_compare, char *template_string)
if (template_string != (char *) NULL && string_to_compare != (char *) NULL
&& strlen (string_to_compare) <= strlen (template_string))
match =
- (strncmp
- (template_string, string_to_compare, strlen (string_to_compare)) == 0);
+ (startswith (template_string, string_to_compare));
else
match = 0;
return match;
@@ -3278,7 +3277,7 @@ producer_is_gcc (const char *producer, int *major, int *minor)
{
const char *cs;

- if (producer != NULL && strncmp (producer, "GNU ", strlen ("GNU ")) == 0)
+ if (producer != NULL && startswith (producer, "GNU "))
{
int maj, min;

diff --git a/gdb/valops.c b/gdb/valops.c
index 23a4b37..b096a51 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1992,9 +1992,9 @@ search_struct_method (const char *name, struct value **arg1p,
const char *t_field_name = TYPE_FN_FIELDLIST_NAME (type, i);

/* FIXME! May need to check for ARM demangling here. */
- if (strncmp (t_field_name, "__", 2) == 0 ||
- strncmp (t_field_name, "op", 2) == 0 ||
- strncmp (t_field_name, "type", 4) == 0)
+ if (startswith (t_field_name, "__") ||
+ startswith (t_field_name, "op") ||
+ startswith (t_field_name, "type"))
{
if (cplus_demangle_opname (t_field_name, dem_opname, DMGL_ANSI))
t_field_name = dem_opname;
@@ -3386,9 +3386,9 @@ value_struct_elt_for_reference (struct type *domain, int offset,
const char *t_field_name = TYPE_FN_FIELDLIST_NAME (t, i);
char dem_opname[64];

- if (strncmp (t_field_name, "__", 2) == 0
- || strncmp (t_field_name, "op", 2) == 0
- || strncmp (t_field_name, "type", 4) == 0)
+ if (startswith (t_field_name, "__")
+ || startswith (t_field_name, "op")
+ || startswith (t_field_name, "type"))
{
if (cplus_demangle_opname (t_field_name,
dem_opname, DMGL_ANSI))
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 107bdf2..d3e2bd3 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -817,7 +817,7 @@ handle_output_debug_string (struct target_waitstatus *ourstatus)
sizeof (_CYGWIN_SIGNAL_STRING) - 1) != 0)
{
#ifdef __CYGWIN__
- if (strncmp (s, "cYg", 3) != 0)
+ if (!startswith (s, "cYg"))
#endif
warning (("%s"), s);
}
@@ -1014,8 +1014,7 @@ handle_exception (struct target_waitstatus *ourstatus)
if ((!cygwin_exceptions && (addr >= cygwin_load_start
&& addr < cygwin_load_end))
|| (find_pc_partial_function (addr, &fn, NULL, NULL)
- && strncmp (fn, "KERNEL32!IsBad",
- strlen ("KERNEL32!IsBad")) == 0))
+ && startswith (fn, "KERNEL32!IsBad")))
return 0;
}
#endif
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index e83bd13..3cb6eda 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -2839,7 +2839,7 @@ scan_xcoff_symtab (struct objfile *objfile)
loader-generated definitions. Keeping the global
symbols leads to "in psymbols but not in symbols"
errors. */
- if (strncmp (namestring, "@FIX", 4) == 0)
+ if (startswith (namestring, "@FIX"))
continue;

symbol.n_value += ANOFFSET (objfile->section_offsets,
--
1.7.1