2 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include "internal/cryptlib.h"
13 const void *ossl_bsearch(const void *key, const void *base, int num,
14 int size, int (*cmp) (const void *, const void *),
17 const char *base_ = base;
18 int l, h, i = 0, c = 0;
27 p = &(base_[i * size]);
36 if (c != 0 && !(flags & OSSL_BSEARCH_VALUE_ON_NOMATCH))
38 else if (c == 0 && (flags & OSSL_BSEARCH_FIRST_VALUE_ON_MATCH)) {
39 while (i > 0 && (*cmp) (key, &(base_[(i - 1) * size])) == 0)
41 p = &(base_[i * size]);