summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAriadne Conill <ariadne@dereferenced.org>2021-12-14 13:49:15 -0600
committerAriadne Conill <ariadne@dereferenced.org>2021-12-14 13:49:15 -0600
commit70f4ec71123a7646bf4e2141969cfdcdecfcdffa (patch)
tree28c71c3ab7df264782c67f47dcd3d7a710cbbdb4
parent4eb0aaa398317da3c043b3dc791f45c8aca1d450 (diff)
downloadapk-tools-70f4ec71123a7646bf4e2141969cfdcdecfcdffa.tar.gz
apk-tools-70f4ec71123a7646bf4e2141969cfdcdecfcdffa.tar.bz2
apk-tools-70f4ec71123a7646bf4e2141969cfdcdecfcdffa.tar.xz
apk-tools-70f4ec71123a7646bf4e2141969cfdcdecfcdffa.zip
portability: implement skeleton with memrchr function
-rw-r--r--meson.build1
-rw-r--r--portability/apk_string.h3
-rw-r--r--portability/memrchr.c9
-rw-r--r--portability/meson.build35
-rw-r--r--src/blob.c11
-rw-r--r--src/meson.build2
6 files changed, 51 insertions, 10 deletions
diff --git a/meson.build b/meson.build
index 902854e..de3e69e 100644
--- a/meson.build
+++ b/meson.build
@@ -30,6 +30,7 @@ add_project_arguments('-D_GNU_SOURCE', language: 'c')
subproject = meson.is_subproject()
subdir('doc')
+subdir('portability')
subdir('libfetch')
subdir('src')
subdir('tests')
diff --git a/portability/apk_string.h b/portability/apk_string.h
new file mode 100644
index 0000000..16054a0
--- /dev/null
+++ b/portability/apk_string.h
@@ -0,0 +1,3 @@
+#ifdef NEED_MEMRCHR
+extern void *memrchr(const void *m, int c, size_t n);
+#endif
diff --git a/portability/memrchr.c b/portability/memrchr.c
new file mode 100644
index 0000000..70547f9
--- /dev/null
+++ b/portability/memrchr.c
@@ -0,0 +1,9 @@
+#include <stddef.h>
+
+void *memrchr(const void *m, int c, size_t n)
+{
+ const unsigned char *s = m;
+ c = (unsigned char)c;
+ while (n--) if (s[n]==c) return (void *)(s+n);
+ return 0;
+}
diff --git a/portability/meson.build b/portability/meson.build
new file mode 100644
index 0000000..e3be65d
--- /dev/null
+++ b/portability/meson.build
@@ -0,0 +1,35 @@
+cc = meson.get_compiler('c')
+
+
+libportability_src = []
+
+
+check_functions = [
+ ['memrchr', 'memrchr.c', 'NEED_MEMRCHR', 'string.h'],
+]
+
+
+foreach f : check_functions
+ if not cc.has_function(f.get(0), prefix: '#include <' + f.get(3) + '>') or not cc.has_header_symbol(f.get(3), f.get(0))
+ add_project_arguments('-D' + f.get(2), language: 'c')
+ libportability_src += [f.get(1)]
+ endif
+endforeach
+
+
+if libportability_src.length() > 0
+ libportability = static_library(
+ 'portability',
+ libportability_src,
+ dependencies: static_deps,
+ )
+
+ libportability_dep = declare_dependency(
+ link_whole: libportability,
+ include_directories: include_directories('.'),
+ )
+else
+ libportability_dep = declare_dependency(
+ include_directories: include_directories('.'),
+ )
+endif
diff --git a/src/blob.c b/src/blob.c
index f5d793b..6af22d1 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -14,6 +14,7 @@
#include "apk_blob.h"
#include "apk_hash.h"
+#include "apk_string.h"
char *apk_blob_cstr(apk_blob_t blob)
{
@@ -156,16 +157,6 @@ int apk_blob_cspn(apk_blob_t blob, const apk_spn_match reject, apk_blob_t *l, ap
}
#endif
-#if defined(__APPLE__)
-void *memrchr(const void *m, int c, size_t n)
-{
- const unsigned char *s = m;
- c = (unsigned char)c;
- while (n--) if (s[n]==c) return (void *)(s+n);
- return 0;
-}
-#endif
-
int apk_blob_rsplit(apk_blob_t blob, char split, apk_blob_t *l, apk_blob_t *r)
{
char *sep;
diff --git a/src/meson.build b/src/meson.build
index 3cc4ce0..ccfdbb0 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -117,6 +117,7 @@ libapk_shared = shared_library(
install: not subproject,
dependencies: [
libfetch_dep,
+ libportability_dep,
shared_deps,
],
c_args: apk_cargs,
@@ -128,6 +129,7 @@ libapk_static = static_library(
install: not subproject,
dependencies: [
libfetch_dep,
+ libportability_dep,
static_deps,
],
c_args: [apk_cargs, '-DOPENSSL_NO_ENGINE'],