Skip to content

Commit 1a0b588

Browse files
committed
libled: provide basename if GLIBC is not avialable
If GNU basename is not avilable, define it. It is safer to use that rather than include libgen.h with XPG basename() definition. Suggested in https://github.com/md-raid-utilities/ledmon/pull/ 272#issuecomment-3596495739 Code copied from md-raid-utilities/mdadm@9dbd11e Signed-off-by: Bernd Kuhls <[email protected]>
1 parent 510f9d0 commit 1a0b588

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/lib/libled_internal.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,13 @@ led_status_t device_exclude_pattern_add(struct led_ctx *ctx, const char *path);
7070
*/
7171
void lib_log(struct led_ctx *ctx, enum led_log_level_enum loglevel, const char *buf, ...)
7272
__attribute__ ((format (printf, 3, 4)));
73+
74+
/*
75+
* Ensure GNU basename behavior on GLIBC less systems.
76+
*/
77+
#ifndef __GLIBC__
78+
#define basename(path) \
79+
(strrchr((path), '/') ? strrchr((path), '/') + 1 : (path))
80+
#endif
81+
7382
#endif

0 commit comments

Comments
 (0)