diff mbox series

tools/hex2hcd: fix musl compatibility

Message ID 20240710123002.5639-1-rahul@sandhuservices.dev
State New
Headers show
Series tools/hex2hcd: fix musl compatibility | expand

Commit Message

Rahul Sandhu July 10, 2024, 12:30 p.m. UTC
The call to basename() relies on a GNU extension
to take a const char * vs a char *. Let's define
a trivial helper function to ensure compatibility
with musl.

Downstream gentoo bug: https://bugs.gentoo.org/926344
Fixes: #843
---
 tools/hex2hcd.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tools/hex2hcd.c b/tools/hex2hcd.c
index e6dca5a81..42c95b759 100644
--- a/tools/hex2hcd.c
+++ b/tools/hex2hcd.c
@@ -285,6 +285,11 @@  static void ver_parse_file(const char *pathname)
 	prev->next = ver;
 }
 
+static const char *helper_basename(const char *path) {
+  const char *base = strrchr(path, '/');
+  return base ? base + 1 : path;
+}
+
 static void ver_parse_entry(const char *pathname)
 {
 	struct stat st;
@@ -302,7 +307,7 @@  static void ver_parse_entry(const char *pathname)
 	}
 
 	if (S_ISREG(st.st_mode)) {
-		ver_parse_file(basename(pathname));
+		ver_parse_file(helper_basename(pathname));
 		goto done;
 	}