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       void *lsearch(const void *key, void *base, size_t *nmemb,
14                   size_t size, int(*compar)(const void *, const void *));
15

DESCRIPTION

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

RETURN VALUE

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

ATTRIBUTES

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

CONFORMING TO

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

BUGS

48       The naming is unfortunate.
49

SEE ALSO

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

COLOPHON

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