diff mbox series

[1/1] xfsdump: Mimic GNU basename() API for non-glibc library e.g. musl

Message ID 20240903064014.176173-1-brahmajit.xyz@gmail.com (mailing list archive)
State Not Applicable, archived
Headers show
Series [1/1] xfsdump: Mimic GNU basename() API for non-glibc library e.g. musl | expand

Commit Message

Brahmajit Das Sept. 3, 2024, 6:39 a.m. UTC
musl only provides POSIX version of basename and it has also removed
providing it via string.h header [1] which now results in compile errors
with newer compilers e.g. clang-18

[1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7

Please also reffer: https://bugs.gentoo.org/937495

Signed-off-by: Brahmajit Das <brahmajit.xyz@gmail.com>
---
 common/main.c    | 3 +++
 invutil/invidx.c | 4 ++++
 2 files changed, 7 insertions(+)

Comments

Christoph Hellwig Sept. 10, 2024, 8:04 a.m. UTC | #1
On Tue, Sep 03, 2024 at 06:39:18AM +0000, Brahmajit Das wrote:
> +#if !defined(__GLIBC__)
> +#define basename(src) (strrchr(src, '/') ? strrchr(src, '/') + 1 : src)
> +#endif

A hacky macro without any explanation is really not a good idea.
Now this basically open codes the glibc implementation of basename,
so maybe just turn it into a proper function always used and write
a comment explaining why it exists.
diff mbox series

Patch

diff --git a/common/main.c b/common/main.c
index 6141ffb..107d335 100644
--- a/common/main.c
+++ b/common/main.c
@@ -77,6 +77,9 @@ 
 #define MINSTACKSZ	0x02000000
 #define MAXSTACKSZ	0x08000000
 
+#if !defined(__GLIBC__)
+#define basename(src) (strrchr(src, '/') ? strrchr(src, '/') + 1 : src)
+#endif
 
 /* declarations of externally defined global symbols *************************/
 
diff --git a/invutil/invidx.c b/invutil/invidx.c
index 5874e8d..942f16f 100644
--- a/invutil/invidx.c
+++ b/invutil/invidx.c
@@ -41,6 +41,10 @@ 
 #include "stobj.h"
 #include "timeutil.h"
 
+#if !defined(__GLIBC__)
+#define basename(src) (strrchr(src, '/') ? strrchr(src, '/') + 1 : src)
+#endif
+
 invidx_fileinfo_t *invidx_file;
 int invidx_numfiles;