#include <stddef.h>
#include "internal/cryptlib.h"
+typedef int (*cmpthunk_fn)(const void *, const void *);
const void *ossl_bsearch(const void *key, const void *base, int num,
int size, int (*cmp)(const void *, const void *),
+ int (*cmp_thunk)(cmpthunk_fn real_cmp_fn, const void *, const void *),
int flags)
{
const char *base_ = base;
while (l < h) {
i = (l + h) / 2;
p = &(base_[i * size]);
- c = (*cmp)(key, p);
+ if (cmp_thunk != NULL)
+ c = cmp_thunk((cmpthunk_fn)cmp, key, (const void *)p);
+ else
+ c = cmp(key, p);
if (c < 0)
h = i;
else if (c > 0)
if (c != 0 && !(flags & OSSL_BSEARCH_VALUE_ON_NOMATCH))
p = NULL;
else if (c == 0 && (flags & OSSL_BSEARCH_FIRST_VALUE_ON_MATCH)) {
- while (i > 0 && (*cmp)(key, &(base_[(i - 1) * size])) == 0)
+ while (i > 0) {
+ if (cmp_thunk != NULL) {
+ if (cmp_thunk((cmpthunk_fn)cmp, key, (const void *)&(base_[(i - 1) * size])))
+ break;
+ } else {
+ if (cmp(key, &(base_[(i - 1) * size])))
+ break;
+ }
i--;
+ }
p = &(base_[i * size]);
}
return p;
int (*cmp)(const void *, const void *),
int flags)
{
- const char *p = ossl_bsearch(key, base, num, size, cmp, flags);
+ const char *p = ossl_bsearch(key, base, num, size, cmp, NULL, flags);
#ifdef CHARSET_EBCDIC
/*
return NULL;
return ossl_bsearch(&name_idx, list->properties, list->num_properties,
- sizeof(*list->properties), &property_idx_cmp, 0);
+ sizeof(*list->properties), &property_idx_cmp, NULL, 0);
}
OSSL_PROPERTY_TYPE ossl_property_get_type(const OSSL_PROPERTY_DEFINITION *prop)
if (pnum_matched != NULL)
ret_val_options |= OSSL_BSEARCH_FIRST_VALUE_ON_MATCH;
- r = ossl_bsearch(&data, st->data, st->num, sizeof(void *), st->comp,
+ r = ossl_bsearch(&data, st->data, st->num, sizeof(void *), st->comp, NULL,
ret_val_options);
if (pnum_matched != NULL) {
const void *ossl_bsearch(const void *key, const void *base, int num,
int size, int (*cmp)(const void *, const void *),
+ int (*cmp_thunk)(int (*real_cmp_fn)(const void *, const void *), const void *, const void *),
int flags);
char *ossl_sk_ASN1_UTF8STRING2text(STACK_OF(ASN1_UTF8STRING) *text,