]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
New common function "startswith"
authorGary Benson <gbenson@redhat.com>
Fri, 6 Mar 2015 09:42:06 +0000 (09:42 +0000)
committerGary Benson <gbenson@redhat.com>
Fri, 6 Mar 2015 09:42:06 +0000 (09:42 +0000)
This commit introduces a new inline common function "startswith"
which takes two string arguments and returns nonzero if the first
string starts with the second.  It also updates the 295 places
where this logic was written out longhand to use the new function.

gdb/ChangeLog:

* common/common-utils.h (startswith): New inline function.
All places where this logic was used updated to use the above.

77 files changed:
gdb/ChangeLog
gdb/ada-lang.c
gdb/amd64-tdep.c
gdb/amd64-windows-tdep.c
gdb/amd64obsd-tdep.c
gdb/arch-utils.c
gdb/arm-tdep.c
gdb/arm-wince-tdep.c
gdb/breakpoint.c
gdb/bsd-uthread.c
gdb/c-typeprint.c
gdb/cli/cli-dump.c
gdb/cli/cli-script.c
gdb/coffread.c
gdb/common/common-utils.h
gdb/compile/compile.c
gdb/corelow.c
gdb/cp-namespace.c
gdb/dbxread.c
gdb/dictionary.c
gdb/dwarf2-frame.c
gdb/dwarf2read.c
gdb/elfread.c
gdb/gcore.c
gdb/gdbserver/hostio.c
gdb/gdbserver/linux-low.c
gdb/gdbserver/linux-x86-low.c
gdb/gdbserver/notif.c
gdb/gdbserver/remote-utils.c
gdb/gdbserver/server.c
gdb/gdbserver/tracepoint.c
gdb/gdbserver/win32-low.c
gdb/gdbtypes.c
gdb/gnu-v2-abi.c
gdb/gnu-v3-abi.c
gdb/go-lang.c
gdb/guile/scm-type.c
gdb/i386-cygwin-tdep.c
gdb/i386-tdep.c
gdb/i386obsd-tdep.c
gdb/infcmd.c
gdb/jv-typeprint.c
gdb/linespec.c
gdb/linux-nat.c
gdb/m2-typeprint.c
gdb/m32r-rom.c
gdb/machoread.c
gdb/macrocmd.c
gdb/microblaze-rom.c
gdb/minsyms.c
gdb/mips-sde-tdep.c
gdb/mips-tdep.c
gdb/msp430-tdep.c
gdb/nat/linux-procfs.c
gdb/nbsd-tdep.c
gdb/p-typeprint.c
gdb/ppc-linux-tdep.c
gdb/python/py-type.c
gdb/regcache.c
gdb/remote-m32r-sdi.c
gdb/remote-notif.c
gdb/remote.c
gdb/reverse.c
gdb/rs6000-tdep.c
gdb/ser-tcp.c
gdb/serial.c
gdb/somread.c
gdb/sparc64nbsd-tdep.c
gdb/sparcnbsd-tdep.c
gdb/symtab.c
gdb/tracefile-tfile.c
gdb/tracepoint.c
gdb/tui/tui-data.c
gdb/utils.c
gdb/valops.c
gdb/windows-nat.c
gdb/xcoffread.c

index bfb584c50d514e4ca8808463d169aa5052cd1548..c7735f1b8b9d78a0fbd46b57db519ca620ef4c84 100644 (file)
@@ -1,3 +1,8 @@
+2015-03-06  Gary Benson <gbenson@redhat.com>
+
+       * common/common-utils.h (startswith): New inline function.
+       All places where this logic was used updated to use the above.
+
 2015-03-05  Pedro Alves  <palves@redhat.com>
 
        PR gdb/18002
index b01672358b1698d81ad3337ff5f064307b59e3e0..1e70d126614bc263149adb3b5de156eea9105432 100644 (file)
@@ -596,7 +596,7 @@ field_name_match (const char *field_name, const char *target)
   return
     (strncmp (field_name, target, len) == 0
      && (field_name[len] == '\0'
-         || (strncmp (field_name + len, "___", 3) == 0
+         || (startswith (field_name + len, "___")
              && strcmp (field_name + strlen (field_name) - 6,
                         "___XVN") != 0)));
 }
@@ -1003,8 +1003,7 @@ ada_encode (const char *decoded)
 
           for (mapping = ada_opname_table;
                mapping->encoded != NULL
-               && strncmp (mapping->decoded, p,
-                           strlen (mapping->decoded)) != 0; mapping += 1)
+               && !startswith (p, mapping->decoded); mapping += 1)
             ;
           if (mapping->encoded == NULL)
             error (_("invalid Ada operator name: %s"), p);
@@ -1085,9 +1084,9 @@ ada_remove_trailing_digits (const char *encoded, int *len)
         *len = i;
       else if (i >= 0 && encoded[i] == '$')
         *len = i;
-      else if (i >= 2 && strncmp (encoded + i - 2, "___", 3) == 0)
+      else if (i >= 2 && startswith (encoded + i - 2, "___"))
         *len = i - 2;
-      else if (i >= 1 && strncmp (encoded + i - 1, "__", 2) == 0)
+      else if (i >= 1 && startswith (encoded + i - 1, "__"))
         *len = i - 1;
     }
 }
@@ -1156,7 +1155,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
@@ -1187,20 +1186,20 @@ ada_decode (const char *encoded)
      is for the body of a task, but that information does not actually
      appear in the decoded name.  */
 
-  if (len0 > 3 && strncmp (encoded + len0 - 3, "TKB", 3) == 0)
+  if (len0 > 3 && startswith (encoded + len0 - 3, "TKB"))
     len0 -= 3;
 
   /* Remove any trailing TB suffix.  The TB suffix is slightly different
      from the TKB suffix because it is used for non-anonymous task
      bodies.  */
 
-  if (len0 > 2 && strncmp (encoded + len0 - 2, "TB", 2) == 0)
+  if (len0 > 2 && startswith (encoded + len0 - 2, "TB"))
     len0 -= 2;
 
   /* Remove trailing "B" suffixes.  */
   /* FIXME: brobecker/2006-04-19: Not sure what this are used for...  */
 
-  if (len0 > 1 && strncmp (encoded + len0 - 1, "B", 1) == 0)
+  if (len0 > 1 && startswith (encoded + len0 - 1, "B"))
     len0 -= 1;
 
   /* Make decoded big enough for possible expansion by operator name.  */
@@ -1258,7 +1257,7 @@ ada_decode (const char *encoded)
       /* Replace "TK__" with "__", which will eventually be translated
          into "." (just below).  */
 
-      if (i < len0 - 4 && strncmp (encoded + i, "TK__", 4) == 0)
+      if (i < len0 - 4 && startswith (encoded + i, "TK__"))
         i += 2;
 
       /* Replace "__B_{DIGITS}+__" sequences by "__", which will eventually
@@ -1467,7 +1466,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));
     }
@@ -4604,7 +4603,7 @@ lesseq_defined_than (struct symbol *sym0, struct symbol *sym1)
           TYPE_CODE (type0) == TYPE_CODE (type1)
           && (equiv_types (type0, type1)
               || (len0 < strlen (name1) && strncmp (name0, name1, len0) == 0
-                  && strncmp (name1 + len0, "___XV", 5) == 0));
+                  && startswith (name1 + len0, "___XV")));
       }
     case LOC_CONST:
       return SYMBOL_VALUE (sym0) == SYMBOL_VALUE (sym1)
@@ -4700,7 +4699,7 @@ ada_lookup_simple_minsym (const char *name)
      using, for instance, Standard.Constraint_Error when Constraint_Error
      is ambiguous (due to the user defining its own Constraint_Error
      entity inside its program).  */
