mirror of https://git.musl-libc.org/git/musl
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
609 B
31 lines
609 B
#include <search.h>
|
|
#include <string.h>
|
|
|
|
void *lsearch(const void *key, void *base, size_t *nelp, size_t width,
|
|
int (*compar)(const void *, const void *))
|
|
{
|
|
char (*p)[width] = base;
|
|
size_t n = *nelp;
|
|
size_t i;
|
|
|
|
for (i = 0; i < n; i++)
|
|
if (compar(p[i], key) == 0)
|
|
return p[i];
|
|
*nelp = n+1;
|
|
return memcpy(p[n], key, width);
|
|
}
|
|
|
|
void *lfind(const void *key, const void *base, size_t *nelp,
|
|
size_t width, int (*compar)(const void *, const void *))
|
|
{
|
|
char (*p)[width] = (void *)base;
|
|
size_t n = *nelp;
|
|
size_t i;
|
|
|
|
for (i = 0; i < n; i++)
|
|
if (compar(p[i], key) == 0)
|
|
return p[i];
|
|
return 0;
|
|
}
|
|
|
|
|
|
|