Hello.

I made similar changes to binutils some time ago and I would like to
come up with the same function for elfutils. Note that current construct
is quite error prone, I found for instance these 2 bad usages:

diff --git a/libdwfl/relocate.c b/libdwfl/relocate.c
index 88b5211d..b6de3510 100644
--- a/libdwfl/relocate.c
+++ b/libdwfl/relocate.c
@@ -518,7 +518,7 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const 
GElf_Ehdr *ehdr,
        Nothing to do here.  */
     return DWFL_E_NOERROR;
 
-  if (strncmp (tname, ".zdebug", strlen ("zdebug")) == 0)
+  if (strncmp (tname, ".zdebug", strlen (".zdebug")) == 0)
     elf_compress_gnu (tscn, 0, 0);
 
   if ((tshdr->sh_flags & SHF_COMPRESSED) != 0)
@@ -539,7 +539,7 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const 
GElf_Ehdr *ehdr,
   if (sname == NULL)
     return DWFL_E_LIBELF;
 
-  if (strncmp (sname, ".zdebug", strlen ("zdebug")) == 0)
+  if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
     elf_compress_gnu (scn, 0, 0);
 
   if ((shdr->sh_flags & SHF_COMPRESSED) != 0)

I'm not convinced about function declaration in system.h. Is it a proper 
location?
And the function is not used in debuginfod/debuginfod-client.c and 
debuginfod/debuginfod.cxx.
I would need another decl for these, am I right?

Cheers,
Martin

---
 backends/aarch64_symbol.c          |  4 +++-
 backends/arm_symbol.c              |  4 +++-
 lib/system.h                       |  9 +++++++++
 libasm/libasmP.h                   |  2 +-
 libdw/dwarf_begin_elf.c            |  4 +++-
 libdwfl/dwfl_frame.c               |  4 +++-
 libdwfl/dwfl_module_getdwarf.c     |  4 ++--
 libdwfl/linux-kernel-modules.c     |  4 ++--
 libdwfl/linux-pid-attach.c         |  6 ++++--
 libdwfl/relocate.c                 |  8 +++++---
 libebl/eblobjnotetypename.c        |  5 +++--
 libebl/eblopenbackend.c            |  4 ++--
 src/elfclassify.c                  |  8 +++-----
 src/elfcompress.c                  | 25 +++++++++++--------------
 src/nm.c                           |  2 +-
 src/readelf.c                      | 11 +++++------
 src/strip.c                        |  2 +-
 tests/dwelf_elf_e_machine_string.c |  4 +++-
 tests/dwelfgnucompressed.c         |  4 +++-
 tests/elfgetchdr.c                 |  4 +++-
 tests/elfputzdata.c                |  4 +++-
 tests/vdsosyms.c                   |  2 +-
 22 files changed, 74 insertions(+), 50 deletions(-)

diff --git a/backends/aarch64_symbol.c b/backends/aarch64_symbol.c
index 464a5695..15e0805b 100644
--- a/backends/aarch64_symbol.c
+++ b/backends/aarch64_symbol.c
@@ -30,6 +30,8 @@
 # include <config.h>
 #endif
 
+#include <system.h>
+
 #include <elf.h>
 #include <stddef.h>
 #include <string.h>
@@ -104,7 +106,7 @@ aarch64_data_marker_symbol (const GElf_Sym *sym, const char 
*sname)
   return (sym != NULL && sname != NULL
          && sym->st_size == 0 && GELF_ST_BIND (sym->st_info) == STB_LOCAL
          && GELF_ST_TYPE (sym->st_info) == STT_NOTYPE
-         && (strcmp (sname, "$d") == 0 || strncmp (sname, "$d.", 3) == 0));
+         && (strcmp (sname, "$d") == 0 || startswith (sname, "$d.")));
 }
 
 const char *
