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