libmraa: Fix compilation with musl libc 1.2.5
authorHauke Mehrtens <hauke@hauke-m.de>
Sun, 14 Apr 2024 13:43:23 +0000 (15:43 +0200)
committerRosen Penev <rosenp@gmail.com>
Sun, 21 Apr 2024 01:07:19 +0000 (18:07 -0700)
Support POSIX basename used in musl libc 1.2.5.

This backports a patch from upstream git.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
libs/libmraa/patches/001-mraa-Use-posix-basename.patch [new file with mode: 0644]

diff --git a/libs/libmraa/patches/001-mraa-Use-posix-basename.patch b/libs/libmraa/patches/001-mraa-Use-posix-basename.patch
new file mode 100644 (file)
index 0000000..97af156
--- /dev/null
@@ -0,0 +1,40 @@
+From 47c3850cddd63cebd9dc48e411963314449118f1 Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Sun, 31 Dec 2023 19:16:35 -0800
+Subject: [PATCH] mraa: Use posix basename
+
+Musl has removed the declaration from string.h [1] which exposes the
+problem especially with clang-17+ compiler where implicit function
+declaration is flagged as error. Use posix basename and make a copy of
+string to operate on to emulate GNU basename behaviour.
+
+[1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ src/mraa.c | 5 ++++-
+ 1 file changed, 4 insertions(+), 1 deletion(-)
+
+--- a/src/mraa.c
++++ b/src/mraa.c
+@@ -12,6 +12,7 @@
+ #endif
+ #include <dlfcn.h>
++#include <libgen.h>
+ #include <pwd.h>
+ #include <sched.h>
+ #include <stddef.h>
+@@ -338,9 +339,11 @@ static int
+ mraa_count_iio_devices(const char* path, const struct stat* sb, int flag, struct FTW* ftwb)
+ {
+     // we are only interested in files with specific names
+-    if (fnmatch(IIO_DEVICE_WILDCARD, basename(path), 0) == 0) {
++    char* tmp = strdup(path);
++    if (fnmatch(IIO_DEVICE_WILDCARD, basename(tmp), 0) == 0) {
+         num_iio_devices++;
+     }
++    free(tmp);
+     return 0;
+ }