Guardian Native C Library Calls Reference Manual (G06.28+, H06.05+)

lsearch(3) Guardian Native C Library Calls Reference Manual
NAME
lsearch - Performs a linear search and update
LIBRARY
G-series native Guardian processes: $SYSTEM.SYSnn.ZCRTLSRL
G-series native OSS processes: /G/system/sysnn/zcrtlsrl
H-series native Guardian processes: $SYSTEM.ZDLLnnn.ZCRTLDLL
H-series OSS processes: /G/system/zdllnnn/zcrtldll
SYNOPSIS
#include <search.h>
#include <sys/types.h>
void *lsearch(
const void *key,
void *base,
size_t *nelp,
size_t width,
int (*compar) (const void *, const void *) );
PARAMETERS
key Points to an entry containing the key that species the entry to be searched for in
the table.
base Points to the rst entry in the table to be searched.
nelp Points to an integer that species the number of entries in the table to be
searched. This integer is incremented whenever an entry is added to the table.
width Species the size of each entry, in bytes.
compar Points to the user-specied function to be used for comparing two table entries
(strcmp(), for example). This function must return 0 (zero) when called with
arguments that point to entries whose keys compare equal, and nonzero other-
wise.
DESCRIPTION
The lsearch() function performs a linear search of a table. This function returns a pointer into a
table indicating where a specied key is located in the table. When the key is not found in the
table, it is added to the end of the table. Free space must be available at the end of the table so
that other program information will not be corrupted.
NOTES
The lsearch() function is reentrant, but care should be taken to ensure that the function supplied
as argument compar is also reentrant.
The function specied for compar does not need to compare every byte; therefore, the table
entries can contain arbitrary data in addition to the values undergoing comparison.
RETURN VALUES
If an entry in the table matches the key, the lsearch() function returns a pointer to its location in
the table. Otherwise, the lsearch() function returns a pointer to the location of the newly added
table entry.
ERRORS
There are no errors dened for this function.
438 Hewlett-Packard Company 527192-007