-  if (strncmp (name, "standard__", sizeof ("standard__") - 1) == 0)
+  if (startswith (name, "standard__"))
     name += sizeof ("standard__") - 1;
 
   ALL_MSYMBOLS (objfile, msymbol)
@@ -5028,11 +5027,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;
@@ -5430,7 +5429,7 @@ ada_lookup_symbol_list_worker (const char *name0, const struct block *block0,
      using, for instance, Standard.Constraint_Error when Constraint_Error
      is ambiguous (due to the user defining its own Constraint_Error
      entity inside its program).  */
-  if (strncmp (name0, "standard__", sizeof ("standard__") - 1) == 0)
+  if (startswith (name0, "standard__"))
     {
       block = NULL;
       name = name0 + sizeof ("standard__") - 1;
@@ -5830,7 +5829,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;
@@ -5984,7 +5983,7 @@ ada_add_block_symbols (struct obstack *obstackp,
             cmp = (int) '_' - (int) SYMBOL_LINKAGE_NAME (sym)[0];
             if (cmp == 0)
               {
-                cmp = strncmp ("_ada_", SYMBOL_LINKAGE_NAME (sym), 5);
+                cmp = !startswith (SYMBOL_LINKAGE_NAME (sym), "_ada_");
                 if (cmp == 0)
                   cmp = strncmp (name, SYMBOL_LINKAGE_NAME (sym) + 5,
                                  name_len);
@@ -6371,7 +6370,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 +6697,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 +6713,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 +6786,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)
@@ -6799,7 +6798,7 @@ ada_variant_discrim_name (struct type *type0)
       if (discrim_start == name + 1)
         return "";
       if ((discrim_start > name + 3
-           && strncmp (discrim_start - 3, "___", 3) == 0)
+           && startswith (discrim_start - 3, "___"))
           || discrim_start[-1] == '.')
         break;
     }
@@ -7551,7 +7550,7 @@ field_alignment (struct type *type, int f)
   else
     align_offset = len - 1;
 
-  if (align_offset < 7 || strncmp ("___XV", name + align_offset - 6, 5) != 0)
+  if (align_offset < 7 || !startswith (name + align_offset - 6, "___XV"))
     return TARGET_CHAR_BIT;
 
   return atoi (name + align_offset) * TARGET_CHAR_BIT;
@@ -12475,7 +12474,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 +12735,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;
index e9de0f66ed51b1f410efb189343ec727dbf0b3e0..c76810342f20dc1a8920b881293cb1cc40a64732 100644 (file)
@@ -2378,8 +2378,7 @@ amd64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
       if (post_prologue_pc
          && (cust != NULL
              && COMPUNIT_PRODUCER (cust) != NULL
-             && strncmp (COMPUNIT_PRODUCER (cust), "clang ",
-                         sizeof ("clang ") - 1) == 0))
+             && startswith (COMPUNIT_PRODUCER (cust), "clang ")))
         return max (start_pc, post_prologue_pc);
     }
 
index 2aa10a100dbc8c39a1b6c5f7436da1e5e1b674ea..de5d8c7ccf7c059b7d23a77740a03b53bd528caf 100644 (file)
@@ -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);
        }
index 04cd31ff003f6e391ebb538177f6b74105646d27..d6c7e90a016a2158f1f22cbcb4e0021bda9c0af0 100644 (file)
@@ -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 = {
index 32d48a744fae2ba43f74c27f04cd43018313ae7a..e1c8ab0163f27a4a01442faba31f52c2fccaecba 100644 (file)
@@ -661,7 +661,7 @@ initialize_current_architecture (void)
       chp = strchr (target_name, '-');
       if (chp != NULL
          && chp - 2 >= target_name
-         && strncmp (chp - 2, "el", 2) == 0)
+         && startswith (chp - 2, "el"))
        default_byte_order = BFD_ENDIAN_LITTLE;
     }
   if (default_byte_order == BFD_ENDIAN_UNKNOWN)
index d7cd6e5af8fe21bd030e9c782785988ec91a3825..630a2077d9cb4bfdc101061f36de3b51afd7ca13 100644 (file)
@@ -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
@@ -1314,9 +1314,7 @@ arm_skip_stack_protector(CORE_ADDR pc, struct gdbarch *gdbarch)
   /* ADDR must correspond to a symbol whose name is __stack_chk_guard.
      Otherwise, this sequence cannot be for stack protector.  */
   if (stack_chk_guard.minsym == NULL
-      || strncmp (MSYMBOL_LINKAGE_NAME (stack_chk_guard.minsym),
-                 "__stack_chk_guard",
-                 strlen ("__stack_chk_guard")) != 0)
+      || !startswith (MSYMBOL_LINKAGE_NAME (stack_chk_guard.minsym), "__stack_chk_guard"))
    return pc;
 
   if (is_thumb)
@@ -1413,10 +1411,8 @@ arm_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
       if (post_prologue_pc
          && (cust == NULL
              || COMPUNIT_PRODUCER (cust) == NULL
-             || strncmp (COMPUNIT_PRODUCER (cust), "GNU ",
-                         sizeof ("GNU ") - 1) == 0
-             || strncmp (COMPUNIT_PRODUCER (cust), "clang ",
-                         sizeof ("clang ") - 1) == 0))
+             || startswith (COMPUNIT_PRODUCER (cust), "GNU ")
+             || startswith (COMPUNIT_PRODUCER (cust), "clang ")))
        return post_prologue_pc;
 
       if (post_prologue_pc != 0)
