public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] RFC: come up with startswith function.
@ 2021-04-19 13:18 Martin Liška
  2021-04-20 11:43 ` Mark Wielaard
  0 siblings, 1 reply; 8+ messages in thread
From: Martin Liška @ 2021-04-19 13:18 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] RFC: come up with startswith function.
  2021-04-19 13:18 [PATCH] RFC: come up with startswith function Martin Liška
@ 2021-04-20 11:43 ` Mark Wielaard
  2021-04-20 11:50   ` Érico Nogueira
  2021-04-21  7:13   ` Martin Liška
  0 siblings, 2 replies; 8+ messages in thread
From: Mark Wielaard @ 2021-04-20 11:43 UTC (permalink / raw)
  To: Martin Liška, elfutils-devel

Hi Martin,

On Mon, 2021-04-19 at 15:18 +0200, Martin Liška wrote:
> 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)

Urgh. Thanks for finding this!

> I'm not convinced about function declaration in system.h. Is it a
> proper location?

Yes, I think it is.

> 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?

I think they both can simply include system.h (might want to double
check the -I search path in debuginfod/Makefile.am) because system.h
should be stand-alone, you don't need to link to anything else.

Maybe for debuginfod.cxx there is a better C++ way for strings. But if
it uses C strings, then it could also simply include system.h.

Thanks,

