]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm.h: provide basename if GLIBC is not avialable
authorMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Tue, 21 May 2024 14:26:33 +0000 (16:26 +0200)
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Tue, 28 May 2024 15:18:54 +0000 (17:18 +0200)
If GNU basename is not avilable, define it. It is safer to use that
rather than include libgen.h with XPG basename() definition.

Fixes:#12

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
mdadm.h

diff --git a/mdadm.h b/mdadm.h
index 40818941bb16f737546763dcbc3ed7e1da7817a8..e9f764a23b1f0dc4bcaa1b7e56ec33acc9eafab5 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -223,6 +223,14 @@ struct dlm_lksb {
 struct __una_u16 { __u16 x; } __attribute__ ((packed));
 struct __una_u32 { __u32 x; } __attribute__ ((packed));
 
+/*
+ * Ensure GNU basename behavior on GLIBC less systems.
+ */
+#ifndef __GLIBC__
+#define basename(path) \
+       (strrchr((path), '/') ? strrchr((path),'/') + 1 : (path))
+#endif
+
 static inline __u16 __get_unaligned16(const void *p)
 {
        const struct __una_u16 *ptr = (const struct __una_u16 *)p;