@@ -9315,8 +9311,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.  */
@@ -9338,11 +9334,9 @@ arm_skip_stub (struct frame_info *frame, CORE_ADDR pc)
   namelen = strlen (name);
   if (name[0] == '_' && name[1] == '_'
       && ((namelen > 2 + strlen ("_from_thumb")
-          && strncmp (name + namelen - strlen ("_from_thumb"), "_from_thumb",
-                      strlen ("_from_thumb")) == 0)
+          && startswith (name + namelen - strlen ("_from_thumb"), "_from_thumb"))
          || (namelen > 2 + strlen ("_from_arm")
-             && strncmp (name + namelen - strlen ("_from_arm"), "_from_arm",
-                         strlen ("_from_arm")) == 0)))
+             && startswith (name + namelen - strlen ("_from_arm"), "_from_arm"))))
     {
       char *target_name;
       int target_len = namelen - 2;
index 206ff4f72bf762860f814fce13cc87855577193b..72295ba4caee51ca1cc6bef0768b51d185ded636 100644 (file)
@@ -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);
index c5d324097016e10375764f6ad8ded5d05a96ffb4..d85f271e0486423889d28d1c7f7615d2feaf6672 100644 (file)
@@ -9729,7 +9729,7 @@ parse_breakpoint_sals (char **address,
   /* If no arg given, or if first arg is 'if ', use the default
      breakpoint.  */
   if ((*address) == NULL
-      || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
+      || (startswith ((*address), "if") && isspace ((*address)[2])))
     {
       /* The last displayed codepoint, if it's valid, is our default breakpoint
          address.  */
@@ -11401,7 +11401,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
          tok++;
          toklen = end_tok - tok + 1;
 
-         if (toklen == 6 && !strncmp (tok, "thread", 6))
+         if (toklen == 6 && startswith (tok, "thread"))
            {
              /* At this point we've found a "thread" token, which means
                 the user is trying to set a watchpoint that triggers
@@ -11423,7 +11423,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
              if (!valid_thread_id (thread))
                invalid_thread_id_error (thread);
            }
-         else if (toklen == 4 && !strncmp (tok, "mask", 4))
+         else if (toklen == 4 && startswith (tok, "mask"))
            {
              /* We've found a "mask" token, which means the user wants to
                 create a hardware watchpoint that is going to have the mask
@@ -15493,7 +15493,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;
index 0a838ef8a3bd7874e2051392fc339fd1a02dc4df..a5abb63d9eaa266d1cc783df9e93149076aea258 100644 (file)
@@ -247,7 +247,7 @@ bsd_uthread_solib_loaded (struct so_list *so)
 
   for (names = bsd_uthread_solib_names; *names; names++)
     {
-      if (strncmp (so->so_original_name, *names, strlen (*names)) == 0)
+      if (startswith (so->so_original_name, *names))
        {
          solib_read_symbols (so, 0);
 
index 64279c86eb6c9d43b20beae69d2ccf291f6debc5..421b72014865e17521b142f907aeb12a88546a79 100644 (file)
@@ -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
@@ -933,7 +933,7 @@ c_type_print_base (struct type *type, struct ui_file *stream,
           enum}" tag for unnamed struct/union/enum's, which we don't
           want to print.  */
        if (TYPE_TAG_NAME (type) != NULL
-           && strncmp (TYPE_TAG_NAME (type), "{unnamed", 8))
+           && !startswith (TYPE_TAG_NAME (type), "{unnamed"))
          {
            /* When printing the tag name, we are still effectively
               printing in the outer context, hence the use of FLAGS
@@ -1345,7 +1345,7 @@ c_type_print_base (struct type *type, struct ui_file *stream,
          tag for unnamed struct/union/enum's, which we don't
          want to print.  */
       if (TYPE_TAG_NAME (type) != NULL
-         && strncmp (TYPE_TAG_NAME (type), "{unnamed", 8))
+         && !startswith (TYPE_TAG_NAME (type), "{unnamed"))
        {
          print_name_maybe_canonical (TYPE_TAG_NAME (type), flags, stream);
          if (show > 0)
index 481c3a28bc6a287f731be3308f5661d2c0eb83c2..0f9485f85e421b26bbd702a22b7dc5c60aef7f69 100644 (file)
@@ -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);
index 65232dacbfa86a25a8be6696be58876a608ed9b8..010d661af4d5e5d235b77e8961583464a9c99315 100644 (file)
@@ -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++;
@@ -988,7 +988,7 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
 
   /* 'end' is always recognized, regardless of parse_commands value.
      We also permit whitespace before end and after.  */
-  if (p_end - p_start == 3 && !strncmp (p_start, "end", 3))
+  if (p_end - p_start == 3 && startswith (p_start, "end"))
     return end_command;
   
   if (parse_commands)
@@ -1005,14 +1005,14 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
        return nop_command;
 
       /* Is the else clause of an if control structure?  */
-      if (p_end - p == 4 && !strncmp (p, "else", 4))
+      if (p_end - p == 4 && startswith (p, "else"))
        return else_command;
 
       /* Check for while, if, break, continue, etc and build a new
         command line structure for them.  */
-      if ((p_end - p >= 14 && !strncmp (p, "while-stepping", 14))
-         || (p_end - p >= 8 && !strncmp (p, "stepping", 8))
-         || (p_end - p >= 2 && !strncmp (p, "ws", 2)))
+      if ((p_end - p >= 14 && startswith (p, "while-stepping"))
+         || (p_end - p >= 8 && startswith (p, "stepping"))
+         || (p_end - p >= 2 && startswith (p, "ws")))
        {
          /* Because validate_actionline and encode_action lookup
             command's line as command, we need the line to
@@ -1027,7 +1027,7 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
             not.  */
          *command = build_command_line (while_stepping_control, p);
        }
-      else if (p_end - p > 5 && !strncmp (p, "while", 5))
+      else if (p_end - p > 5 && startswith (p, "while"))
        {
          char *first_arg;
 
@@ -1036,7 +1036,7 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
            first_arg++;
          *command = build_command_line (while_control, first_arg);
        }
-      else if (p_end - p > 2 && !strncmp (p, "if", 2))
+      else if (p_end - p > 2 && startswith (p, "if"))
        {
          char *first_arg;
 
@@ -1045,7 +1045,7 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
            first_arg++;
          *command = build_command_line (if_control, first_arg);
        }
-      else if (p_end - p >= 8 && !strncmp (p, "commands", 8))
+      else if (p_end - p >= 8 && startswith (p, "commands"))
        {
          char *first_arg;
 
@@ -1054,13 +1054,13 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
            first_arg++;
          *command = build_command_line (commands_control, first_arg);
        }
-      else if (p_end - p == 6 && !strncmp (p, "python", 6))
+      else if (p_end - p == 6 && startswith (p, "python"))
        {
          /* Note that we ignore the inline "python command" form
             here.  */
          *command = build_command_line (python_control, "");
        }
-      else if (p_end - p == 6 && !strncmp (p, "compile", 7))
+      else if (p_end - p == 6 && startswith (p, "compile"))
        {
          /* Note that we ignore the inline "compile command" form
             here.  */
@@ -1068,12 +1068,12 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
          (*command)->control_u.compile.scope = COMPILE_I_INVALID_SCOPE;
        }
 
-      else if (p_end - p == 5 && !strncmp (p, "guile", 5))
+      else if (p_end - p == 5 && startswith (p, "guile"))
        {
          /* Note that we ignore the inline "guile command" form here.  */
          *command = build_command_line (guile_control, "");
        }
-      else if (p_end - p == 10 && !strncmp (p, "loop_break", 10))
+      else if (p_end - p == 10 && startswith (p, "loop_break"))
        {
          *command = (struct command_line *)
            xmalloc (sizeof (struct command_line));
@@ -1083,7 +1083,7 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
          (*command)->body_count = 0;
          (*command)->body_list = NULL;
        }
-      else if (p_end - p == 13 && !strncmp (p, "loop_continue", 13))
+      else if (p_end - p == 13 && startswith (p, "loop_continue"))
        {
          *command = (struct command_line *)
            xmalloc (sizeof (struct command_line));
index 366d82823adb38e55cc11e6d307c810d2eff607f..28f7b18120f483d2018a1480ef8675570f8c36cd 100644 (file)
@@ -231,7 +231,7 @@ coff_locate_sections (bfd *abfd, asection *sectp, void *csip)
       csi->textaddr = bfd_section_vma (abfd, sectp);
       csi->textsize += bfd_section_size (abfd, sectp);
     }
-  else if (strncmp (name, ".text", sizeof ".text" - 1) == 0)
+  else if (startswith (name, ".text"))
     {
       csi->textsize += bfd_section_size (abfd, sectp);
     }
@@ -239,7 +239,7 @@ coff_locate_sections (bfd *abfd, asection *sectp, void *csip)
     {
       csi->stabstrsect = sectp;
     }
-  else if (strncmp (name, ".stab", sizeof ".stab" - 1) == 0)
+  else if (startswith (name, ".stab"))
     {
       const char *s;
 
@@ -448,7 +448,7 @@ is_import_fixup_symbol (struct coff_symbol *cs,
     return 0;
 
   /* The name must start with "__fu<digits>__".  */
-  if (strncmp (cs->c_name, "__fu", 4) != 0)
+  if (!startswith (cs->c_name, "__fu"))
     return 0;
   if (! isdigit (cs->c_name[4]))
     return 0;
@@ -605,8 +605,8 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags)
      FIXME: We should use BFD to read the symbol table, and thus avoid
      this problem.  */
   pe_file =
-    strncmp (bfd_get_target (objfile->obfd), "pe", 2) == 0
-    || strncmp (bfd_get_target (objfile->obfd), "epoc-pe", 7) == 0;
+    startswith (bfd_get_target (objfile->obfd), "pe")
+    || startswith (bfd_get_target (objfile->obfd), "epoc-pe");
 
   /* End of warning.  */
 
@@ -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;
@@ -946,14 +946,14 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
            }
          else if (!SDB_TYPE (cs->c_type)
                   && cs->c_name[0] == 'L'
-                  && (strncmp (cs->c_name, "LI%", 3) == 0
-                      || strncmp (cs->c_name, "LF%", 3) == 0
-                      || strncmp (cs->c_name, "LC%", 3) == 0
-                      || strncmp (cs->c_name, "LP%", 3) == 0
-                      || strncmp (cs->c_name, "LPB%", 4) == 0
-                      || strncmp (cs->c_name, "LBB%", 4) == 0
-                      || strncmp (cs->c_name, "LBE%", 4) == 0
-                      || strncmp (cs->c_name, "LPBX%", 5) == 0))
+                  && (startswith (cs->c_name, "LI%")
+                      || startswith (cs->c_name, "LF%")
+                      || startswith (cs->c_name, "LC%")
+                      || startswith (cs->c_name, "LP%")
+                      || startswith (cs->c_name, "LPB%")
+                      || startswith (cs->c_name, "LBB%")
+                      || startswith (cs->c_name, "LBE%")
+                      || startswith (cs->c_name, "LPBX%")))
            /* At least on a 3b1, gcc generates swbeg and string labels
               that look like this.  Ignore them.  */
            break;
index 60aa030a0f7cfa7d9e5bb8f554fefb24769cf28d..cd2665aec5085696920b4b83ffca4428feb5a968 100644 (file)
@@ -68,4 +68,13 @@ char *savestring (const char *ptr, size_t len);
 
 extern char *safe_strerror (int);
 
+/* Return non-zero if the start of STRING matches PATTERN, zero
+   otherwise.  */
+
+static inline int
+startswith (const char *string, const char *pattern)
+{
+  return strncmp (string, pattern, strlen (pattern)) == 0;
+}
+
 #endif
index c204a135ef2a8f865b8028e8d6fa2511d1d4f217..1d342a0d82c75bd9e2a4b0f2aa15aacf6bd1a06b 100644 (file)
@@ -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)
@@ -313,7 +313,7 @@ get_selected_pc_producer_options (void)
   const char *cs;
 
   if (symtab == NULL || symtab->producer == NULL
-      || strncmp (symtab->producer, "GNU ", strlen ("GNU ")) != 0)
+      || !startswith (symtab->producer, "GNU "))
     return NULL;
 
   cs = symtab->producer;
