dnsproxy: Update to 0.70.0
[feed/packages.git] / lang / lua-eco / patches / 0001-Support-POSIX-basename-from-musl-libc.patch
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
5
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
8 defines it.
9
10 This change fixes compilation with musl libc 1.2.5.
11 ````
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);
15 | ^~~~~~~~
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);
18 | ^
19 ````
20
21 basename() modifies the input string, copy it first with strdup(), If
22 strdup() returns NULL the code will handle it.
23
24 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
25 ---
26 log/log.c | 10 ++++++++--
27 1 file changed, 8 insertions(+), 2 deletions(-)
28
29 --- a/log/log.c
30 +++ b/log/log.c
31 @@ -9,6 +9,7 @@
32 #include <stdlib.h>
33 #include <unistd.h>
34 #include <string.h>
35 +#include <libgen.h>
36
37 #include "log.h"
38
39 @@ -65,6 +66,7 @@ void ___log(const char *filename, int li
40 {
41 char new_fmt[256];
42 va_list ap;
43 + char *dirc = NULL;
44
45 priority = LOG_PRI(priority);
46
47 @@ -72,9 +74,13 @@ void ___log(const char *filename, int li
48 return;
49
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);
56 + }
57 snprintf(new_fmt, sizeof(new_fmt), "(%s:%3d) %s", filename, line, fmt);
58 + if (!(__log_flags__ & LOG_FLAG_PATH))
59 + free(dirc);
60 } else {
61 snprintf(new_fmt, sizeof(new_fmt), "%s", fmt);
62 }