diff --git a/backends/arm_symbol.c b/backends/arm_symbol.c
index c8e1d7f9..a733cfff 100644
--- a/backends/arm_symbol.c
+++ b/backends/arm_symbol.c
@@ -30,6 +30,8 @@
 # include <config.h>
 #endif
 
+#include <system.h>
+
 #include <elf.h>
 #include <stddef.h>
 #include <string.h>
@@ -154,5 +156,5 @@ arm_data_marker_symbol (const GElf_Sym *sym, const char 
*sname)
   return (sym != NULL && sname != NULL
           && sym->st_size == 0 && GELF_ST_BIND (sym->st_info) == STB_LOCAL
           && GELF_ST_TYPE (sym->st_info) == STT_NOTYPE
-          && (strcmp (sname, "$d") == 0 || strncmp (sname, "$d.", 3) == 0));
+          && (strcmp (sname, "$d") == 0 || startswith (sname, "$d.")));
 }
diff --git a/lib/system.h b/lib/system.h
index 1c478e1c..e4a2aed8 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -37,6 +37,7 @@
 #include <endian.h>
 #include <byteswap.h>
 #include <unistd.h>
+#include <string.h>
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 # define LE32(n)       (n)
@@ -69,6 +70,14 @@
     ((void *) ((char *) memcpy (dest, src, n) + (size_t) n))
 #endif
 
