1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sun, 14 Apr 2024 17:13:17 +0200
4 Subject: Support POSIX basename() from musl libc
6 Musl libc 1.2.5 removed the definition of the basename() function from
7 string.h and only provides it in libgen.h as the POSIX standard
10 This change fixes compilation with musl libc 1.2.5.
12 /build_dir/target-mips_24kc_musl/lua-eco-3.3.0/log/log.c: In function '___log':
13 /build_dir/target-mips_24kc_musl/lua-eco-3.3.0/log/log.c:76:24: error: implicit declaration of function 'basename' [-Werror=implicit-function-declaration]
14 76 | filename = basename(filename);
16 /build_dir/target-mips_24kc_musl/lua-eco-3.3.0/log/log.c:76:22: error: assignment to 'const char *' from 'int' makes pointer from integer without a cast [-Werror=int-conversion]
17 76 | filename = basename(filename);
21 basename() modifies the input string, copy it first with strdup(), If
22 strdup() returns NULL the code will handle it.
24 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
26 log/log.c | 10 ++++++++--
27 1 file changed, 8 insertions(+), 2 deletions(-)
39 @@ -65,6 +66,7 @@ void ___log(const char *filename, int li
45 priority = LOG_PRI(priority);
47 @@ -72,9 +74,13 @@ void ___log(const char *filename, int li
50 if (__log_flags__ & LOG_FLAG_FILE || __log_flags__ & LOG_FLAG_PATH) {
51 - if (!(__log_flags__ & LOG_FLAG_PATH))
52 - filename = basename(filename);
53 + if (!(__log_flags__ & LOG_FLAG_PATH)) {
54 + dirc = strdup(filename);
55 + filename = basename(dirc);
57 snprintf(new_fmt, sizeof(new_fmt), "(%s:%3d) %s", filename, line, fmt);
58 + if (!(__log_flags__ & LOG_FLAG_PATH))
61 snprintf(new_fmt, sizeof(new_fmt), "%s", fmt);