1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sun, 14 Apr 2024 16:06:15 +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/rtty-mbedtls/rtty-8.1.1/src/file.c:156:24: error: implicit declaration of function 'basename' [-Werror=implicit-function-declaration]
13 156 | const char *name = basename(path);
17 basename() modifies the input string, copy it first with strdup(), If
18 strdup() returns NULL the code will handle it.
20 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
22 src/file.c | 8 +++++++-
23 src/filectl.c | 6 +++++-
24 2 files changed, 12 insertions(+), 2 deletions(-)
33 #include <sys/statvfs.h>
34 #include <linux/limits.h>
35 #include <sys/sysinfo.h>
36 @@ -153,13 +154,17 @@ static int start_upload_file(struct file
38 struct tty *tty = container_of(ctx, struct tty, file);
39 struct rtty *rtty = tty->rtty;
40 - const char *name = basename(path);
46 + dirc = strdup(path);
47 + name = basename(dirc);
48 fd = open(path, O_RDONLY);
50 log_err("open '%s' fail: %s\n", path, strerror(errno));
55 @@ -177,6 +182,7 @@ static int start_upload_file(struct file
56 ctx->remain_size = st.st_size;
58 log_info("upload file: %s, size: %" PRIu64 "\n", path, (uint64_t)st.st_size);
73 @@ -75,6 +76,7 @@ static void handle_file_control_msg(int
75 struct file_control_msg msg;
80 if (buffer_put_fd(&b, fd, -1, NULL) < 0)
81 @@ -90,7 +92,9 @@ static void handle_file_control_msg(int
84 gettimeofday(&start_time, NULL);
85 - printf("Transferring '%s'...Press Ctrl+C to cancel\n", basename(path));
86 + dirc = strdup(path);
87 + printf("Transferring '%s'...Press Ctrl+C to cancel\n", basename(dirc));
90 if (total_size == 0) {
91 printf(" 100%% 0 B 0s\n");