+/* Return TRUE if the start of STR matches PREFIX, FALSE otherwise.  */
+
+static inline int
+startswith (const char *str, const char *prefix)
+{
+  return strncmp (str, prefix, strlen (prefix)) == 0;
+}
+
 /* A special gettext function we use if the strings are too short.  */
 #define sgettext(Str) \
   ({ const char *__res = strrchr (_(Str), '|');                              \
diff --git a/libasm/libasmP.h b/libasm/libasmP.h
index 8b72f32b..5b5fb776 100644
--- a/libasm/libasmP.h
+++ b/libasm/libasmP.h
@@ -302,6 +302,6 @@ extern int __disasm_cb_internal (DisasmCtx_t *ctx, const 
uint8_t **startp,
 // XXX The second part should probably be controlled by an option which
 // isn't implemented yet
 // XXX Also, the format will change with the backend.
-#define asm_emit_symbol_p(name) (strncmp (name, ".L", 2) != 0)
+#define asm_emit_symbol_p(name) (!startswith (name, ".L"))
 
 #endif /* libasmP.h */
diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c
index 757ac4fa..9e944b86 100644
--- a/libdw/dwarf_begin_elf.c
+++ b/libdw/dwarf_begin_elf.c
@@ -30,6 +30,8 @@
 # include <config.h>
 #endif
 
+#include <system.h>
+
 #include <assert.h>
 #include <stdbool.h>
 #include <stddef.h>
@@ -138,7 +140,7 @@ check_section (Dwarf *result, size_t shstrndx, Elf_Scn 
*scn, bool inscngrp)
          break;
        }
       else if (scnlen > 14 /* .gnu.debuglto_ prefix. */
-              && strncmp (scnname, ".gnu.debuglto_", 14) == 0
+              && startswith (scnname, ".gnu.debuglto_")
               && strcmp (&scnname[14], dwarf_scnnames[cnt]) == 0)
        break;
     }
diff --git a/libdwfl/dwfl_frame.c b/libdwfl/dwfl_frame.c
index 5bbf850e..77e0c5cb 100644
--- a/libdwfl/dwfl_frame.c
+++ b/libdwfl/dwfl_frame.c
@@ -30,6 +30,8 @@
 # include <config.h>
 #endif
 
+#include <system.h>
+
 #include "libdwflP.h"
 #include <unistd.h>
 
@@ -172,7 +174,7 @@ dwfl_attach_state (Dwfl *dwfl, Elf *elf, pid_t pid,
             is called from dwfl_linux_proc_attach with elf == NULL.
             __libdwfl_module_getebl will call __libdwfl_getelf which
             will call the find_elf callback.  */
-         if (strncmp (mod->name, "[vdso: ", 7) == 0
+         if (startswith (mod->name, "[vdso: ")
              || strcmp (strrchr (mod->name, ' ') ?: "",
                         " (deleted)") == 0)
            continue;
diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c
index 2f3dd0dd..6f076057 100644
--- a/libdwfl/dwfl_module_getdwarf.c
+++ b/libdwfl/dwfl_module_getdwarf.c
@@ -1162,7 +1162,7 @@ find_symtab (Dwfl_Module *mod)
   if (sname == NULL)
     goto elferr;
 
-  if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+  if (startswith (sname, ".zdebug"))
     /* Try to uncompress, but it might already have been, an error
        might just indicate, already uncompressed.  */
     elf_compress_gnu (symstrscn, 0, 0);
@@ -1245,7 +1245,7 @@ find_symtab (Dwfl_Module *mod)
       if (sname == NULL)
        goto elferr;
 
-      if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+      if (startswith (sname, ".zdebug"))
        /* Try to uncompress, but it might already have been, an error
           might just indicate, already uncompressed.  */
        elf_compress_gnu (aux_strscn, 0, 0);
diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c
index 6edb27f2..c0f8dfa4 100644
--- a/libdwfl/linux-kernel-modules.c
+++ b/libdwfl/linux-kernel-modules.c
@@ -924,7 +924,7 @@ dwfl_linux_kernel_module_section_address
 
          if (!strcmp (secname, ".modinfo")
              || !strcmp (secname, ".data.percpu")
-             || !strncmp (secname, ".exit", 5))
+             || startswith (secname, ".exit"))
            {
              *addr = (Dwarf_Addr) -1l;
              return DWARF_CB_OK;
@@ -935,7 +935,7 @@ dwfl_linux_kernel_module_section_address
             behavior, and this cruft leaks out into the /sys information.
             The file name for ".init*" may actually look like "_init*".  */
 
-         const bool is_init = !strncmp (secname, ".init", 5);
+         const bool is_init = startswith (secname, ".init");
          if (is_init)
            {
              if (asprintf (&sysfile, SECADDRDIRFMT "_%s",
diff --git a/libdwfl/linux-pid-attach.c b/libdwfl/linux-pid-attach.c
index fdf5c9b1..cd534825 100644
--- a/libdwfl/linux-pid-attach.c
+++ b/libdwfl/linux-pid-attach.c
@@ -30,6 +30,8 @@
 # include <config.h>
 #endif
 
+#include <system.h>
+
 #include "libelfP.h"
 #include "libdwflP.h"
 #include <sys/types.h>
@@ -59,7 +61,7 @@ linux_proc_pid_is_stopped (pid_t pid)
 
   have_state = false;
   while (fgets (buffer, sizeof (buffer), procfile) != NULL)
-    if (strncmp (buffer, "State:", 6) == 0)
+    if (startswith (buffer, "State:"))
       {
        have_state = true;
        break;
@@ -407,7 +409,7 @@ dwfl_linux_proc_attach (Dwfl *dwfl, pid_t pid, bool 
assume_ptrace_stopped)
   char *line = NULL;
   size_t linelen = 0;
   while (getline (&line, &linelen, procfile) >= 0)
-    if (strncmp (line, "Tgid:", 5) == 0)
+    if (startswith (line, "Tgid:"))
       {
        errno = 0;
        char *endptr;
diff --git a/libdwfl/relocate.c b/libdwfl/relocate.c
index 88b5211d..0497bd4f 100644
--- a/libdwfl/relocate.c
+++ b/libdwfl/relocate.c
@@ -30,6 +30,8 @@
 # include <config.h>
 #endif
 
+#include <system.h>
+
 #include "libelfP.h"
 #include "libdwflP.h"
 
@@ -237,7 +239,7 @@ resolve_symbol (Dwfl_Module *referer, struct 
reloc_symtab_cache *symtab,
            return DWFL_E_LIBELF;
 
          /* If the section is already decompressed, that isn't an error.  */
-         if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+         if (startswith (sname, ".zdebug"))
            elf_compress_gnu (scn, 0, 0);
 
          if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
@@ -518,7 +520,7 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const 
GElf_Ehdr *ehdr,
        Nothing to do here.  */
     return DWFL_E_NOERROR;
 
-  if (strncmp (tname, ".zdebug", strlen ("zdebug")) == 0)
+  if (startswith (tname, ".zdebug"))
     elf_compress_gnu (tscn, 0, 0);
 
   if ((tshdr->sh_flags & SHF_COMPRESSED) != 0)
@@ -539,7 +541,7 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const 
GElf_Ehdr *ehdr,
   if (sname == NULL)
     return DWFL_E_LIBELF;
 
-  if (strncmp (sname, ".zdebug", strlen ("zdebug")) == 0)
+  if (startswith (sname, ".zdebug"))
     elf_compress_gnu (scn, 0, 0);
 
   if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
diff --git a/libebl/eblobjnotetypename.c b/libebl/eblobjnotetypename.c
index 9daddcda..4662906d 100644
--- a/libebl/eblobjnotetypename.c
+++ b/libebl/eblobjnotetypename.c
@@ -31,6 +31,8 @@
 # include <config.h>
 #endif
 
+#include <system.h>
+
 #include <inttypes.h>
 #include <stdio.h>
 #include <string.h>
@@ -79,8 +81,7 @@ ebl_object_note_type_name (Ebl *ebl, const char *name, 
uint32_t type,
            }
        }
 
-      if (strncmp (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX,
-                  strlen (ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX)) == 0)
+      if (startswith (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX))
        {
          /* GNU Build Attribute notes (ab)use the owner name to store
             most of their data.  Don't decode everything here.  Just
diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c
index a8af1658..71fafed7 100644
--- a/libebl/eblopenbackend.c
+++ b/libebl/eblopenbackend.c
@@ -616,9 +616,9 @@ default_debugscn_p (const char *name)
                                   / sizeof (dwarf_scn_names[0]));
   for (size_t cnt = 0; cnt < ndwarf_scn_names; ++cnt)
     if (strcmp (name, dwarf_scn_names[cnt]) == 0
-       || (strncmp (name, ".zdebug", strlen (".zdebug")) == 0
+       || (startswith (name, ".zdebug")
            && strcmp (&name[2], &dwarf_scn_names[cnt][1]) == 0)
-       || (strncmp (name, ".gnu.debuglto_", strlen (".gnu.debuglto_")) == 0
+       || (startswith (name, ".gnu.debuglto_")
            && strcmp (&name[14], dwarf_scn_names[cnt]) == 0))
       return true;
 
diff --git a/src/elfclassify.c b/src/elfclassify.c
index ae626bb1..fe7eeeed 100644
--- a/src/elfclassify.c
+++ b/src/elfclassify.c
@@ -16,6 +16,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
+#include <system.h>
 
 #include <argp.h>
 #include <error.h>
@@ -335,11 +336,8 @@ run_classify (void)
                     stderr);
            has_bits_alloc = true;
          }
-        const char *debug_prefix = ".debug_";
-        const char *zdebug_prefix = ".zdebug_";
-        if (strncmp (section_name, debug_prefix, strlen (debug_prefix)) == 0
-           || strncmp (section_name, zdebug_prefix,
-                       strlen (zdebug_prefix)) == 0)
+        if (startswith (section_name, ".debug_")
+           || startswith (section_name, ".zdebug_"))
           {
             if (verbose > 1 && !has_debug_sections)
               fputs ("debug: .debug_* section found\n", stderr);
diff --git a/src/elfcompress.c b/src/elfcompress.c
index c5ba6c34..d5bc3300 100644
--- a/src/elfcompress.c
+++ b/src/elfcompress.c
@@ -448,7 +448,7 @@ process_file (const char *fname)
        {
          if (!force && type == T_DECOMPRESS
              && (shdr->sh_flags & SHF_COMPRESSED) == 0
-             && strncmp (sname, ".zdebug", strlen (".zdebug")) != 0)
+             && !startswith (sname, ".zdebug"))
            {
              if (verbose > 0)
                printf ("[%zd] %s already decompressed\n", ndx, sname);
@@ -460,7 +460,7 @@ process_file (const char *fname)
                printf ("[%zd] %s already compressed\n", ndx, sname);
            }
          else if (!force && type == T_COMPRESS_GNU
-                  && strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+                  && startswith (sname, ".zdebug"))
            {
              if (verbose > 0)
                printf ("[%zd] %s already GNU compressed\n", ndx, sname);
@@ -472,11 +472,9 @@ process_file (const char *fname)
              /* Check if we might want to change this section name.  */
              if (! adjust_names
                  && ((type != T_COMPRESS_GNU
-                      && strncmp (sname, ".zdebug",
-                                  strlen (".zdebug")) == 0)
+                      && startswith (sname, ".zdebug"))
                      || (type == T_COMPRESS_GNU
-                         && strncmp (sname, ".debug",
-                                     strlen (".debug")) == 0)))
+                         && startswith (sname, ".debug"))))
                adjust_names = true;
 
              /* We need a buffer this large if we change the names.  */
@@ -696,7 +694,7 @@ process_file (const char *fname)
                                        false, false, verbose > 0) < 0)
                    goto cleanup;
                }
-             else if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+             else if (startswith (sname, ".zdebug"))
                {
                  snamebuf[0] = '.';
                  strcpy (&snamebuf[1], &sname[2]);
@@ -710,7 +708,7 @@ process_file (const char *fname)
              break;
 
            case T_COMPRESS_GNU:
-             if (strncmp (sname, ".debug", strlen (".debug")) == 0)
+             if (startswith (sname, ".debug"))
                {
                  if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
                    {
@@ -757,7 +755,7 @@ process_file (const char *fname)
                }
              else if (verbose >= 0)
                {
-                 if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+                 if (startswith (sname, ".zdebug"))
                    printf ("[%zd] %s unchanged, already GNU compressed",
                            ndx, sname);
                  else
@@ -769,7 +767,7 @@ process_file (const char *fname)
            case T_COMPRESS_ZLIB:
              if ((shdr->sh_flags & SHF_COMPRESSED) == 0)
                {
-                 if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+                 if (startswith (sname, ".zdebug"))
                    {
                      /* First decompress to recompress zlib style.
                         Don't report even when verbose.  */
@@ -900,7 +898,7 @@ process_file (const char *fname)
                      symtab_size = size;
                      symtab_compressed = T_COMPRESS_ZLIB;
                    }
-                 else if (strncmp (name, ".zdebug", strlen (".zdebug")) == 0)
+                 else if (startswith (name, ".zdebug"))
                    {
                      /* Don't report the (internal) uncompression.  */
                      if (compress_section (newscn, size, sname, NULL, ndx,
@@ -1046,7 +1044,7 @@ process_file (const char *fname)
          shstrtab_size = shdr->sh_size;
          if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
            shstrtab_compressed = T_COMPRESS_ZLIB;
-         else if (strncmp (shstrtab_name, ".zdebug", strlen (".zdebug")) == 0)
+         else if (startswith (shstrtab_name, ".zdebug"))
            shstrtab_compressed = T_COMPRESS_GNU;
        }
 
@@ -1187,8 +1185,7 @@ process_file (const char *fname)
                  symtab_size = shdr->sh_size;
                  if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
                    symtab_compressed = T_COMPRESS_ZLIB;
-                 else if (strncmp (symtab_name, ".zdebug",
-                                   strlen (".zdebug")) == 0)
+                 else if (startswith (symtab_name, ".zdebug"))
                    symtab_compressed = T_COMPRESS_GNU;
                }
 
diff --git a/src/nm.c b/src/nm.c
index fb761ef3..ddb67bb1 100644
--- a/src/nm.c
+++ b/src/nm.c
@@ -858,7 +858,7 @@ show_symbols_sysv (Ebl *ebl, GElf_Word strndx, const char 
*fullname,
       bind = ebl_symbol_binding_name (ebl,
                                      GELF_ST_BIND (syms[cnt].sym.st_info),
                                      symbindbuf, sizeof (symbindbuf));
-      if (bind != NULL && strncmp (bind, "GNU_", strlen ("GNU_")) == 0)
+      if (bind != NULL && startswith (bind, "GNU_"))
        bind += strlen ("GNU_");
       printf ("%-*s|%s|%-6s|%-8s|%s|%*s|%s\n",
              longest_name, symstr, addressbuf, bind,
diff --git a/src/readelf.c b/src/readelf.c
index b9740455..9b472622 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -1335,7 +1335,7 @@ There are %zd section headers, starting at offset %#" 
PRIx64 ":\n\
                       _("bad compression header for section %zd: %s"),
                       elf_ndxscn (scn), elf_errmsg (-1));
            }
-         else if (strncmp(".zdebug", sname, strlen (".zdebug")) == 0)
+         else if (startswith (sname, ".zdebug"))
            {
              ssize_t size;
              if ((size = dwelf_scn_gnu_compressed_size (scn)) >= 0)
@@ -11451,7 +11451,7 @@ print_debug (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr 
*ehdr)
                          || (scnlen == dbglen + 5
                              && strstr (name, ".dwo") == name + dbglen + 1)))
                  || (scnlen > 14 /* .gnu.debuglto_ prefix. */
-                     && strncmp (name, ".gnu.debuglto_", 14) == 0
+                     && startswith (name, ".gnu.debuglto_")
                      && strcmp (&name[14], debug_sections[n].name) == 0)
 )
                {
@@ -12455,8 +12455,7 @@ handle_notes_data (Ebl *ebl, const GElf_Ehdr *ehdr,
         into the owner name field.  Extract just the owner name
         prefix here, then use the rest later as data.  */
       bool is_gnu_build_attr
-       = strncmp (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX,
-                  strlen (ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX)) == 0;
+       = startswith (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX);
       const char *print_name = (is_gnu_build_attr
                                ? ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX : name);
       size_t print_namesz = (is_gnu_build_attr
@@ -12636,7 +12635,7 @@ dump_data_section (Elf_Scn *scn, const GElf_Shdr *shdr, 
const char *name)
                        _("Couldn't uncompress section"),
                        elf_ndxscn (scn));
            }
-         else if (strncmp (name, ".zdebug", strlen (".zdebug")) == 0)
+         else if (startswith (name, ".zdebug"))
            {
              if (elf_compress_gnu (scn, 0, 0) < 0)
                printf ("WARNING: %s [%zd]\n",
@@ -12687,7 +12686,7 @@ print_string_section (Elf_Scn *scn, const GElf_Shdr 
*shdr, const char *name)
                        _("Couldn't uncompress section"),
                        elf_ndxscn (scn));
            }
-         else if (strncmp (name, ".zdebug", strlen (".zdebug")) == 0)
+         else if (startswith (name, ".zdebug"))
            {
              if (elf_compress_gnu (scn, 0, 0) < 0)
                printf ("WARNING: %s [%zd]\n",
diff --git a/src/strip.c b/src/strip.c
index 7a5d4e4c..70fc8c03 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -607,7 +607,7 @@ remove_debug_relocations (Ebl *ebl, Elf *elf, GElf_Ehdr 
*ehdr,
          GElf_Chdr tchdr;
          int tcompress_type = 0;
          bool is_gnu_compressed = false;
-         if (strncmp (tname, ".zdebug", strlen ("zdebug")) == 0)
+         if (startswith (tname, ".zdebug"))
            {
              is_gnu_compressed = true;
              if (elf_compress_gnu (tscn, 0, 0) != 1)
diff --git a/tests/dwelf_elf_e_machine_string.c 
b/tests/dwelf_elf_e_machine_string.c
index afad1058..30599c36 100644
--- a/tests/dwelf_elf_e_machine_string.c
+++ b/tests/dwelf_elf_e_machine_string.c
@@ -19,6 +19,8 @@
 # include <config.h>
 #endif
 
+#include <system.h>
+
 #include <assert.h>
 #include <errno.h>
 #include <inttypes.h>
@@ -41,7 +43,7 @@ main (int argc, char **argv)
       const char *machine;
 
       errno = 0;
-      if (strncmp ("0x", argv[i], 2) == 0)
+      if (startswith (argv[i], "0x"))
        val = strtol (&argv[i][2], NULL, 16);
       else
        val = strtol (argv[i], NULL, 10);
diff --git a/tests/dwelfgnucompressed.c b/tests/dwelfgnucompressed.c
index 0132271c..447f3d59 100644
--- a/tests/dwelfgnucompressed.c
+++ b/tests/dwelfgnucompressed.c
@@ -18,6 +18,8 @@
 # include <config.h>
 #endif
 
+#include <system.h>
+
 #include <assert.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -82,7 +84,7 @@ main (int argc, char *argv[])
              break;
            }
 
-         if (strncmp(".zdebug", sname, strlen (".zdebug")) == 0)
+         if (startswith (sname, ".zdebug"))
            {
              ssize_t size;
              if ((size = dwelf_scn_gnu_compressed_size (scn)) == -1)
diff --git a/tests/elfgetchdr.c b/tests/elfgetchdr.c
index 44ba1789..171c4df8 100644
--- a/tests/elfgetchdr.c
+++ b/tests/elfgetchdr.c
@@ -18,6 +18,8 @@
 # include <config.h>
 #endif
 
+#include <system.h>
+
 #include <assert.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -99,7 +101,7 @@ main (int argc, char *argv[])
                }
 
              /* This duplicates what the dwelfgnucompressed testcase does.  */
-             if (strncmp(".zdebug", sname, strlen (".zdebug")) == 0)
+             if (startswith (sname, ".zdebug"))
                {
                  ssize_t size;
                  if ((size = dwelf_scn_gnu_compressed_size (scn)) == -1)
diff --git a/tests/elfputzdata.c b/tests/elfputzdata.c
index 0d9c020e..0ff363f9 100644
--- a/tests/elfputzdata.c
+++ b/tests/elfputzdata.c
@@ -18,6 +18,8 @@
 # include <config.h>
 #endif
 
+#include <system.h>
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -83,7 +85,7 @@ main (int argc, char *argv[])
              printf ("Cannot compress %zd %s\n", idx, name);
            }
          else if ((shdr->sh_flags & SHF_COMPRESSED) != 0
-                  || strncmp (name, ".zdebug", strlen (".zdebug")) == 0)
+                  || startswith (name, ".zdebug"))
            {
              printf ("Already compressed %zd %s\n", idx, name);
            }
diff --git a/tests/vdsosyms.c b/tests/vdsosyms.c
index 83ab034f..ff1a18a8 100644
--- a/tests/vdsosyms.c
+++ b/tests/vdsosyms.c
@@ -43,7 +43,7 @@ module_callback (Dwfl_Module *mod, void **userdata 
__attribute__((unused)),
 {
   /* We can only recognize the vdso by inspecting the "magic name".  */
   printf ("module name: %s\n", name);
-  if (strncmp ("[vdso: ", name, 7) == 0)
+  if (startswith (name, "[vdso: "))
     {
       vdso_syms = dwfl_module_getsymtab (mod);
       printf ("vdso syms: %d\n", vdso_syms);
-- 
2.31.1

Reply via email to