1LSEARCH(3)                 Linux Programmer's Manual                LSEARCH(3)
2
3
4

NAME

6       lfind, lsearch - linear search of an array
7

SYNOPSIS

9       #include <search.h>
10
11       void *lfind(const void *key, const void *base, size_t *nmemb,
12                size_t size, int(*compar)(const void *, const void *));
13
14       void *lsearch(const void *key, void *base, size_t *nmemb,
15                size_t size, int(*compar)(const void *, const void *));
16

DESCRIPTION

18       lfind() and lsearch() perform a linear search for key in the array base
19       which has *nmemb elements of size bytes each.  The comparison  function
20       referenced  by  compar is expected to have two arguments which point to
21       the key object and to an array member, in that order, and which returns
22       zero if the key object matches the array member, and nonzero otherwise.
23
24       If  lsearch()  does not find a matching element, then the key object is
25       inserted at the end of the table, and *nmemb is incremented.   In  par‐
26       ticular,  one  should know that a matching element exists, or that more
27       room is available.
28

RETURN VALUE

30       lfind() returns a pointer to a matching member of the array, or NULL if
31       no match is found.  lsearch() returns a pointer to a matching member of
32       the array, or to the newly added member if no match is found.
33

ATTRIBUTES

35       For  an  explanation  of  the  terms  used   in   this   section,   see
36       attributes(7).
37
38       ┌───────────────────┬───────────────┬─────────┐
39Interface          Attribute     Value   
40       ├───────────────────┼───────────────┼─────────┤
41lfind(), lsearch() │ Thread safety │ MT-Safe │
42       └───────────────────┴───────────────┴─────────┘
43

CONFORMING TO

45       POSIX.1-2001,  POSIX.1-2008,  SVr4,  4.3BSD.   Present  in  libc  since
46       libc-4.6.27.
47

BUGS

49       The naming is unfortunate.
50

SEE ALSO

52       bsearch(3), hsearch(3), tsearch(3)
53

COLOPHON

55       This page is part of release 4.15 of the Linux  man-pages  project.   A
56       description  of  the project, information about reporting bugs, and the
57       latest    version    of    this    page,    can     be     found     at
58       https://www.kernel.org/doc/man-pages/.
59
60
61
62GNU                               2017-09-15                        LSEARCH(3)
Impressum