index c7d4318e0014b61354752381758e6e5a4dcfb760..65e13268cbb37f29ed9d80ed287f7283d0aa31dc 100644 (file)
@@ -234,7 +234,7 @@ add_to_thread_list (bfd *abfd, asection *asect, void *reg_sect_arg)
   int fake_pid_p = 0;
   struct inferior *inf;
 
-  if (strncmp (bfd_section_name (abfd, asect), ".reg/", 5) != 0)
+  if (!startswith (bfd_section_name (abfd, asect), ".reg/"))
     return;
 
   core_tid = atoi (bfd_section_name (abfd, asect) + 5);
index 4f684321929e00b648bd4f62f088cd67693d6c85..4a00cb62e6679e3125adb669dfc091da3fa9fc65 100644 (file)
@@ -497,8 +497,7 @@ cp_lookup_symbol_via_imports (const char *scope,
 
       len = strlen (current->import_dest);
       directive_match = (search_parents
-                         ? (strncmp (scope, current->import_dest,
-                                     strlen (current->import_dest)) == 0
+                         ? (startswith (scope, current->import_dest)
                             && (len == 0
                                 || scope[len] == ':'
                                || scope[len] == '\0'))
index 4f60e10bceb559c7640123b72f4d24bee2a6b3fb..c8f974ff04c2dd27ebe5b43922dfa2512791d170 100644 (file)
@@ -539,12 +539,12 @@ dbx_symfile_read (struct objfile *objfile, int symfile_flags)
      differently from Solaris), and false for SunOS4 and other a.out
      file formats.  */
   block_address_function_relative =
-    ((0 == strncmp (bfd_get_target (sym_bfd), "elf", 3))
-     || (0 == strncmp (bfd_get_target (sym_bfd), "som", 3))
-     || (0 == strncmp (bfd_get_target (sym_bfd), "coff", 4))
-     || (0 == strncmp (bfd_get_target (sym_bfd), "pe", 2))
-     || (0 == strncmp (bfd_get_target (sym_bfd), "epoc-pe", 7))
-     || (0 == strncmp (bfd_get_target (sym_bfd), "nlm", 3)));
+    ((startswith (bfd_get_target (sym_bfd), "elf"))
+     || (startswith (bfd_get_target (sym_bfd), "som"))
+     || (startswith (bfd_get_target (sym_bfd), "coff"))
+     || (startswith (bfd_get_target (sym_bfd), "pe"))
+     || (startswith (bfd_get_target (sym_bfd), "epoc-pe"))
+     || (startswith (bfd_get_target (sym_bfd), "nlm")));
 
   val = bfd_seek (sym_bfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET);
   if (val < 0)
@@ -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;
        }
     }
