[dm-devel] [PATCH 3/5] libmultipath: always use glibc basename()

mwilck at suse.com mwilck at suse.com
Tue Oct 27 22:45:34 UTC 2020


From: Martin Wilck <mwilck at suse.com>

Our code relies on the non-destructive behavior of glibc's basename().
Fortunately that function is very simple, and our unit test makes
it easy to verify its functionality.

Signed-off-by: Martin Wilck <mwilck at suse.com>
---
 libmultipath/util.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/libmultipath/util.c b/libmultipath/util.c
index 39ccace..1748eaf 100644
--- a/libmultipath/util.c
+++ b/libmultipath/util.c
@@ -34,6 +34,19 @@ strchop(char *str)
 	return i;
 }
 
+#ifndef __GLIBC__
+/*
+ * glibc's non-destructive version of basename()
+ * License: LGPL-2.1-or-later
+ */
+static const char *__basename(const char *filename)
+{
+	char *p = strrchr(filename, '/');
+	return p ? p + 1 : filename;
+}
+#define basename(x) __basename(x)
+#endif
+
 int
 basenamecpy (const char *src, char *dst, size_t size)
 {
-- 
2.29.0





More information about the dm-devel mailing list