Open System Services Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)
bsearch(3) OSS Library Calls Reference Manual
NAME
bsearch - Performs a binary search
LIBRARY
G-series native Guardian processes: $SYSTEM.SYSnn.ZCRTLSRL
G-series native OSS processes: /G/system/sysnn/zcrtlsrl
H-series and J-series native Guardian processes: $SYSTEM.ZDLLnnn.ZCRTLDLL
32-bit H-series and J-series OSS processes: /G/system/zdllnnn/zcrtldll
64-bit H-series and J-series OSS processes: /G/system/zdllnnn/ycrtldll
SYNOPSIS
#include <stdlib.h>
void *bsearch(
const void *key,
const void *base,
size_t nmemb,
size_t size,
int (*compar)(const void *, const void *));
PARAMETERS
key Target of search.
base Points to the initial object in the array.
nmemb Specifies the number of elements in the array.
size Specifies the byte size of each element of the array.
compar Points to the comparison function, which is called with two parameters that point
to the key object and to an array member, in that order.
DESCRIPTION
The bsearch( ) function does a binary search and returns a pointer in an array that indicates
where an object is found. The array must have been previously sorted in increasing order accord-
ing to a provided comparison function, compar.
The compar comparison function is called with two parameters that point to objects that are com-
pared during the search. This function returns an integer less than, equal to, or greater than 0
(zero) depending whether the object pointed to by the first const void * parameter is to be con-
sidered less than, equal to, or greater than the second const void * parameter.
NOTES
The bsearch( ) function is reentrant, but care should be taken to ensure that the function supplied
as argument compar is also reentrant.
RETURN VALUES
Upon successful completion, the bsearch() function returns a pointer to a matching object in the
array. A null pointer is returned when no match is found. When two or more objects compare
equally, the returned object is unspecified.
RELATED INFORMATION
Functions: qsort(3), tsearch(3).
1−58 Hewlett-Packard Company 527187-017