index 2c81182cb5cffbf44d27a52ec3c373b6cb24b9ee..a16955a071a8d6e2ac5505f06380e395dc4e4828 100644 (file)
@@ -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);
index 71e3f6b7e6deb56c4b7820a4424d1a926f496b7a..b648aa350ec611a098f3162f5fd3bc2620c4a9cd 100644 (file)
@@ -878,7 +878,7 @@ dwarf2_frame_find_quirks (struct dwarf2_frame_state *fs,
         this problem is fixed (no quirk needed).  If the armcc
         augmentation is missing, the quirk is needed.  */
       if (fde->cie->version == 3
-         && (strncmp (fde->cie->augmentation, "armcc", 5) != 0
+         && (!startswith (fde->cie->augmentation, "armcc")
              || strchr (fde->cie->augmentation + 5, '+') == NULL))
        fs->armcc_cfa_offsets_reversed = 1;
 
@@ -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
index 071f97bea614fc1558671d79b0053187b6770527..a283cba63779007ddded9d71e5605858406f9835 100644 (file)
@@ -12306,7 +12306,7 @@ check_producer (struct dwarf2_cu *cu)
       cu->producer_is_gxx_lt_4_6 = major < 4 || (major == 4 && minor < 6);
       cu->producer_is_gcc_lt_4_3 = major < 4 || (major == 4 && minor < 3);
     }
-  else if (strncmp (cu->producer, "Intel(R) C", strlen ("Intel(R) C")) == 0)
+  else if (startswith (cu->producer, "Intel(R) C"))
     cu->producer_is_icc = 1;
   else
     {
@@ -12987,8 +12987,8 @@ is_vtable_name (const char *name, struct dwarf2_cu *cu)
 
   /* Look for the C++ and Java forms of the vtable.  */
   if ((cu->language == language_java
-       && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
-       || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
+       && startswith (name, vtable))
+       || (startswith (name, vptr)
        && is_cplus_marker (name[sizeof (vptr) - 1])))
     return 1;
 
@@ -13296,8 +13296,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
                }
            }
          else if (cu->producer
-                  && strncmp (cu->producer,
-                              "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
+                  && startswith (cu->producer, "IBM(R) XL C/C++ Advanced Edition"))
            {
              /* The IBM XLC compiler does not provide direct indication
                 of the containing type, but the vtable pointer is
@@ -14695,7 +14694,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
        type_flags |= TYPE_FLAG_UNSIGNED;
        if (cu->language == language_fortran
            && name
-           && strncmp (name, "character(", sizeof ("character(") - 1) == 0)
+           && startswith (name, "character("))
          code = TYPE_CODE_CHAR;
        break;
       case DW_ATE_signed_char:
@@ -18262,7 +18261,7 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
                  if (cu->language == language_fortran && die->parent
                      && die->parent->tag == DW_TAG_module
                      && cu->producer
-                     && strncmp (cu->producer, "GNU Fortran ", 12) == 0)
+                     && startswith (cu->producer, "GNU Fortran "))
                    SYMBOL_ACLASS_INDEX (sym) = LOC_UNRESOLVED;
 
                  /* A variable with DW_AT_external is never static,
@@ -19339,8 +19338,8 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
         or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
         and GCC 4.4.  We work around this problem by ignoring these.  */
       if (attr && DW_STRING (attr)
-         && (strncmp (DW_STRING (attr), "._", 2) == 0
-             || strncmp (DW_STRING (attr), "<anonymous", 10) == 0))
+         && (startswith (DW_STRING (attr), "._")
+             || startswith (DW_STRING (attr), "<anonymous")))
        return NULL;
 
       /* GCC might emit a nameless typedef that has a linkage name.  See
index 4a6576f80261317478077416b675e7988ca94694..4b97b0427aa53145a9921d926037a231347fa609 100644 (file)
@@ -322,7 +322,7 @@ elf_symtab_read (struct objfile *objfile, int type,
             for that section is ".plt".  So, if there is a ".plt"
             section, and yet the section name of our symbol does not
             start with ".plt", we ignore that symbol.  */
-         if (strncmp (sect->name, ".plt", 4) != 0
+         if (!startswith (sect->name, ".plt")
              && bfd_get_section_by_name (abfd, ".plt") != NULL)
            continue;
 
index 1ebff2a42036890196b4d21419530307d65239e7..3e05c612676c74861360bbadf0184af4e81058f4 100644 (file)
@@ -387,9 +387,9 @@ make_output_phdrs (bfd *obfd, asection *osec, void *ignored)
   int p_type = 0;
 
   /* FIXME: these constants may only be applicable for ELF.  */
-  if (strncmp (bfd_section_name (obfd, osec), "load", 4) == 0)
+  if (startswith (bfd_section_name (obfd, osec), "load"))
     p_type = PT_LOAD;
-  else if (strncmp (bfd_section_name (obfd, osec), "note", 4) == 0)
+  else if (startswith (bfd_section_name (obfd, osec), "note"))
     p_type = PT_NOTE;
   else
     p_type = PT_NULL;
@@ -562,7 +562,7 @@ gcore_copy_callback (bfd *obfd, asection *osec, void *ignored)
     return;
 
   /* Only interested in "load" sections.  */
-  if (strncmp ("load", bfd_section_name (obfd, osec), 4) != 0)
+  if (!startswith (bfd_section_name (obfd, osec), "load"))
     return;
 
   size = min (total_size, MAX_COPY_BYTES);
index e6b7754cf170e8dd5123b7145ddce1972020ffcc..ec29eb9d2d4630a5de399d41dace8b82359dfa17 100644 (file)
@@ -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;
index 4da11c6b083c2c3fb1d04ee962761e19904dad1d..48d905b81b655835450f58ee84cef04e33b0da84 100644 (file)
@@ -5903,9 +5903,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
        {
index 3a10e612b204f9628bc08a283cb02245dc1eb219..72478d8647dc97b8342bb8e6fb42a9befcc72c54 100644 (file)
@@ -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;
index ba2af775b74a2dd7ccbf08d2b63fa7f0719f4b51..436c1b8244f87a1f2ffca316e3e21f7ecdbd3153 100644 (file)
@@ -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;
     }
index 02c40f519404d5544a79b166ad49cebbd80c669b..1de86beecfbf22128ea7c08841bb64a3c6d71c0f 100644 (file)
@@ -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;
@@ -1447,7 +1447,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;
@@ -1556,7 +1556,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);
index 83529ffcd4cad36bb289ea041bc3cc9906a43359..4189877fa3127cc114c917d4cde543e619e498cb 100644 (file)
@@ -429,7 +429,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:");
@@ -473,7 +473,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:");
@@ -492,7 +492,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;
@@ -522,7 +522,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:");
@@ -547,7 +547,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:");
@@ -587,7 +587,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;
@@ -624,8 +624,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;
@@ -649,7 +648,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;
@@ -1072,8 +1071,7 @@ handle_monitor_command (char *mon, char *own_buf)
       remote_debug = 0;
       monitor_output ("Protocol debug output disabled.\n");
     }
-  else if (strncmp (mon, "set debug-format ",
-                   sizeof ("set debug-format ") - 1) == 0)
+  else if (startswith (mon, "set debug-format "))
     {
       char *error_msg
        = parse_debug_format_options (mon + sizeof ("set debug-format ") - 1,
@@ -1661,7 +1659,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.  */
@@ -1935,7 +1933,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];
@@ -2089,7 +2087,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;
@@ -2154,7 +2152,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;
@@ -2176,7 +2174,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);
@@ -2207,8 +2205,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
       return;
     }
 
-  if (strncmp ("qSearch:memory:", own_buf,
-              sizeof ("qSearch:memory:") - 1) == 0)
+  if (startswith (own_buf, "qSearch:memory:"))
     {
       require_running (own_buf);
       handle_search_memory (own_buf, packet_len);
@@ -2216,7 +2213,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
     }
 
   if (strcmp (own_buf, "qAttached") == 0
-      || strncmp (own_buf, "qAttached:", sizeof ("qAttached:") - 1) == 0)
+      || startswith (own_buf, "qAttached:"))
     {
       struct process_info *process;
 
@@ -2242,7 +2239,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;
@@ -2672,14 +2669,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 ())
@@ -2691,11 +2688,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 ())
        {
@@ -2707,7 +2704,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 ())
        {
@@ -2719,7 +2716,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 ())
        {
@@ -3211,9 +3208,7 @@ captured_main (int argc, char *argv[])
        }
       else if (strcmp (*next_arg, "--debug") == 0)
        debug_threads = 1;
