public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Yonggang Luo <luoyonggang@gmail.com>
To: elfutils-devel@sourceware.org
Cc: Yonggang Luo <luoyonggang@gmail.com>
Subject: [PATCH 09/25] include libgen.h in system.h
Date: Fri, 21 Oct 2022 02:25:48 +0800	[thread overview]
Message-ID: <20221020182603.815-10-luoyonggang@gmail.com> (raw)
In-Reply-To: <20221020182603.815-1-luoyonggang@gmail.com>

basename function are accessed multiple place, but used without include libgen.h

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 lib/system.h                         | 1 +
 libdw/dwarf_getsrc_file.c            | 2 +-
 libdwfl/dwfl_module_getsrc_file.c    | 2 +-
 libdwfl/dwfl_segment_report_module.c | 2 +-
 libdwfl/find-debuginfo.c             | 6 +++---
 libdwfl/link_map.c                   | 2 +-
 src/addr2line.c                      | 4 ++--
 src/nm.c                             | 4 ++--
 src/stack.c                          | 2 +-
 src/strip.c                          | 2 +-
 10 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/lib/system.h b/lib/system.h
index 561d3e03..7132cd6d 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -42,6 +42,7 @@
 /* System dependend headers */
 #include <byteswap.h>
 #include <endian.h>
+#include <libgen.h>
 #if HAVE_DECL_MMAP
 #include <sys/mman.h>
 #endif
diff --git a/libdw/dwarf_getsrc_file.c b/libdw/dwarf_getsrc_file.c
index 5289c7da..884fea32 100644
--- a/libdw/dwarf_getsrc_file.c
+++ b/libdw/dwarf_getsrc_file.c
@@ -98,7 +98,7 @@ dwarf_getsrc_file (Dwarf *dbg, const char *fname, int lineno, int column,
 	      /* Match the name with the name the user provided.  */
 	      const char *fname2 = line->files->info[lastfile].name;
 	      if (is_basename)
-		lastmatch = strcmp (basename (fname2), fname) == 0;
+		lastmatch = strcmp (basename ((char *)fname2), fname) == 0;
 	      else
 		lastmatch = strcmp (fname2, fname) == 0;
 	    }
