POSIX Issue 7, 2018 defines the prototype of function lfind
in search.h as:
void *lfind(const void *, const void *, size_t *,
size_t, int (*)(const void *, const void *));
Or, more clearly from the LSEARCH(3P) man page:
void *lfind(const void *key, const void *base, size_t *nelp,
size_t width, int (*compar)(const void *, const void *));
nelp
is a size_t*
and not a const size_t *
. This makes sense for lsearch
, which can insert an item and thus must update *nelp
, but I don’t see the utility for lfind
:
The integer to which nelp points shall beincremented if the entry is added to the table.
The lfind() function shall be equivalent to lsearch(), except that if the entry is not found, it is not added to the table. Instead, a null pointer is returned.
Is this a missing qualifier, or is there a situation in which *nelp
has to be modified in lfind
?