]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/lsearch.3
Revert "src.mk, All pages: Move man* to man/"
[thirdparty/man-pages.git] / man3 / lsearch.3
CommitLineData
fea681da
MK
1.\" Copyright 1995 Jim Van Zandt <jrv@vanzandt.mv.com>
2.\"
5fbde956 3.\" SPDX-License-Identifier: Linux-man-pages-copyleft
fea681da
MK
4.\"
5.\" Corrected prototype and include, aeb, 990927
45186a5d 6.TH LSEARCH 3 2021-03-22 "Linux man-pages (unreleased)"
fea681da
MK
7.SH NAME
8lfind, lsearch \- linear search of an array
f238bad3
AC
9.SH LIBRARY
10Standard C library
8fc3b2cf 11.RI ( libc ", " \-lc )
fea681da
MK
12.SH SYNOPSIS
13.nf
14.B #include <search.h>
68e4db0a 15.PP
fea681da 16.BI "void *lfind(const void *" key ", const void *" base ", size_t *" nmemb ,
511bb71b 17.BI " size_t " size ", int(*" compar ")(const void *, const void *));"
fea681da 18.BI "void *lsearch(const void *" key ", void *" base ", size_t *" nmemb ,
511bb71b 19.BI " size_t " size ", int(*" compar ")(const void *, const void *));"
fea681da
MK
20.fi
21.SH DESCRIPTION
60a90ecd
MK
22.BR lfind ()
23and
24.BR lsearch ()
25perform a linear search for
35cfd378
MK
26.I key
27in the array
1ae6b2c7 28.I base
35cfd378
MK
29which has
30.I *nmemb
31elements of
32.I size
33bytes each.
c13182ef 34The comparison function referenced by
35cfd378
MK
35.I compar
36is expected to have two arguments which point to the
37.I key
38object and to an array member, in that order, and which
39returns zero if the
40.I key
41object matches the array member, and
c7094399 42nonzero otherwise.
fea681da 43.PP
60a90ecd
MK
44If
45.BR lsearch ()
35cfd378
MK
46does not find a matching element, then the
47.I key
48object is inserted at the end of the table, and
49.I *nmemb
50is
fea681da
MK
51incremented.
52In particular, one should know that a matching element
53exists, or that more room is available.
47297adb 54.SH RETURN VALUE
60a90ecd
MK
55.BR lfind ()
56returns a pointer to a matching member of the array, or
988db661 57NULL if no match is found.
60a90ecd
MK
58.BR lsearch ()
59returns a pointer to
fea681da
MK
60a matching member of the array, or to the newly added member if no
61match is found.
1ef777ea
ZL
62.SH ATTRIBUTES
63For an explanation of the terms used in this section, see
64.BR attributes (7).
c466875e
MK
65.ad l
66.nh
1ef777ea
ZL
67.TS
68allbox;
c466875e 69lbx lb lb
1ef777ea
ZL
70l l l.
71Interface Attribute Value
72T{
73.BR lfind (),
74.BR lsearch ()
75T} Thread safety MT-Safe
76.TE
c466875e
MK
77.hy
78.ad
847e0d88 79.sp 1
3113c7f3 80.SH STANDARDS
5d8d86dd 81POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
fea681da
MK
82Present in libc since libc-4.6.27.
83.SH BUGS
84The naming is unfortunate.
47297adb 85.SH SEE ALSO
fea681da
MK
86.BR bsearch (3),
87.BR hsearch (3),
88.BR tsearch (3)