-      else if (strncmp (*next_arg,
-                       "--debug-format=",
-                       sizeof ("--debug-format=") - 1) == 0)
+      else if (startswith (*next_arg, "--debug-format="))
        {
          char *error_msg
            = parse_debug_format_options ((*next_arg)
@@ -3232,9 +3227,7 @@ captured_main (int argc, char *argv[])
          gdbserver_show_disableable (stdout);
          exit (0);
        }
-      else if (strncmp (*next_arg,
-                       "--disable-packet=",
-                       sizeof ("--disable-packet=") - 1) == 0)
+      else if (startswith (*next_arg, "--disable-packet="))
        {
          char *packets, *tok;
 
@@ -3533,7 +3526,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)
index 6fcd0b07b5d61615fe404cd9d7eda122050c4f0d..27fcf032479d786c7d913ded36c6b0fbb1f8df56 100644 (file)
@@ -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;
                }
@@ -7215,21 +7214,15 @@ gdb_agent_helper_thread (void *arg)
                {
                  cmd_qtsstm (cmd_buf);
                }
-             else if (strncmp ("unprobe_marker_at:",
-                               cmd_buf,
-                               sizeof ("unprobe_marker_at:") - 1) == 0)
+             else if (startswith (cmd_buf, "unprobe_marker_at:"))
                {
                  unprobe_marker_at (cmd_buf);
                }
-             else if (strncmp ("probe_marker_at:",
-                               cmd_buf,
-                               sizeof ("probe_marker_at:") - 1) == 0)
+             else if (startswith (cmd_buf, "probe_marker_at:"))
                {
                  probe_marker_at (cmd_buf);
                }
-             else if (strncmp ("qTSTMat:",
-                               cmd_buf,
-                               sizeof ("qTSTMat:") - 1) == 0)
+             else if (startswith (cmd_buf, "qTSTMat:"))
                {
                  cmd_qtstmat (cmd_buf);
                }
index 2b24c8717bc725143accdb37a06cbc35252b82ac..6c86765b2db03984a2ea4866df7a431caa115181 100644 (file)
@@ -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)
        {
index 24f64bee93bc4fd3d89b1ce6116ea97d04180835..d087a12100cdb1d198072a5ba927e8243636badf 100644 (file)
@@ -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.  */
@@ -2471,7 +2471,7 @@ check_stub_method_group (struct type *type, int method_id)
 
      Therefore the only thing we need to handle here are v2 operator
      names.  */
-  if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0)
+  if (found_stub && !startswith (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z"))
     {
       int ret;
       char dem_opname[256];
index 53893747834bd2cc8b9b403851bc5f6139b49dae..68b734c1b18fc0a1e0b633a2222c29186819e5d2 100644 (file)
@@ -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
index 6a96d21473e94015d73ca668f9975b9f1c5779f8..d1ed8fce24cedbede1e4619e75eb3458576d60e9 100644 (file)
@@ -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");
 }
 
 
@@ -330,7 +330,7 @@ gnuv3_rtti_type (struct value *value,
      should work just as well, and doesn't read target memory.  */
   vtable_symbol_name = MSYMBOL_DEMANGLED_NAME (vtable_symbol);
   if (vtable_symbol_name == NULL
-      || strncmp (vtable_symbol_name, "vtable for ", 11))
+      || !startswith (vtable_symbol_name, "vtable for "))
     {
       warning (_("can't find linker symbol for virtual table for `%s' value"),
               TYPE_SAFE_NAME (values_type));
index 9bdc99a79995389a8ccace02b12803d03dbeb7c4..b48467d838c5fb12a797ce126b076ecc8847d89c 100644 (file)
@@ -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.  */
index 196b4a13633253af8683ef4fa6c0fd391ce35a08..d21a7aec8c1eaa4d5705a2be32286ccbe8a25358 100644 (file)
@@ -1216,11 +1216,11 @@ tyscm_lookup_typename (const char *type_name, const struct block *block)
 
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
-      if (!strncmp (type_name, "struct ", 7))
+      if (startswith (type_name, "struct "))
        type = lookup_struct (type_name + 7, NULL);
-      else if (!strncmp (type_name, "union ", 6))
+      else if (startswith (type_name, "union "))
        type = lookup_union (type_name + 6, NULL);
-      else if (!strncmp (type_name, "enum ", 5))
+      else if (startswith (type_name, "enum "))
        type = lookup_enum (type_name + 5, NULL);
       else
        type = lookup_typename (current_language, get_current_arch (),
index a4f64e515d01c9c3f16aa3bec85e531eedce6cfd..79ff478fa9532bba8419398b88d7f478fd90e1ee 100644 (file)
@@ -107,7 +107,7 @@ core_process_module_section (bfd *abfd, asection *sect, void *obj)
 
   gdb_byte *buf = NULL;
 
-  if (strncmp (sect->name, ".module", 7) != 0)
+  if (!startswith (sect->name, ".module"))
     return;
 
   buf = xmalloc (bfd_get_section_size (sect) + 1);
index 8c08f8b850bfd6760142e88225594d7eb723d91a..a78bedfc5fb6967751a3ad950db3cd9328737efd 100644 (file)
@@ -1824,8 +1824,7 @@ i386_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
       if (post_prologue_pc
          && (cust != NULL
              && COMPUNIT_PRODUCER (cust) != NULL
-             && strncmp (COMPUNIT_PRODUCER (cust), "clang ",
-                         sizeof ("clang ") - 1) == 0))
+             && startswith (COMPUNIT_PRODUCER (cust), "clang ")))
         return max (start_pc, post_prologue_pc);
     }
  
@@ -3854,8 +3853,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);
        }
