mesh: Provide GNU basename compatible implementation
authorKhem Raj <raj.khem@gmail.com>
Wed, 28 Aug 2024 06:09:26 +0000 (23:09 -0700)
committerWootak Jung <wootak.jung@samsung.com>
Thu, 20 Feb 2025 07:43:22 +0000 (16:43 +0900)
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.

Fixes: https://github.com/bluez/bluez/issues/843
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
configure.ac
mesh/mesh-config-json.c
mesh/missing.h [new file with mode: 0644]
mesh/rpl.c
tools/hex2hcd.c
tools/missing.h [new file with mode: 0644]

index 8eaec3b50e5f4fbff7d0107926e67553121b60ec..07bc69b254a50e506413af21828996389d260002 100755 (executable)
@@ -71,7 +71,16 @@ AC_CHECK_LIB(pthread, pthread_create, dummy=yes,
 AC_CHECK_LIB(dl, dlopen, dummy=yes,
                        AC_MSG_ERROR(dynamic linking loader is required))
 
-AC_CHECK_HEADERS(linux/types.h linux/if_alg.h linux/uinput.h linux/uhid.h sys/random.h)
+AC_CHECK_HEADERS(string.h linux/types.h linux/if_alg.h linux/uinput.h linux/uhid.h sys/random.h)
+
+# basename may be only available in libgen.h with the POSIX behavior,
+# not desired here
+AC_CHECK_DECLS([basename], [],
+                               AC_MSG_WARN([GNU basename extension not found]),
+                               [#define _GNU_SOURCE 1
+                                #include <string.h>
+                                ])
+
 
 PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.28)
 
index 9ee4dc6df63437c610a055d3ecc0a5816d9a87b8..857e65988cc184909db727e9ce116228acc3916b 100644 (file)
@@ -29,6 +29,7 @@
 #include <ell/ell.h>
 #include <json-c/json.h>
 
+#include "mesh/missing.h"
 #include "mesh/mesh-defs.h"
 #include "mesh/util.h"
 #include "mesh/mesh-config.h"
@@ -2695,7 +2696,8 @@ bool mesh_config_load_nodes(const char *cfgdir_name, mesh_config_node_func_t cb,
 
 void mesh_config_destroy_nvm(struct mesh_config *cfg)
 {
-       char *node_dir, *node_name;
+       char *node_dir;
+       const char *node_name;
        char uuid[33];
 
        if (!cfg)
diff --git a/mesh/missing.h b/mesh/missing.h
new file mode 100644 (file)
index 0000000..464df9b
--- /dev/null
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2024  Khem Raj <raj.khem@gmail.com>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#if !HAVE_DECL_BASENAME
+#include <string.h>
+static inline const char *basename(const char *path)
+{
+       const char *base = strrchr(path, '/');
+
+       return base ? base + 1 : path;
+}
+#endif
index 46c42a846fa6cb04841e60719296f3c87e914290..0148bd72c92e64aba1918fb4ff9fc99dc2a89789 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <ell/ell.h>
 
+#include "mesh/missing.h"
 #include "mesh/mesh-defs.h"
 
 #include "mesh/node.h"
index 0e8a56051d04069fa6df4b411d3649087b3c5569..515c8db9ffdd7cd353a26583b2a3208f0a84fd31 100755 (executable)
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <stdbool.h>
 #include <sys/stat.h>
+#include "tools/missing.h"
 
 static ssize_t process_record(int fd, const char *line, uint16_t *upper_addr)
 {
diff --git a/tools/missing.h b/tools/missing.h
new file mode 100644 (file)
index 0000000..464df9b
--- /dev/null
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2024  Khem Raj <raj.khem@gmail.com>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#if !HAVE_DECL_BASENAME
+#include <string.h>
+static inline const char *basename(const char *path)
+{
+       const char *base = strrchr(path, '/');
+
+       return base ? base + 1 : path;
+}
+#endif