portability: implement skeleton with memrchr function

cute-signatures
Ariadne Conill 2021-12-14 13:49:15 -06:00 committed by Timo Teräs
parent 9ed4785f1c
commit a7a0c0a6ca
5 changed files with 60 additions and 1 deletions

View File

@ -33,6 +33,7 @@ add_project_arguments('-D_FILE_OFFSET_BITS=64', language: 'c')
subproject = meson.is_subproject()
subdir('doc')
subdir('portability')
subdir('libfetch')
subdir('src')
subdir('tests')

9
portability/memrchr.c Normal file
View File

@ -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;
}

35
portability/meson.build Normal file
View File

@ -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) + '>', args: ['-D_GNU_SOURCE']) or not cc.has_header_symbol(f.get(3), f.get(0), args: ['-D_GNU_SOURCE'])
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

5
portability/string.h Normal file
View File

@ -0,0 +1,5 @@
#include_next <string.h>
#ifdef NEED_MEMRCHR
extern void *memrchr(const void *m, int c, size_t n);
#endif

View File

@ -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'],
@ -158,7 +160,12 @@ if(lua_dep.found())
libluaapk = library(
'luaapk',
luaapk_src,
dependencies: [lua_dep, libapk_dep, shared_deps],
dependencies: [
lua_dep,
libapk_dep,
shared_deps,
libportability_dep.partial_dependency(includes: true),
],
install: true,
install_dir: lua_dep.get_pkgconfig_variable('libdir'),
c_args: apk_cargs,
@ -173,6 +180,7 @@ apk_exe = executable(
libapk_dep,
shared_deps,
libfetch_dep.partial_dependency(includes: true),
libportability_dep.partial_dependency(includes: true),
],
c_args: apk_cargs,
)
@ -185,6 +193,7 @@ if get_option('static_apk')
dependencies: [
static_deps,
libfetch_dep.partial_dependency(includes: true),
libportability_dep.partial_dependency(includes: true),
],
link_with: libapk_static,
c_args: [apk_cargs, '-DOPENSSL_NO_ENGINE'],