1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #include "alloc-util.h"
4 #include "dlfcn-util.h"
5 #include "pcre2-dlopen.h"
8 static void *pcre2_dl
= NULL
;
10 pcre2_match_data
* (*sym_pcre2_match_data_create
)(uint32_t, pcre2_general_context
*);
11 void (*sym_pcre2_match_data_free
)(pcre2_match_data
*);
12 void (*sym_pcre2_code_free
)(pcre2_code
*);
13 pcre2_code
* (*sym_pcre2_compile
)(PCRE2_SPTR
, PCRE2_SIZE
, uint32_t, int *, PCRE2_SIZE
*, pcre2_compile_context
*);
14 int (*sym_pcre2_get_error_message
)(int, PCRE2_UCHAR
*, PCRE2_SIZE
);
15 int (*sym_pcre2_match
)(const pcre2_code
*, PCRE2_SPTR
, PCRE2_SIZE
, PCRE2_SIZE
, uint32_t, pcre2_match_data
*, pcre2_match_context
*);
16 PCRE2_SIZE
* (*sym_pcre2_get_ovector_pointer
)(pcre2_match_data
*);
18 int dlopen_pcre2(void) {
19 _cleanup_(dlclosep
) void *dl
= NULL
;
23 return 0; /* Already loaded */
25 dl
= dlopen("libpcre2-8.so.0", RTLD_LAZY
);
27 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP
),
28 "PCRE2 support is not installed: %s", dlerror());
30 r
= dlsym_many_and_warn(
33 &sym_pcre2_match_data_create
, "pcre2_match_data_create_8",
34 &sym_pcre2_match_data_free
, "pcre2_match_data_free_8",
35 &sym_pcre2_code_free
, "pcre2_code_free_8",
36 &sym_pcre2_compile
, "pcre2_compile_8",
37 &sym_pcre2_get_error_message
, "pcre2_get_error_message_8",
38 &sym_pcre2_match
, "pcre2_match_8",
39 &sym_pcre2_get_ovector_pointer
, "pcre2_get_ovector_pointer_8",
44 /* Note that we never release the reference here, because there's no real reason to, after all this
45 * was traditionally a regular shared library dependency which lives forever too. */
46 pcre2_dl
= TAKE_PTR(dl
);
53 int dlopen_pcre2(void) {
54 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP
),
55 "PCRE2 support is not compiled in.");