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