]>
Commit | Line | Data |
---|---|---|
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 |
9 | lfind, lsearch \- linear search of an array | |
f238bad3 AC |
10 | .SH LIBRARY |
11 | Standard 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 "], \ |
18 | const void " base [. size " * ." nmemb ], | |
19 | .BI " size_t *" nmemb ", size_t " size , | |
20 | .BI " int(*" compar ")(const void [." size "], \ | |
21 | const void [." size ])); | |
22 | .BI "void *lsearch(const void " key [. size "], \ | |
23 | void " base [. size " * ." nmemb ], | |
24 | .BI " size_t *" nmemb ", size_t " size , | |
25 | .BI " int(*" compar ")(const void [." size "], \ | |
26 | const void [." size ])); | |
fea681da MK |
27 | .fi |
28 | .SH DESCRIPTION | |
60a90ecd MK |
29 | .BR lfind () |
30 | and | |
31 | .BR lsearch () | |
32 | perform a linear search for | |
35cfd378 MK |
33 | .I key |
34 | in the array | |
1ae6b2c7 | 35 | .I base |
35cfd378 MK |
36 | which has |
37 | .I *nmemb | |
38 | elements of | |
39 | .I size | |
40 | bytes each. | |
c13182ef | 41 | The comparison function referenced by |
35cfd378 MK |
42 | .I compar |
43 | is expected to have two arguments which point to the | |
44 | .I key | |
45 | object and to an array member, in that order, and which | |
46 | returns zero if the | |
47 | .I key | |
48 | object matches the array member, and | |
c7094399 | 49 | nonzero otherwise. |
fea681da | 50 | .PP |
60a90ecd MK |
51 | If |
52 | .BR lsearch () | |
35cfd378 MK |
53 | does not find a matching element, then the |
54 | .I key | |
55 | object is inserted at the end of the table, and | |
56 | .I *nmemb | |
57 | is | |
fea681da MK |
58 | incremented. |
59 | In particular, one should know that a matching element | |
60 | exists, or that more room is available. | |
47297adb | 61 | .SH RETURN VALUE |
60a90ecd MK |
62 | .BR lfind () |
63 | returns a pointer to a matching member of the array, or | |
988db661 | 64 | NULL if no match is found. |
60a90ecd MK |
65 | .BR lsearch () |
66 | returns a pointer to | |
fea681da MK |
67 | a matching member of the array, or to the newly added member if no |
68 | match is found. | |
1ef777ea ZL |
69 | .SH ATTRIBUTES |
70 | For an explanation of the terms used in this section, see | |
71 | .BR attributes (7). | |
72 | .TS | |
73 | allbox; | |
c466875e | 74 | lbx lb lb |
1ef777ea ZL |
75 | l l l. |
76 | Interface Attribute Value | |
77 | T{ | |
9e54434e BR |
78 | .na |
79 | .nh | |
1ef777ea ZL |
80 | .BR lfind (), |
81 | .BR lsearch () | |
82 | T} Thread safety MT-Safe | |
83 | .TE | |
847e0d88 | 84 | .sp 1 |
3113c7f3 | 85 | .SH STANDARDS |
4131356c AC |
86 | POSIX.1-2008. |
87 | .SH HISTORY | |
88 | POSIX.1-2001, SVr4, 4.3BSD. | |
89 | libc-4.6.27. | |
fea681da MK |
90 | .SH BUGS |
91 | The naming is unfortunate. | |
47297adb | 92 | .SH SEE ALSO |
fea681da MK |
93 | .BR bsearch (3), |
94 | .BR hsearch (3), | |
95 | .BR tsearch (3) |