]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/lsearch.3
err.3: EXAMPLES: use EXIT_FAILURE rather than 1 as exit status
[thirdparty/man-pages.git] / man3 / lsearch.3
CommitLineData
fea681da
MK
1.\" Copyright 1995 Jim Van Zandt <jrv@vanzandt.mv.com>
2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
4.\" Permission is granted to make and distribute verbatim copies of this
5.\" manual provided the copyright notice and this permission notice are
6.\" preserved on all copies.
7.\"
8.\" Permission is granted to copy and distribute modified versions of this
9.\" manual under the conditions for verbatim copying, provided that the
10.\" entire resulting derived work is distributed under the terms of a
11.\" permission notice identical to this one.
c13182ef 12.\"
fea681da
MK
13.\" Since the Linux kernel and libraries are constantly changing, this
14.\" manual page may be incorrect or out-of-date. The author(s) assume no
15.\" responsibility for errors or omissions, or for damages resulting from
16.\" the use of the information contained herein. The author(s) may not
17.\" have taken the same level of care in the production of this manual,
18.\" which is licensed free of charge, as they might when working
19.\" professionally.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
fea681da
MK
24.\"
25.\" Corrected prototype and include, aeb, 990927
4b8c67d9 26.TH LSEARCH 3 2017-09-15 "GNU" "Linux Programmer's Manual"
fea681da
MK
27.SH NAME
28lfind, lsearch \- linear search of an array
29.SH SYNOPSIS
30.nf
31.B #include <search.h>
68e4db0a 32.PP
fea681da 33.BI "void *lfind(const void *" key ", const void *" base ", size_t *" nmemb ,
62218dc0 34.BI " size_t " size ", int(*" compar ")(const void *, const void *));"
68e4db0a 35.PP
fea681da 36.BI "void *lsearch(const void *" key ", void *" base ", size_t *" nmemb ,
62218dc0 37.BI " size_t " size ", int(*" compar ")(const void *, const void *));"
fea681da
MK
38.fi
39.SH DESCRIPTION
60a90ecd
MK
40.BR lfind ()
41and
42.BR lsearch ()
43perform a linear search for
35cfd378
MK
44.I key
45in the array
51700fd7 46.IR base
35cfd378
MK
47which has
48.I *nmemb
49elements of
50.I size
51bytes each.
c13182ef 52The comparison function referenced by
35cfd378
MK
53.I compar
54is expected to have two arguments which point to the
55.I key
56object and to an array member, in that order, and which
57returns zero if the
58.I key
59object matches the array member, and
c7094399 60nonzero otherwise.
fea681da 61.PP
60a90ecd
MK
62If
63.BR lsearch ()
35cfd378
MK
64does not find a matching element, then the
65.I key
66object is inserted at the end of the table, and
67.I *nmemb
68is
fea681da
MK
69incremented.
70In particular, one should know that a matching element
71exists, or that more room is available.
47297adb 72.SH RETURN VALUE
60a90ecd
MK
73.BR lfind ()
74returns a pointer to a matching member of the array, or
988db661 75NULL if no match is found.
60a90ecd
MK
76.BR lsearch ()
77returns a pointer to
fea681da
MK
78a matching member of the array, or to the newly added member if no
79match is found.
1ef777ea
ZL
80.SH ATTRIBUTES
81For an explanation of the terms used in this section, see
82.BR attributes (7).
83.TS
84allbox;
85lbw18 lb lb
86l l l.
87Interface Attribute Value
88T{
89.BR lfind (),
90.BR lsearch ()
91T} Thread safety MT-Safe
92.TE
847e0d88 93.sp 1
47297adb 94.SH CONFORMING TO
5d8d86dd 95POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
fea681da
MK
96Present in libc since libc-4.6.27.
97.SH BUGS
98The naming is unfortunate.
47297adb 99.SH SEE ALSO
fea681da
MK
100.BR bsearch (3),
101.BR hsearch (3),
102.BR tsearch (3)