diff --git a/libdwfl/dwfl_module_getsrc_file.c b/libdwfl/dwfl_module_getsrc_file.c
index cea2ba41..6daf29d6 100644
--- a/libdwfl/dwfl_module_getsrc_file.c
+++ b/libdwfl/dwfl_module_getsrc_file.c
@@ -103,7 +103,7 @@ dwfl_module_getsrc_file (Dwfl_Module *mod,
 		{
 		  /* Match the name with the name the user provided.  */
 		  lastfile = file;
-		  lastmatch = !strcmp (is_basename ? basename (file) : file,
+		  lastmatch = !strcmp (is_basename ? basename ((char *)file) : file,
 				       fname);
 		}
 	    }
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index 287fc002..aa228254 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -736,7 +736,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
 	      bias += fixup;
 	      if (module->name[0] != '\0')
 		{
-		  name = basename (module->name);
+		  name = basename ((char *)module->name);
 		  name_is_final = true;
 		}
 	      break;
diff --git a/libdwfl/find-debuginfo.c b/libdwfl/find-debuginfo.c
index 7f7ab632..a9b7be3d 100644
--- a/libdwfl/find-debuginfo.c
+++ b/libdwfl/find-debuginfo.c
@@ -164,7 +164,7 @@ find_debuginfo_in_path (Dwfl_Module *mod, const char *file_name,
 {
   bool cancheck = debuglink_crc != (GElf_Word) 0;
 
-  const char *file_basename = file_name == NULL ? NULL : basename (file_name);
+  const char *file_basename = file_name == NULL ? NULL : basename ((char *)file_name);
   char *localname = NULL;
 
   /* We invent a debuglink .debug name if NULL, but then want to try the
@@ -278,7 +278,7 @@ find_debuginfo_in_path (Dwfl_Module *mod, const char *file_name,
 	  else
 	    {
 	      subdir = NULL;
-	      file = basename (debuglink_file);
+	      file = basename ((char *)debuglink_file);
 	    }
 	  try_file_basename = debuglink_null;
 	  break;
@@ -306,7 +306,7 @@ find_debuginfo_in_path (Dwfl_Module *mod, const char *file_name,
 	    if (mod->dw != NULL && (p[0] == '\0' || p[0] == '/'))
 	      {
 		fd = try_open (&main_stat, dir, ".dwz",
-			       basename (file), &fname);
+			       basename ((char *)file), &fname);
 		if (fd < 0)
 		  {
 		    if (errno != ENOENT && errno != ENOTDIR)
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index 7ec7eca1..403d4ee5 100644
--- a/libdwfl/link_map.c
+++ b/libdwfl/link_map.c
@@ -469,7 +469,7 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
 		      if (r_debug_info_module == NULL)
 			{
 			  // XXX hook for sysroot
-			  mod = __libdwfl_report_elf (dwfl, basename (name),
+			  mod = __libdwfl_report_elf (dwfl, basename ((char *)name),
 						      name, fd, elf, base,
 						      true, true);
 			  if (mod != NULL)
diff --git a/src/addr2line.c b/src/addr2line.c
index 7768b266..3abf1d7a 100644
--- a/src/addr2line.c
+++ b/src/addr2line.c
@@ -381,7 +381,7 @@ print_dwarf_function (Dwfl_Module *mod, Dwarf_Addr addr)
 		  if (file == NULL)
 		    file = "???";
 		  else if (only_basenames)
-		    file = basename (file);
+		    file = basename ((char *)file);
 		  else if (use_comp_dir && file[0] != '/')
 		    {
 		      const char *const *dirs;
@@ -564,7 +564,7 @@ print_src (const char *src, int lineno, int linecol, Dwarf_Die *cu)
   const char *comp_dir_sep = "";
 
   if (only_basenames)
-    src = basename (src);
+    src = basename ((char *)src);
   else if (use_comp_dir && src[0] != '/')
     {
       Dwarf_Attribute attr;
diff --git a/src/nm.c b/src/nm.c
index b46c1fd7..717ec0f6 100644
--- a/src/nm.c
+++ b/src/nm.c
@@ -1417,7 +1417,7 @@ show_symbols (int fd, Ebl *ebl, GElf_Ehdr *ehdr,
 			  int lineno;
 			  (void) dwarf_lineno (line, &lineno);
 			  const char *file = dwarf_linesrc (line, NULL, NULL);
-			  file = (file != NULL) ? basename (file) : "???";
+			  file = (file != NULL) ? basename ((char *)file) : "???";
 			  int n;
 			  n = obstack_printf (&whereob, "%s:%d%c", file,
 					      lineno, '\0');
@@ -1448,7 +1448,7 @@ show_symbols (int fd, Ebl *ebl, GElf_Ehdr *ehdr,
 		{
 		  /* We found the line.  */
 		  int n = obstack_printf (&whereob, "%s:%" PRIu64 "%c",
-					  basename ((*found)->file),
+					  basename ((char *)(*found)->file),
 					  (*found)->lineno,
 					  '\0');
 		  sym_mem[nentries_used].where = obstack_finish (&whereob);
diff --git a/src/stack.c b/src/stack.c
index 534aa93c..82413772 100644
--- a/src/stack.c
+++ b/src/stack.c
@@ -152,7 +152,7 @@ module_callback (Dwfl_Module *mod, void **userdata __attribute__((unused)),
 
   int width = get_addr_width (mod);
   printf ("0x%0*" PRIx64 "-0x%0*" PRIx64 " %s\n",
-	  width, start, width, end, basename (name));
+	  width, start, width, end, basename ((char *)name));
 
   const unsigned char *id;
   GElf_Addr id_vaddr;
diff --git a/src/strip.c b/src/strip.c
index 2a2cc801..6ac987fd 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -1800,7 +1800,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
 		      elf_errmsg (-1));
 	}
 
-      char *debug_basename = basename (debug_fname_embed ?: debug_fname);
+      char *debug_basename = basename ((char *)(debug_fname_embed ?: debug_fname));
       off_t crc_offset = strlen (debug_basename) + 1;
       /* Align to 4 byte boundary */
       crc_offset = ((crc_offset - 1) & ~3) + 4;
-- 
2.36.1.windows.1


  parent reply	other threads:[~2022-10-20 18:26 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
2022-10-20 18:25 ` [PATCH 01/25] Rename 'hello2.spec.' -> 'hello2.spec' 'hello3.spec.' -> 'hello3.spec' Yonggang Luo
2022-10-27 13:02   ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 02/25] ignore build directory Yonggang Luo
2022-10-27 13:03   ` Mark Wielaard
2022-12-16 21:14     ` 罗勇刚(Yonggang Luo)
2022-12-20 12:35       ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 03/25] libebl: There is no need #include <dlfcn.h> in eblclosebackend.c and eblopenbackend.c Yonggang Luo
2022-10-27 13:09   ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 04/25] libelf/libdwfl: Remove "#define LIB_SYSTEM_H 1" in libelf_crc32.c and libdwfl_crc32.c Yonggang Luo
2022-10-27 13:20   ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 05/25] use #include <system.h> instead platform depended header <endian.h> in libdw/memory-access.h Yonggang Luo
2022-10-27 13:26   ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 06/25] move platform depended include into system.h of libebl Yonggang Luo
2022-10-28 11:35   ` Mark Wielaard
2022-12-16 21:19     ` 罗勇刚(Yonggang Luo)
2022-12-20 13:59       ` Mark Wielaard
2022-12-20 17:44         ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 07/25] move platform depended include into system.h of libasm, libcpu, libdw, libdwfl and libdwelf Yonggang Luo
2022-10-28 12:07   ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 08/25] Use configure to detect HAVE_DECL_MMAP and use it for system doesn't provide sys/mman.h Yonggang Luo
2022-10-28 11:41   ` Mark Wielaard
2022-12-16 21:21     ` 罗勇刚(Yonggang Luo)
2022-12-20 14:04       ` Mark Wielaard
2022-12-20 16:30         ` 罗勇刚(Yonggang Luo)
2022-12-21 16:54           ` Mark Wielaard
2022-12-22  3:50             ` 罗勇刚(Yonggang Luo)
2022-10-20 18:25 ` Yonggang Luo [this message]
2022-10-28 11:45   ` [PATCH 09/25] include libgen.h in system.h Mark Wielaard
2022-12-16 21:22     ` 罗勇刚(Yonggang Luo)
2022-12-16 21:34       ` 罗勇刚(Yonggang Luo)
2022-12-20 15:05       ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 10/25] libcpu: Remove the need of NMNES by using enum Yonggang Luo
2022-12-12 12:37   ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 11/25] libcpu: Use __asm instead asm that can be recognized by both clang-cl and gcc Yonggang Luo
2022-12-12 12:42   ` Mark Wielaard
2022-12-16 21:36     ` 罗勇刚(Yonggang Luo)
2022-10-20 18:25 ` [PATCH 12/25] libcpu: Use "#define FCT_mod$64r_m FCT_mod$r_m" is enough and can be recognized by clang-cl on windows in i386_data.h Yonggang Luo
2022-12-12 12:58   ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 13/25] libdw: typeof -> __typeof that can be recognized by both clang-cl and gcc Yonggang Luo
2022-12-12 13:12   ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 14/25] libdw: check __OPTIMIZE__ in dwarf_whatattr.c and dwarf_whatform.c to match the header Yonggang Luo
2022-12-12 13:31   ` Mark Wielaard
2022-12-16 21:47     ` 罗勇刚(Yonggang Luo)
2022-12-20 15:08       ` Mark Wielaard
2022-12-20 16:31         ` 罗勇刚(Yonggang Luo)
2022-10-20 18:25 ` [PATCH 15/25] lib: Implement error properly even when not HAVE_ERR_H Yonggang Luo
2022-12-12 15:37   ` Mark Wielaard
2022-12-16 21:50     ` 罗勇刚(Yonggang Luo)
2022-12-20 15:10       ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 16/25] libeu: Move the implementation of pwrite_retry, write_retry and pread_retry from header to source Yonggang Luo
2022-12-12 15:45   ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 17/25] libelf: uid_t, gid_t and mode_t are not comes with msvcrt, so using long/unsigned long instead on win32 Yonggang Luo
2022-10-20 18:25 ` [PATCH 18/25] lib: Use NOT_HAVE_LIBINTL to guard #include <libintl.h> Yonggang Luo
2022-10-20 18:25 ` [PATCH 19/25] libelf: F_GETFD may not predefined with msvc/mingw, guard the usage of it Yonggang Luo
2022-12-12 15:54   ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 20/25] Add function sys_get_page_size to replace platform dependent sysconf (_SC_PAGESIZE) Yonggang Luo
2022-10-20 18:26 ` [PATCH 21/25] libasm: stdio_ext.h are not present on win32 Yonggang Luo
2022-10-20 18:26 ` [PATCH 22/25] libebl/libdwelf: define ssize_t and pid_t for MSVC within installed header libdwelf.h and libebl.h Yonggang Luo
2022-10-20 18:26 ` [PATCH 23/25] libasm/debuginfod: fchmod doesn't present on win32 Yonggang Luo
2022-10-20 18:26 ` [PATCH 24/25] lib: isatty is not available on windows Yonggang Luo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221020182603.815-10-luoyonggang@gmail.com \
    --to=luoyonggang@gmail.com \
    --cc=elfutils-devel@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).