diff mbox series

[1/6] opkg: Use own version of portable basename function

Message ID 20231210202549.155550-1-raj.khem@gmail.com
State Accepted, archived
Commit f76d44192919c0b9a2f66ba93190322fe5bcb3ed
Headers show
Series [1/6] opkg: Use own version of portable basename function | expand

Commit Message

Khem Raj Dec. 10, 2023, 8:25 p.m. UTC
Fixes build with upcoming musl release.

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 ...Provide-basename-function-as-utility.patch | 131 ++++++++++++++++++
 meta/recipes-devtools/opkg/opkg_0.6.2.bb      |   1 +
 2 files changed, 132 insertions(+)
 create mode 100644 meta/recipes-devtools/opkg/opkg/0001-libopkg-Provide-basename-function-as-utility.patch
diff mbox series

Patch

diff --git a/meta/recipes-devtools/opkg/opkg/0001-libopkg-Provide-basename-function-as-utility.patch b/meta/recipes-devtools/opkg/opkg/0001-libopkg-Provide-basename-function-as-utility.patch
new file mode 100644
index 00000000000..91b00bb4085
--- /dev/null
+++ b/meta/recipes-devtools/opkg/opkg/0001-libopkg-Provide-basename-function-as-utility.patch
@@ -0,0 +1,131 @@ 
+From c3770c1254a288f1312a66ebf4a5da60a1ae215b Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Sat, 9 Dec 2023 17:07:22 -0800
+Subject: [PATCH] libopkg: Provide basename function as utility
+
+glibc provides two implementations one when string.h is used and Posix
+compliant one from libgen.h when string.h is not included. Lets
+implement gnu compliant version using strchr and use it Everywhere for
+portability reasons. This will help compiling with next release of musl
+where signature is removed from strin.h [1]
+
+[1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7
+
+Upstream-Status: Submitted [https://lists.yoctoproject.org/g/opkg/message/11]
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ libopkg/opkg_archive.c  | 2 +-
+ libopkg/opkg_download.c | 6 ++----
+ libopkg/opkg_remove.c   | 2 +-
+ libopkg/pkg.c           | 4 +---
+ libopkg/xfuncs.c        | 6 ++++++
+ libopkg/xfuncs.h        | 1 +
+ 6 files changed, 12 insertions(+), 9 deletions(-)
+
+diff --git a/libopkg/opkg_archive.c b/libopkg/opkg_archive.c
+index 03a4afb..da37d8a 100644
+--- a/libopkg/opkg_archive.c
++++ b/libopkg/opkg_archive.c
+@@ -797,7 +797,7 @@ int gz_write_archive(const char *filename, const char *gz_filename)
+     }
+ 
+     /* Remove path hierarchy, as we are only compressing a single file */
+-    archive_entry_set_pathname(entry, basename(filename));
++    archive_entry_set_pathname(entry, xbasename(filename));
+ 
+     r = archive_write_header(a, entry);
+     if (r != ARCHIVE_OK) {
+diff --git a/libopkg/opkg_download.c b/libopkg/opkg_download.c
+index 4086f83..130a8c1 100644
+--- a/libopkg/opkg_download.c
++++ b/libopkg/opkg_download.c
+@@ -158,7 +158,6 @@ static char *get_cache_location(const char *src)
+     char *md5sum_hex;
+     char *cache_location;
+     char *short_file_name;
+-    char *tmp = xstrdup(src);
+ 
+     md5_buffer(src, strlen(src), md5sum_bin);
+     md5sum_hex = md5_to_string(md5sum_bin);
+@@ -168,14 +167,13 @@ static char *get_cache_location(const char *src)
+      * MAX_SHORT_FILE_NAME_LENGTH to ensure that the total cache file name
+      * length is reasonable.
+      */
+-    short_file_name = basename(tmp);
++    short_file_name = xbasename(src);
+     if (strlen(short_file_name) > MAX_SHORT_FILE_NAME_LENGTH)
+         short_file_name[MAX_SHORT_FILE_NAME_LENGTH] = '\0';
+ 
+     sprintf_alloc(&cache_location, "%s/%s_%s", opkg_config->cache_dir,
+                   md5sum_hex, short_file_name);
+     free(md5sum_hex);
+-    free(tmp);
+     return cache_location;
+ }
+ 
+@@ -361,7 +359,7 @@ int opkg_download_pkg_to_dir(pkg_t * pkg, const char *dir)
+     char *url = NULL;
+     int err = 0;
+ 
+-    sprintf_alloc(&dest_file_name, "%s/%s", dir, basename(pkg->filename));
++    sprintf_alloc(&dest_file_name, "%s/%s", dir, xbasename(pkg->filename));
+ 
+     if (opkg_config->volatile_cache) {
+         url = get_pkg_url(pkg);
+diff --git a/libopkg/opkg_remove.c b/libopkg/opkg_remove.c
+index 889c672..e9d5714 100644
+--- a/libopkg/opkg_remove.c
++++ b/libopkg/opkg_remove.c
+@@ -215,7 +215,7 @@ void remove_maintainer_scripts(pkg_t * pkg)
+         return;
+ 
+     for (i = 0; i < globbuf.gl_pathc; i++) {
+-        filename = xstrdup(basename(globbuf.gl_pathv[i]));
++        filename = xstrdup(xbasename(globbuf.gl_pathv[i]));
+         lastdot = strrchr(filename, '.');
+         *lastdot = '\0';
+         // Only delete files that match the package name (the glob may match files
+diff --git a/libopkg/pkg.c b/libopkg/pkg.c
+index 6b1bd8f..3d13fed 100644
+--- a/libopkg/pkg.c
++++ b/libopkg/pkg.c
+@@ -271,10 +271,8 @@ int pkg_init_from_file(pkg_t * pkg, const char *filename)
+ 
+     pkg->local_filename = xstrdup(filename);
+ 
+-    tmp = xstrdup(filename);
+     sprintf_alloc(&control_path, "%s/%s.control.XXXXXX", opkg_config->tmp_dir,
+-                  basename(tmp));
+-    free(tmp);
++                  xbasename(filename));
+     fd = mkstemp(control_path);
+     if (fd == -1) {
+         opkg_perror(ERROR, "Failed to make temp file %s", control_path);
+diff --git a/libopkg/xfuncs.c b/libopkg/xfuncs.c
+index 9ee1a7d..11e3d92 100644
+--- a/libopkg/xfuncs.c
++++ b/libopkg/xfuncs.c
+@@ -110,3 +110,9 @@ extern char *xdirname(const char *path)
+     free(pathcopy);
+     return parent;
+ }
++/* implement Glibc basename behavior */
++const char *xbasename(const char *path)
++{
++    const char *tmp = strrchr(path, '/');
++    return tmp ? tmp+1 : path;
++}
+diff --git a/libopkg/xfuncs.h b/libopkg/xfuncs.h
+index 5d278b4..0d4ef32 100644
+--- a/libopkg/xfuncs.h
++++ b/libopkg/xfuncs.h
+@@ -30,5 +30,6 @@ extern void *xcalloc(size_t nmemb, size_t size);
+ extern char *xstrdup(const char *s);
+ extern char *xstrndup(const char *s, int n);
+ extern char *xdirname(const char *path);
++extern const char *xbasename(const char *path);
+ 
+ #endif                          /* XFUNCS_H */
+-- 
+2.43.0
+
diff --git a/meta/recipes-devtools/opkg/opkg_0.6.2.bb b/meta/recipes-devtools/opkg/opkg_0.6.2.bb
index 46be137354c..02f4a46561e 100644
--- a/meta/recipes-devtools/opkg/opkg_0.6.2.bb
+++ b/meta/recipes-devtools/opkg/opkg_0.6.2.bb
@@ -15,6 +15,7 @@  PE = "1"
 SRC_URI = "http://downloads.yoctoproject.org/releases/${BPN}/${BPN}-${PV}.tar.gz \
            file://opkg.conf \
            file://0001-opkg_conf-create-opkg.lock-in-run-instead-of-var-run.patch \
+           file://0001-libopkg-Provide-basename-function-as-utility.patch \
            file://run-ptest \
            "