mount_setattr.2: Minor tweaks to Christian's patch
[man-pages.git] / man3 / lsearch.3
blob6a07ab5c72c2a34a1b741fc9939849534e12cd49
1 .\" Copyright 1995 Jim Van Zandt <jrv@vanzandt.mv.com>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
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 .\" %%%LICENSE_END
24 .\"
25 .\" Corrected prototype and include, aeb, 990927
26 .TH LSEARCH 3  2021-03-22 "GNU" "Linux Programmer's Manual"
27 .SH NAME
28 lfind, lsearch \- linear search of an array
29 .SH SYNOPSIS
30 .nf
31 .B #include <search.h>
32 .PP
33 .BI "void *lfind(const void *" key ", const void *" base ", size_t *" nmemb ,
34 .BI "            size_t " size ", int(*" compar ")(const void *, const void *));"
35 .BI "void *lsearch(const void *" key ", void *" base ", size_t *" nmemb ,
36 .BI "            size_t " size ", int(*" compar ")(const void *, const void *));"
37 .fi
38 .SH DESCRIPTION
39 .BR lfind ()
40 and
41 .BR lsearch ()
42 perform a linear search for
43 .I key
44 in the array
45 .IR base
46 which has
47 .I *nmemb
48 elements of
49 .I size
50 bytes each.
51 The comparison function referenced by
52 .I compar
53 is expected to have two arguments which point to the
54 .I key
55 object and to an array member, in that order, and which
56 returns zero if the
57 .I key
58 object matches the array member, and
59 nonzero otherwise.
60 .PP
62 .BR lsearch ()
63 does not find a matching element, then the
64 .I key
65 object is inserted at the end of the table, and
66 .I *nmemb
68 incremented.
69 In particular, one should know that a matching element
70 exists, or that more room is available.
71 .SH RETURN VALUE
72 .BR lfind ()
73 returns a pointer to a matching member of the array, or
74 NULL if no match is found.
75 .BR lsearch ()
76 returns a pointer to
77 a matching member of the array, or to the newly added member if no
78 match is found.
79 .SH ATTRIBUTES
80 For an explanation of the terms used in this section, see
81 .BR attributes (7).
82 .ad l
83 .nh
84 .TS
85 allbox;
86 lbx lb lb
87 l l l.
88 Interface       Attribute       Value
90 .BR lfind (),
91 .BR lsearch ()
92 T}      Thread safety   MT-Safe
93 .TE
94 .hy
95 .ad
96 .sp 1
97 .SH CONFORMING TO
98 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
99 Present in libc since libc-4.6.27.
100 .SH BUGS
101 The naming is unfortunate.
102 .SH SEE ALSO
103 .BR bsearch (3),
104 .BR hsearch (3),
105 .BR tsearch (3)