2018-10-02 21:42:02 +08:00
|
|
|
/*****************************************************************************
|
|
|
|
* lfind.c : implement lfind
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void *lfind(const void *key, const void *base, size_t *nmemb,
|
|
|
|
size_t size, int(*cmp)(const void *, const void *))
|
|
|
|
{
|
2020-02-19 07:24:13 +08:00
|
|
|
for (size_t i = 0; i < *nmemb; ++i)
|
2018-10-02 21:42:02 +08:00
|
|
|
{
|
2020-02-19 07:24:13 +08:00
|
|
|
const void *elem = (const char*)base + i * size;
|
2018-10-02 21:42:02 +08:00
|
|
|
if (!cmp(key, elem))
|
2020-02-19 07:24:13 +08:00
|
|
|
return (void*)elem;
|
2018-10-02 21:42:02 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|