Re: [PATCH 1/1] bpftool: Be more portable by using POSIX's basename()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 1/29/24 3:33 PM, Arnaldo Carvalho de Melo wrote:
musl libc had the basename() prototype in string.h, but this is a
glibc-ism, now they removed the _GNU_SOURCE bits in their devel distro,
Alpine Linux edge:

   https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7

So lets use the POSIX version, the whole rationale is spelled out at:

   https://gitlab.alpinelinux.org/alpine/aports/-/issues/15643

Acked-by: Jiri Olsa <olsajiri@xxxxxxxxx>
Acked-by: Quentin Monnet <quentin@xxxxxxxxxxxxx>
Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: Andrii Nakryiko <andrii.nakryiko@xxxxxxxxx>
Cc: Ian Rogers <irogers@xxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Link: https://lore.kernel.org/lkml/ZZhsPs00TI75RdAr@xxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
  tools/bpf/bpftool/gen.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
index ee3ce2b8000d75d2..a5cc5938c3d7951e 100644
--- a/tools/bpf/bpftool/gen.c
+++ b/tools/bpf/bpftool/gen.c
@@ -7,6 +7,7 @@
  #include <ctype.h>
  #include <errno.h>
  #include <fcntl.h>
+#include <libgen.h>
  #include <linux/err.h>
  #include <stdbool.h>
  #include <stdio.h>
@@ -56,9 +57,10 @@ static bool str_has_suffix(const char *str, const char *suffix)
static void get_obj_name(char *name, const char *file)
  {
-	/* Using basename() GNU version which doesn't modify arg. */
-	strncpy(name, basename(file), MAX_OBJ_NAME_LEN - 1);
-	name[MAX_OBJ_NAME_LEN - 1] = '\0';
+	char file_copy[PATH_MAX];

Added a newline in here while applying, otherwise lgtm, thanks!

+	/* Using basename() POSIX version to be more portable. */
+	strncpy(file_copy, file, PATH_MAX - 1)[PATH_MAX - 1] = '\0';
+	strncpy(name, basename(file_copy), MAX_OBJ_NAME_LEN - 1)[MAX_OBJ_NAME_LEN - 1] = '\0';
  	if (str_has_suffix(name, ".o"))
  		name[strlen(name) - 2] = '\0';
  	sanitize_identifier(name);






[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux