Merge pull request #23991 from friendly-bits/master-geoip-shell
[feed/packages.git] / utils / rtty / 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 16:06:15 +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/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);
14 | ^~~~~~~~
15 ````
16
17 basename() modifies the input string, copy it first with strdup(), If
18 strdup() returns NULL the code will handle it.
19
20 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
21 ---
22 src/file.c | 8 +++++++-
23 src/filectl.c | 6 +++++-
24 2 files changed, 12 insertions(+), 2 deletions(-)
25
26 --- a/src/file.c
27 +++ b/src/file.c
28 @@ -29,6 +29,7 @@
29 #include <unistd.h>
30 #include <mntent.h>
31 #include <inttypes.h>
32 +#include <libgen.h>
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
37 {
38 struct tty *tty = container_of(ctx, struct tty, file);
39 struct rtty *rtty = tty->rtty;
40 - const char *name = basename(path);
41 + const char *name;
42 struct stat st;
43 int fd;
44 + char *dirc;
45
46 + dirc = strdup(path);
47 + name = basename(dirc);
48 fd = open(path, O_RDONLY);
49 if (fd < 0) {
50 log_err("open '%s' fail: %s\n", path, strerror(errno));
51 + free(dirc);
52 return -1;
53 }
54
55 @@ -177,6 +182,7 @@ static int start_upload_file(struct file
56 ctx->remain_size = st.st_size;
57
58 log_info("upload file: %s, size: %" PRIu64 "\n", path, (uint64_t)st.st_size);
59 + free(dirc);
60
61 return 0;
62 }
63 --- a/src/filectl.c
64 +++ b/src/filectl.c
65 @@ -30,6 +30,7 @@
66 #include <errno.h>
67 #include <stdio.h>
68 #include <fcntl.h>
69 +#include <libgen.h>
70
71 #include "utils.h"
72 #include "file.h"
73 @@ -75,6 +76,7 @@ static void handle_file_control_msg(int
74 {
75 struct file_control_msg msg;
76 struct buffer b = {};
77 + char *dirc;
78
79 while (true) {
80 if (buffer_put_fd(&b, fd, -1, NULL) < 0)
81 @@ -90,7 +92,9 @@ static void handle_file_control_msg(int
82 if (sfd > -1) {
83 close(sfd);
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));
88 + free(dirc);
89
90 if (total_size == 0) {
91 printf(" 100%% 0 B 0s\n");