]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/lsearch.3
Automated unformatting of parentheses using unformat_parens.sh
[thirdparty/man-pages.git] / man3 / lsearch.3
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\" Copyright 1995 Jim Van Zandt <jrv@vanzandt.mv.com>
3 .\"
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.
12 .\"
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.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\"
24 .\" Corrected prototype and include, aeb, 990927
25 .TH LSEARCH 3 1999-09-27 "GNU" "Linux Programmer's Manual"
26 .SH NAME
27 lfind, lsearch \- linear search of an array
28 .SH SYNOPSIS
29 .nf
30 .B #include <search.h>
31 .sp
32 .BI "void *lfind(const void *" key ", const void *" base ", size_t *" nmemb ,
33 .RS
34 .BI "size_t " size ", int(*" compar ")(const void *, const void *));"
35 .RE
36 .sp
37 .BI "void *lsearch(const void *" key ", void *" base ", size_t *" nmemb ,
38 .RS
39 .BI "size_t " size ", int(*" compar ")(const void *, const void *));"
40 .RE
41 .fi
42 .SH DESCRIPTION
43 \fBlfind\fP() and \fBlsearch\fP() perform a linear search for
44 \fIkey\fP in the array \fIbase\fP which has *\fInmemb\fP elements of
45 \fIsize\fP bytes each. The comparison function referenced by
46 \fIcompar\fP is expected to have two arguments which point to the
47 \fIkey\fP object and to an array member, in that order, and which
48 returns zero if the \fIkey\fP object matches the array member, and
49 non-zero otherwise.
50 .PP
51 If \fBlsearch\fP() does not find a matching element, then the \fIkey\fP
52 object is inserted at the end of the table, and *\fInmemb\fP is
53 incremented.
54 In particular, one should know that a matching element
55 exists, or that more room is available.
56 .SH "RETURN VALUE"
57 \fBlfind\fP() returns a pointer to a matching member of the array, or
58 \fBNULL\fP if no match is found. \fBlsearch\fP() returns a pointer to
59 a matching member of the array, or to the newly added member if no
60 match is found.
61 .SH "CONFORMING TO"
62 SVID 1, SVID 3, 4.3BSD, POSIX 1003.1-2003.
63 Present in libc since libc-4.6.27.
64 .SH BUGS
65 The naming is unfortunate.
66 .SH "SEE ALSO"
67 .BR bsearch (3),
68 .BR hsearch (3),
69 .BR tsearch (3)