mesh: Move local basename into utility file
authorKhem Raj <raj.khem@gmail.com>
Tue, 17 Sep 2024 03:17:45 +0000 (20:17 -0700)
committerWootak Jung <wootak.jung@samsung.com>
Thu, 20 Feb 2025 07:43:23 +0000 (16:43 +0900)
Defining an override via a missing.h can prove difficult when a file
needs to use basename and dirname both the APIs and needs to include
libgen.h for them, in such situations there will be signature clash
for basename function.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Makefile.mesh
mesh/mesh-config-json.c
mesh/missing.h [deleted file]
mesh/rpl.c
mesh/util.c
mesh/util.h

index f95cb2a51f86fc0b2b303969d5c3db476da3337e..f67f883b5421627a6ed32384b59998b704f5bbec 100644 (file)
@@ -37,7 +37,7 @@ mesh_sources = mesh/mesh.h mesh/mesh.c \
                                mesh/keyring.h mesh/keyring.c \
                                mesh/rpl.h mesh/rpl.c \
                                mesh/prv-beacon.h mesh/prvbeac-server.c \
-                               mesh/mesh-defs.h mesh/missing.h
+                               mesh/mesh-defs.h
 libexec_PROGRAMS += mesh/bluetooth-meshd
 
 mesh/mesh.$(OBJEXT): ell/internal
index 857e65988cc184909db727e9ce116228acc3916b..de0636263e73b33dc710aec7470f154d17bf5d2f 100644 (file)
@@ -29,7 +29,6 @@
 #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"
@@ -2709,7 +2708,7 @@ void mesh_config_destroy_nvm(struct mesh_config *cfg)
        if (!hex2str(cfg->uuid, 16, uuid, sizeof(uuid)))
                return;
 
-       node_name = basename(node_dir);
+       node_name = mesh_basename(node_dir);
 
        /* Make sure path name of node follows expected guidelines */
        if (strcmp(node_name, uuid))
diff --git a/mesh/missing.h b/mesh/missing.h
deleted file mode 100644 (file)
index 464df9b..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-// 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 0148bd72c92e64aba1918fb4ff9fc99dc2a89789..e6197063a18488149e633e9d99ab942caf8400e1 100644 (file)
@@ -27,7 +27,6 @@
 
 #include <ell/ell.h>
 
-#include "mesh/missing.h"
 #include "mesh/mesh-defs.h"
 
 #include "mesh/node.h"
@@ -150,7 +149,7 @@ static void get_entries(const char *iv_path, struct l_queue *rpl_list)
        if (!dir)
                return;
 
-       iv_txt = basename(iv_path);
+       iv_txt = mesh_basename(iv_path);
        if (sscanf(iv_txt, "%08x", &iv_index) != 1) {
                closedir(dir);
                return;
index 37c031aa0751cb78b34deb40e3e93ce8fac951a3..a3a28360a58cd5459eee86116b8036431d3dfe03 100644 (file)
@@ -160,3 +160,13 @@ void enable_debug(void)
        debug_enabled = true;
        l_debug_enable("*");
 }
+
+#if !HAVE_DECL_BASENAME
+#include <string.h>
+const char *mesh_basename(const char *path)
+{
+       const char *base = strrchr(path, '/');
+
+       return base ? base + 1 : path;
+}
+#endif
index 085ec333097d18aa7350145b9340ebeae1ac0d9a..bb417dc40f16e544a58d75d57ab3040761363887 100644 (file)
@@ -16,3 +16,8 @@ void print_packet(const char *label, const void *data, uint16_t size);
 int create_dir(const char *dir_name);
 void del_path(const char *path);
 void enable_debug(void);
+#if !HAVE_DECL_BASENAME
+const char *mesh_basename(const char *path);
+#else
+#define mesh_basename basename
+#endif