Mark

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] RFC: come up with startswith function.
  2021-04-20 11:43 ` Mark Wielaard
@ 2021-04-20 11:50   ` Érico Nogueira
  2021-04-21  7:13   ` Martin Liška
  1 sibling, 0 replies; 8+ messages in thread
From: Érico Nogueira @ 2021-04-20 11:50 UTC (permalink / raw)
  To: Mark Wielaard, Martin Liška, elfutils-devel



Em 20/04/2021 08:43, Mark Wielaard escreveu:
> Hi Martin,
> 
> On Mon, 2021-04-19 at 15:18 +0200, Martin Liška wrote:
>> 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)
> 
> Urgh. Thanks for finding this!
> 
>> I'm not convinced about function declaration in system.h. Is it a
>> proper location?
> 
> Yes, I think it is.
> 
>> 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?
> 
> I think they both can simply include system.h (might want to double
> check the -I search path in debuginfod/Makefile.am) because system.h
> should be stand-alone, you don't need to link to anything else.
> 
> Maybe for debuginfod.cxx there is a better C++ way for strings. But if
> it uses C strings, then it could also simply include system.h.

std::basic_string_view::starts_with is only C++20, so I'd suggest 
wrapping `startswith` to not have to type `.c_str()` all the time, but 
nothing beyond that.

> 
> Thanks,
> 
> Mark
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] RFC: come up with startswith function.
  2021-04-20 11:43 ` Mark Wielaard
  2021-04-20 11:50   ` Érico Nogueira
@ 2021-04-21  7:13   ` Martin Liška
  2021-04-30 22:13     ` Mark Wielaard
  1 sibling, 1 reply; 8+ messages in thread
From: Martin Liška @ 2021-04-21  7:13 UTC (permalink / raw)
  To: Mark Wielaard, elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 2571 bytes --]

On 4/20/21 1:43 PM, Mark Wielaard wrote:
> Hi Martin,
> 
> On Mon, 2021-04-19 at 15:18 +0200, Martin Liška wrote:
>> 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)
> 
> Urgh. Thanks for finding this!
> 
>> I'm not convinced about function declaration in system.h. Is it a
>> proper location?
> 
> Yes, I think it is.
> 
>> 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?
> 
> I think they both can simply include system.h (might want to double
> check the -I search path in debuginfod/Makefile.am) because system.h
> should be stand-alone, you don't need to link to anything else.

All right, there was a different problem I had:

In file included from ../lib/system.h:39,

                 from debuginfod.cxx:40:

../lib/system.h: In function ‘ssize_t write_retry(int, const void*, size_t)’:

../lib/system.h:135:56: error: pointer of type ‘void *’ used in arithmetic [-Werror=pointer-arith]

  135 |       ssize_t ret = TEMP_FAILURE_RETRY (write (fd, buf + recvd, len - recvd));

      |                                                    ~~~~^~~~~~~


I fixed that in the attached patch.

> 
> Maybe for debuginfod.cxx there is a better C++ way for strings. But if
> it uses C strings, then it could also simply include system.h.

Apparently, it's not using strncmp with a string objects.

Is the patch ready to be installed?
Thanks,
Martin

> 
> Thanks,
> 
> Mark
> 


[-- Attachment #2: 0001-Come-up-with-startswith-function.patch --]
[-- Type: text/x-patch, Size: 26473 bytes --]

From 4be9bec67e52ee6f011197951bb8810713be3eae Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Mon, 19 Apr 2021 14:33:36 +0200
Subject: [PATCH] Come up with startswith function.

backends/ChangeLog:

	* aarch64_symbol.c (aarch64_data_marker_symbol): Use startswith.
	* arm_symbol.c (arm_data_marker_symbol): Likewise.

debuginfod/ChangeLog:

	* debuginfod-client.c (debuginfod_query_server): Use startswith.
	(debuginfod_add_http_header): Likewise.
	* debuginfod.cxx: Likewise.

lib/ChangeLog:

	* system.h (startswith): New function.
	(pwrite_retry): Cast to char *.
	(write_retry): Likewise.
	(pread_retry): Likewise.

libasm/ChangeLog:

	* libasmP.h (asm_emit_symbol_p): Use startswith.

libdw/ChangeLog:

	* dwarf_begin_elf.c (check_section): Use startswith.

libdwfl/ChangeLog:

	* dwfl_frame.c (dwfl_attach_state): Use startswith.
	* dwfl_module_getdwarf.c (find_symtab): Likewise.
	* linux-kernel-modules.c: Likewise.
	* linux-pid-attach.c (linux_proc_pid_is_stopped): Likewise.
	(dwfl_linux_proc_attach): Likewise.
	* relocate.c (resolve_symbol): Likewise.
	(relocate_section): Likewise.

libebl/ChangeLog:

	* eblobjnotetypename.c (ebl_object_note_type_name): Use startswith.
	* eblopenbackend.c (default_debugscn_p): Likewise.

src/ChangeLog:

	* elfclassify.c (run_classify): Use startswith.
	* elfcompress.c (process_file): Likewise.
	* nm.c (show_symbols_sysv): Likewise.
	* readelf.c (print_debug): Likewise.
	(handle_notes_data): Likewise.
	(dump_data_section): Likewise.
	(print_string_section): Likewise.
	* strip.c (remove_debug_relocations): Likewise.

tests/ChangeLog:

	* dwelf_elf_e_machine_string.c (main): Use startswith.
	* dwelfgnucompressed.c (main): Likewise.
	* elfgetchdr.c (main): Likewise.
	* elfputzdata.c (main): Likewise.
	* vdsosyms.c (module_callback): Likewise.
---
 backends/aarch64_symbol.c          |  4 +++-
 backends/arm_symbol.c              |  4 +++-
 debuginfod/debuginfod-client.c     |  4 ++--
 debuginfod/debuginfod.cxx          |  9 +++++----
 lib/system.h                       | 15 ++++++++++++---
 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 +-
 24 files changed, 84 insertions(+), 59 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/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index d5e7bbdf..29b4750d 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -1018,7 +1018,7 @@ debuginfod_query_server (debuginfod_client *c,
                                                     &scheme);
                   if(ok3 == CURLE_OK && scheme)
                     {
-                      if (strncmp (scheme, "HTTP", 4) == 0)
+                      if (startswith (scheme, "HTTP"))
                         if (resp_code == 200)
                           {
                             verified_handle = msg->easy_handle;
@@ -1219,7 +1219,7 @@ int debuginfod_add_http_header (debuginfod_client *client, const char* header)
 
   /* Track if User-Agent: is being set.  If so, signal not to add the
      default one. */
-  if (strncmp (header, "User-Agent:", 11) == 0)
+  if (startswith (header, "User-Agent:"))
     client->user_agent_set_p = 1;
 
   client->headers = temp;
diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx
index 473511ea..590e8f94 100644
--- a/debuginfod/debuginfod.cxx
+++ b/debuginfod/debuginfod.cxx
@@ -37,6 +37,7 @@ extern "C" {
 
 #include "debuginfod.h"
 #include <dwarf.h>
+#include <system.h>
 
 #include <argp.h>
 #ifdef __GNUC__
@@ -2267,15 +2268,15 @@ elf_classify (int fd, bool &executable_p, bool &debuginfo_p, string &buildid, se
           const char *section_name = elf_strptr (elf, shstrndx, shdr->sh_name);
           if (section_name == NULL)
             break;
-          if (strncmp(section_name, ".debug_line", 11) == 0 ||
-              strncmp(section_name, ".zdebug_line", 12) == 0)
+          if (startswith (section_name, ".debug_line") ||
+              startswith (section_name, ".zdebug_line"))
             {
               debuginfo_p = true;
               dwarf_extract_source_paths (elf, debug_sourcefiles);
               break; // expecting only one .*debug_line, so no need to look for others
             }
-          else if (strncmp(section_name, ".debug_", 7) == 0 ||
-                   strncmp(section_name, ".zdebug_", 8) == 0)
+          else if (startswith (section_name, ".debug_") ||
+                   startswith (section_name, ".zdebug_"))
             {
               debuginfo_p = true;
               // NB: don't break; need to parse .debug_line for sources
diff --git a/lib/system.h b/lib/system.h
index 1c478e1c..cdf18ed7 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), '|');			      \
@@ -104,7 +113,7 @@ pwrite_retry (int fd, const void *buf, size_t len, off_t off)
 
   do
     {
-      ssize_t ret = TEMP_FAILURE_RETRY (pwrite (fd, buf + recvd, len - recvd,
+      ssize_t ret = TEMP_FAILURE_RETRY (pwrite (fd, ((char *)buf) + recvd, len - recvd,
 						off + recvd));
       if (ret <= 0)
 	return ret < 0 ? ret : recvd;
@@ -123,7 +132,7 @@ write_retry (int fd, const void *buf, size_t len)
 
   do
     {
-      ssize_t ret = TEMP_FAILURE_RETRY (write (fd, buf + recvd, len - recvd));
+      ssize_t ret = TEMP_FAILURE_RETRY (write (fd, ((char *)buf) + recvd, len - recvd));
       if (ret <= 0)
 	return ret < 0 ? ret : recvd;
 
@@ -141,7 +150,7 @@ pread_retry (int fd, void *buf, size_t len, off_t off)
 
   do
     {
-      ssize_t ret = TEMP_FAILURE_RETRY (pread (fd, buf + recvd, len - recvd,
+      ssize_t ret = TEMP_FAILURE_RETRY (pread (fd, ((char *)buf) + recvd, len - recvd,
 					       off + recvd));
       if (ret <= 0)
 	return ret < 0 ? ret : recvd;
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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] RFC: come up with startswith function.
  2021-04-21  7:13   ` Martin Liška
