safec
3.0
Safe C Library - ISO TR24731 Bounds Checking Interface
|
#include "safe_lib.h"
Functions | |
EXPORT void * | bsearch_s (const void *key, const void *base, rsize_t nmemb, rsize_t size, int(*compar)(const void *k, const void *y, void *context), void *context) |
The bsearch_s function finds an element equal to element pointed to by key in an array pointed to by base. More... | |
EXPORT void* bsearch_s | ( | const void * | key, |
const void * | base, | ||
rsize_t | nmemb, | ||
rsize_t | size, | ||
int(*)(const void *k, const void *y, void *context) | compar, | ||
void * | context | ||
) |
The bsearch_s
function finds an element equal to element pointed to by key in an array pointed to by base.
The array contains count elements of size bytes and must be partitioned with respect to key, that is, all the elements that compare less than must appear before all the elements that compare equal to, and those must appear before all the elements that compare greater than the key object. A fully sorted array satisfies these requirements. The elements are compared using function pointed to by comp. The behavior is undefined if the array is not already partitioned with respect to *key in ascending order according to the same criterion that compar uses.
[in] | key | pointer to the element to search for |
[in] | base | pointer to the array to examine |
[in] | nmemb | number of elements in the array |
[in] | size | size of each element in the array in bytes |
[in] | compar | comparison function which returns a negative integer value if the first argument is less than the second, a positive integer value if the first argument is greater than the second and zero if the arguments are equal. key is passed as the first argument, an element from the array as the second. The signature of the comparison function should be equivalent to the following: int cmp(const void *a, const void *b); The function must not modify the objects passed to it and must return consistent results when called for the same objects, regardless of their positions in the array. |
[in] | context | additional information (e.g., collating sequence), passed to compar as the third argument |
If the array contains several elements that compar would indicate as equal to the element searched for, then it is unspecified which element the function will return as the result.
NULL | when not found or any error |
errno values: ESNULLP when key, base or compar are a NULL pointer, and nmemb is > 0 ESLEMAX when nmemb or size > RSIZE_MAX_MEM