index 5e1d7f8115303ed119ce92d24fb8932054b75e73..eae445c845f6bfb85842db59696d692b3b9c0fc8 100644 (file)
@@ -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 = {
index 3737b8f6f1cfed1892a0c029317c2ef4ee2f7a6e..99104e9b673d924c18e1a642afebd78aa39eb97b 100644 (file)
@@ -791,7 +791,7 @@ continue_command (char *args, int from_tty)
 
   if (args != NULL)
     {
-      if (strncmp (args, "-a", sizeof ("-a") - 1) == 0)
+      if (startswith (args, "-a"))
        {
          all_threads = 1;
          args += sizeof ("-a") - 1;
@@ -2870,7 +2870,7 @@ interrupt_command (char *args, int from_tty)
       dont_repeat ();          /* Not for the faint of heart.  */
 
       if (args != NULL
-         && strncmp (args, "-a", sizeof ("-a") - 1) == 0)
+         && startswith (args, "-a"))
        all_threads = 1;
 
       if (!non_stop && all_threads)
index 5338c95fa387892be5268092e0327c85c9401e8f..0bf6d10b31e66022d8eaa83cefc9ce33a7e38eff 100644 (file)
@@ -168,12 +168,12 @@ java_type_print_base (struct type *type, struct ui_file *stream, int show,
            {
              QUIT;
              /* Don't print out virtual function table.  */
-             if (strncmp (TYPE_FIELD_NAME (type, i), "_vptr", 5) == 0
+             if (startswith (TYPE_FIELD_NAME (type, i), "_vptr")
                  && is_cplus_marker ((TYPE_FIELD_NAME (type, i))[5]))
                continue;
 
              /* Don't print the dummy field "class".  */
-             if (strncmp (TYPE_FIELD_NAME (type, i), "class", 5) == 0)
+             if (startswith (TYPE_FIELD_NAME (type, i), "class"))
                continue;
 
              print_spaces_filtered (level + 4, stream);
index 0d012b402b732213f34fe921ac95df5e4c19f21e..7d7c58d5f2b648392d177ee60e461036c08edb97 100644 (file)
@@ -454,8 +454,7 @@ is_ada_operator (const char *string)
 
   for (mapping = ada_opname_table;
        mapping->encoded != NULL
-        && strncmp (mapping->decoded, string,
-                    strlen (mapping->decoded)) != 0; ++mapping)
+        && !startswith (string, mapping->decoded); ++mapping)
     ;
 
   return mapping->decoded == NULL ? 0 : strlen (mapping->decoded);
@@ -1122,9 +1121,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 +1209,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
index 4a5a066721685a59279fddc2b520fc120e968e59..627280ed9d44faa216ff6c1e07331c72c837ce61 100644 (file)
@@ -4215,13 +4215,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);
     }
 
index 21bca390721ba8ad624f011ca514f2647000efec..be198722bf9862bd538951c9fcd53a8fc69de82c 100644 (file)
@@ -538,7 +538,7 @@ m2_record_fields (struct type *type, struct ui_file *stream, int show,
   /* Print the tag if it exists.  */
   if (TYPE_TAG_NAME (type) != NULL)
     {
-      if (strncmp (TYPE_TAG_NAME (type), "$$", 2) != 0)
+      if (!startswith (TYPE_TAG_NAME (type), "$$"))
        {
          fputs_filtered (TYPE_TAG_NAME (type), stream);
          if (show > 0)
index 9d6b8b369d1cd072983b83ee591c10f816da0453..a2ac53795a67eb85bf1d2fbbe006754cc34ed45d 100644 (file)
@@ -447,7 +447,7 @@ m32r_upload_command (char *args, int from_tty)
 
       myIPaddress = skip_spaces (myIPaddress);
 
-      if (!strncmp (myIPaddress, "0.0.", 4))   /* empty */
+      if (startswith (myIPaddress, "0.0."))    /* empty */
        error (_("Please use 'set board-address' to "
                 "set the M32R-EVA board's IP address."));
       if (strchr (myIPaddress, '('))
index 790f665049a52d16bb429b1698321020e98d3cd1..831bbcb622e0636e88c4da40e10d6792b1fe3dc0 100644 (file)
@@ -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)
index a40049a0b0d2a5f9520dc4997ac153e80c475aec..3db1239f2419defd6c19af8f01d738da15bf30ad 100644 (file)
@@ -325,7 +325,7 @@ extract_identifier (char **expp, int is_parameter)
   char *p = *expp;
   unsigned int len;
 
-  if (is_parameter && !strncmp (p, "...", 3))
+  if (is_parameter && startswith (p, "..."))
     {
       /* Ok.  */
     }
@@ -339,7 +339,7 @@ extract_identifier (char **expp, int is_parameter)
        ;
     }
 
-  if (is_parameter && !strncmp (p, "...", 3))      
+  if (is_parameter && startswith (p, "..."))      
     p += 3;
 
   len = p - *expp;
index 66251db3938e41a6e99686891b6a3b5cf9f94d7b..beffadf10035e86c1de751539e0dd7cb9cc7215d 100644 (file)
@@ -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;
index f8985e8e873f73a6801b399337a1919e11b0897f..d7097a9394d86abdc7fa57ac9dad40d40d570985 100644 (file)
@@ -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)
index eb171bf3f9b751a25f39bc4d6defb4a1b2703d2a..0246b27bbad3467da9097d75e212cd3f3069b5b8 100644 (file)
@@ -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;
 }
 
index bd8faef26bd3f0f0e6a537fd66e96d96a74f3ab4..6e8ccd688a42af1be95f90654d190c2747b46448 100644 (file)
@@ -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.  */
@@ -3813,7 +3812,7 @@ mips_stub_frame_sniffer (const struct frame_unwind *self,
   msym = lookup_minimal_symbol_by_pc (pc);
   if (msym.minsym != NULL
       && MSYMBOL_LINKAGE_NAME (msym.minsym) != NULL
-      && strncmp (MSYMBOL_LINKAGE_NAME (msym.minsym), ".pic.", 5) == 0)
+      && startswith (MSYMBOL_LINKAGE_NAME (msym.minsym), ".pic."))
     return 1;
 
   return 0;
@@ -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
@@ -7934,7 +7933,7 @@ mips_skip_pic_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
   if (msym.minsym == NULL
       || BMSYMBOL_VALUE_ADDRESS (msym) != pc
       || MSYMBOL_LINKAGE_NAME (msym.minsym) == NULL
-      || strncmp (MSYMBOL_LINKAGE_NAME (msym.minsym), ".pic.", 5) != 0)
+      || !startswith (MSYMBOL_LINKAGE_NAME (msym.minsym), ".pic."))
     return 0;
 
   /* A two-instruction header.  */
@@ -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"));
 }
 
index f4ee41adcc6c18e68a185ed956d4c0ba8d0106a7..622ce552040f5af90eeba9720474cf32bc21c6d3 100644 (file)
@@ -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.  */
index 1e922b94824ae876d51065c351a18bb7f6c732d9..f1493839f60254f1a96d2d3cb2784a38ecce9d41 100644 (file)
@@ -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;
index 59d97d424b5254dc9be03ae711f3dbcd920645d8..762d80f6c82267b3eb90f62a6b9bc013ae2df2c2 100644 (file)
@@ -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"));
 }
index 5a7a887253b60b14fc6dff7177c1c9a562723002..b5bf4d456ec32675f2efd5d30131d82025cb6028 100644 (file)
@@ -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)
     {
@@ -567,7 +567,7 @@ pascal_type_print_base (struct type *type, struct ui_file *stream, int show,
            {
              QUIT;
              /* Don't print out virtual function table.  */
-             if ((strncmp (TYPE_FIELD_NAME (type, i), "_vptr", 5) == 0)
+             if ((startswith (TYPE_FIELD_NAME (type, i), "_vptr"))
                  && is_cplus_marker ((TYPE_FIELD_NAME (type, i))[5]))
                continue;
 
@@ -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))
index a7b1163571642b4ad47bc880a2f8dae754e9e5a8..6c6eacfb16aff046e1da7ccd67781f64a8da0f4b 100644 (file)
@@ -985,7 +985,7 @@ ppc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
 static int
 ppc_linux_spu_section (bfd *abfd, asection *asect, void *user_data)
 {
-  return strncmp (bfd_section_name (abfd, asect), "SPU/", 4) == 0;
+  return startswith (bfd_section_name (abfd, asect), "SPU/");
 }
 
 static const struct target_desc *
index a3da67807de52703d3dc4ccb086b84422e9af8bb..72d4dcf93e44f5dc75c98d355773cd198f0a4830 100644 (file)
@@ -747,11 +747,11 @@ typy_lookup_typename (const char *type_name, const struct block *block)
 
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
-      if (!strncmp (type_name, "struct ", 7))
+      if (startswith (type_name, "struct "))
        type = lookup_struct (type_name + 7, NULL);
-      else if (!strncmp (type_name, "union ", 6))
+      else if (startswith (type_name, "union "))
        type = lookup_union (type_name + 6, NULL);
-      else if (!strncmp (type_name, "enum ", 5))
+      else if (startswith (type_name, "enum "))
        type = lookup_enum (type_name + 5, NULL);
       else
        type = lookup_typename (python_language, python_gdbarch,
index 9373ceb2e5f185567e9e1d2cf5d08b4104998a83..366eba0a427fb555f3dda3bb547ff9ccfbb2cfcf 100644 (file)
@@ -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);
index c55b75c6fecb90c398053fb6d4443adc6e70e3e5..f7ea0b85c924f6fe90f73d88f4faa7dd196ef2c4 100644 (file)
@@ -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);
index 3e07fc7241aa72176f274419ba5021f06fffdf53..2d24a9a57f736ff412a82884f145eb8b1d5e0453 100644 (file)
@@ -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;
     }