@ 2021-04-30 22:13     ` Mark Wielaard
  2021-05-10 13:26       ` Martin Liška
  0 siblings, 1 reply; 8+ messages in thread
From: Mark Wielaard @ 2021-04-30 22:13 UTC (permalink / raw)
  To: Martin Liška, elfutils-devel

Hi Martin,

On Wed, 2021-04-21 at 09:13 +0200, Martin Liška wrote:
> Is the patch ready to be installed?

Yes, it is. It looks good and makes the code simpler to read.
Is it OK to add your Signed-off-by before I push it?
See 
https://sourceware.org/git/?p=elfutils.git;a=blob_plain;f=CONTRIBUTING;hb=HEAD

Thanks,

Mark

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] RFC: come up with startswith function.
  2021-04-30 22:13     ` Mark Wielaard
@ 2021-05-10 13:26       ` Martin Liška
  2021-05-12 10:01         ` Mark Wielaard
  0 siblings, 1 reply; 8+ messages in thread
From: Martin Liška @ 2021-05-10 13:26 UTC (permalink / raw)
  To: Mark Wielaard, elfutils-devel

On 5/1/21 12:13 AM, Mark Wielaard wrote:
> Yes, it is. It looks good and makes the code simpler to read.

Thanks.

> Is it OK to add your Signed-off-by before I push it?

Yes, please do it and push it.

Martin


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] RFC: come up with startswith function.
  2021-05-10 13:26       ` Martin Liška
@ 2021-05-12 10:01         ` Mark Wielaard
  2021-05-12 10:24           ` Martin Liška
  0 siblings, 1 reply; 8+ messages in thread
From: Mark Wielaard @ 2021-05-12 10:01 UTC (permalink / raw)
  To: Martin Liška, elfutils-devel

Hi Martin,

On Mon, 2021-05-10 at 15:26 +0200, Martin Liška wrote:
> On 5/1/21 12:13 AM, Mark Wielaard wrote:
> > Yes, it is. It looks good and makes the code simpler to read.
> 
> Thanks.
> 
> > Is it OK to add your Signed-off-by before I push it?
> 
> Yes, please do it and push it.

Pushed as:

commit adc201f81902f3015a841869756ed4b9b811fe33 (HEAD -> master)
Author: Martin Liska <mliska@suse.cz>
Date:   Mon Apr 19 14:33:36 2021 +0200

    Come up with startswith function.
    
    New function in system.h that returns true if a string has a given
    prefix, false otherwise.  Use it in place of strncmp.
    
    Signed-off-by: Martin Liška <mliska@suse.cz>

Sorry it missed the 0.184 release.

Cheers,

Mark

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] RFC: come up with startswith function.
  2021-05-12 10:01         ` Mark Wielaard
@ 2021-05-12 10:24           ` Martin Liška
  0 siblings, 0 replies; 8+ messages in thread
From: Martin Liška @ 2021-05-12 10:24 UTC (permalink / raw)
  To: Mark Wielaard, elfutils-devel

On 5/12/21 12:01 PM, Mark Wielaard wrote:
> Sorry it missed the 0.184 release.

Thanks. Don't worry, it's a NOP, nothing urgent.

Martin

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-05-12 10:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-19 13:18 [PATCH] RFC: come up with startswith function Martin Liška
2021-04-20 11:43 ` Mark Wielaard
2021-04-20 11:50   ` Érico Nogueira
2021-04-21  7:13   ` Martin Liška
2021-04-30 22:13     ` Mark Wielaard
2021-05-10 13:26       ` Martin Liška
2021-05-12 10:01         ` Mark Wielaard
2021-05-12 10:24           ` Martin Liška

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).