index 8f783a440b007435f095b462814f78a7a86d9536..495dfdc41522bbbe59c2b30b357ba8b727f4be31 100644 (file)
@@ -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;
@@ -3157,14 +3157,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 != ';')
@@ -3173,7 +3173,7 @@ get_offsets (void)
       else
        lose = 1;
 
-      if (!lose && strncmp (ptr, ";Bss=", 5) == 0)
+      if (!lose && startswith (ptr, ";Bss="))
        {
          ptr += 5;
          while (*ptr && *ptr != ';')
@@ -3185,7 +3185,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.  */
@@ -3193,7 +3193,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 != ';')
@@ -3800,7 +3800,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;
 
@@ -3840,7 +3840,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 "
@@ -4631,7 +4631,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;
@@ -5729,8 +5729,7 @@ Packet: '%s'\n"),
 
            if (*p == '\0')
              ;
-           else if (strncmp (p,
-                             "process:", sizeof ("process:") - 1) == 0)
+           else if (startswith (p, "process:"))
              {
                ULONGEST upid;
 
@@ -10212,9 +10211,7 @@ remote_bfd_iovec_stat (struct bfd *abfd, void *stream, struct stat *sb)
 int
 remote_filename_p (const char *filename)
 {
-  return strncmp (filename,
-                 REMOTE_SYSROOT_PREFIX,
-                 sizeof (REMOTE_SYSROOT_PREFIX) - 1) == 0;
+  return startswith (filename, REMOTE_SYSROOT_PREFIX);
 }
 
 bfd *
index e0946c80ba830883d5d88f80eed968c84c8addaa..ed55a3a4ddab585b0d4a64cad0da68c77e7f919b 100644 (file)
@@ -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);
index 46f6e41c5eb63f1197e6914d313eb2db2fd2fe36..0a869292517e3f3ef98bb47a87b43d032548bca0 100644 (file)
@@ -2220,7 +2220,7 @@ static int
 rs6000_in_solib_return_trampoline (struct gdbarch *gdbarch,
                                   CORE_ADDR pc, const char *name)
 {
-  return name && !strncmp (name, "@FIX", 4);
+  return name && startswith (name, "@FIX");
 }
 
 /* Skip code that the user doesn't want to see when stepping:
index 3467b1f694fd05b35cfd9df1d22e9a345264a4f2..9c3dcf4ee4d227013354b0898d3e6e0790ffc9ed 100644 (file)
@@ -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, ':');
index 59bf7af3ca46a8ced82846dbc4394f4fc3336639..b7e620d0f411c2bdff2c43e9dd25c2aaae225867 100644 (file)
@@ -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.  */
index 2bee2b1fa55b1d01a3f28aad5866281021bb6040..49cfe766a62009b1520fef47d1e8f3b902ddf1d6 100644 (file)
@@ -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;
 
index 78e3b58e07090e51b771f5f49edf4b2d7842cf0e..32da6ac697ae46b16c17606b7ae57c00be0b5a97 100644 (file)
@@ -216,7 +216,7 @@ sparc64nbsd_sigtramp_frame_sniffer (const struct frame_unwind *self,
   find_pc_partial_function (pc, &name, NULL, NULL);
   if (sparc64nbsd_pc_in_sigtramp (pc, name))
     {
-      if (name == NULL || strncmp (name, "__sigtramp_sigcontext", 21))
+      if (name == NULL || !startswith (name, "__sigtramp_sigcontext"))
        return 1;
     }
 
index b5fab8b0ea956455da8c8f21576754d2211c2f74..c145919926f1834a2a369907f936669dbcb7d088 100644 (file)
@@ -241,7 +241,7 @@ sparc32nbsd_sigcontext_frame_sniffer (const struct frame_unwind *self,
   find_pc_partial_function (pc, &name, NULL, NULL);
   if (sparc32nbsd_pc_in_sigtramp (pc, name))
     {
-      if (name == NULL || strncmp (name, "__sigtramp_sigcontext", 21))
+      if (name == NULL || !startswith (name, "__sigtramp_sigcontext"))
        return 1;
     }
 
index 12168cbefc3c8ed676af016424436563a222b5fd..aebe2d979e18ad14fba30eed4eb7554284840e3c 100644 (file)
@@ -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)
     {
@@ -3950,7 +3950,7 @@ static const char *
 operator_chars (const char *p, const char **end)
 {
   *end = "";
-  if (strncmp (p, "operator", 8))
+  if (!startswith (p, "operator"))
     return *end;
   p += 8;
 
@@ -6003,7 +6003,7 @@ producer_is_realview (const char *producer)
     return 0;
 
   for (i = 0; i < ARRAY_SIZE (arm_idents); i++)
-    if (strncmp (producer, arm_idents[i], strlen (arm_idents[i])) == 0)
+    if (startswith (producer, arm_idents[i]))
       return 1;
 
   return 0;
index 44c6189f824668e40960a5cfebd2ace50a551b08..3ee7243d3d18b3221dd5e1569a9a7a456b145e99 100644 (file)
@@ -426,7 +426,7 @@ tfile_open (const char *arg, int from_tty)
 
   bytes += TRACE_HEADER_SIZE;
   if (!(header[0] == 0x7f
-       && (strncmp (header + 1, "TRACE0\n", 7) == 0)))
+       && (startswith (header + 1, "TRACE0\n"))))
     error (_("File is not a valid trace file."));
 
   push_target (&tfile_ops);
@@ -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);
index 0774f5e2a28aa580f3040ed733d0d2acb5e88e59..7c04ecbcd76741ae049514fa30d6604e43c8af16 100644 (file)
@@ -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')
index 3eff9fdb6b89016dbbe3a35f7106e7f73f135b93..43bcec2aeb0ea9f7e455ca6f12b685bbd54ad21b 100644 (file)
@@ -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++;
index 4f9f4f05a2dd56e980d0ecddbe18e535282c7ba7..7172bba719e2e19a734fb09a694bedd276066e00 100644 (file)
@@ -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;
 
index 23a4b3778f8120f30b6b6c1967273f91c1a0371d..b096a516a1e67e8ff09620f830a6336dc47d799c 100644 (file)
@@ -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))
index 107bdf2bb6a66dd3f0e6215453d640efc763e279..42a6046a48714a4e1991a8fc42d40c74afc6acc8 100644 (file)
@@ -813,11 +813,10 @@ handle_output_debug_string (struct target_waitstatus *ourstatus)
        &s, 1024, 0)
       || !s || !*s)
     /* nothing to do */;
-  else if (strncmp (s, _CYGWIN_SIGNAL_STRING,
-                   sizeof (_CYGWIN_SIGNAL_STRING) - 1) != 0)
+  else if (!startswith (s, _CYGWIN_SIGNAL_STRING))
     {
 #ifdef __CYGWIN__
-      if (strncmp (s, "cYg", 3) != 0)
+      if (!startswith (s, "cYg"))
 #endif
        warning (("%s"), s);
     }
@@ -1014,8 +1013,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
index e83bd13e16365b77f2f3b599958a34c4cd588c2e..3cb6eda305389db9593616a87c15b246fb536990 100644 (file)
@@ -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,