Commit | Line | Data |
---|---|---|
a7c86a7b KB |
1 | .\" Copyright (c) 1989 The Regents of the University of California. |
2 | .\" All rights reserved. | |
3 | .\" | |
4 | .\" Redistribution and use in source and binary forms are permitted | |
5 | .\" provided that the above copyright notice and this paragraph are | |
6 | .\" duplicated in all such forms and that any documentation, | |
7 | .\" advertising materials, and other materials related to such | |
8 | .\" distribution and use acknowledge that the software was developed | |
9 | .\" by the University of California, Berkeley. The name of the | |
10 | .\" University may not be used to endorse or promote products derived | |
11 | .\" from this software without specific prior written permission. | |
12 | .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
13 | .\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
14 | .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
15 | .\" | |
8190f343 | 16 | .\" @(#)lsearch.3 5.2 (Berkeley) %G% |
a7c86a7b KB |
17 | .\" |
18 | .TH LSEARCH 3 "" | |
19 | .UC 7 | |
20 | .SH NAME | |
8190f343 | 21 | lsearch, lfind, \- linear searching routines |
a7c86a7b KB |
22 | .SH SYNOPSIS |
23 | .ft B | |
24 | .nf | |
8190f343 KB |
25 | char * |
26 | lsearch(const void *key, const void *base, | |
27 | size_t *nelp, size_t width, | |
28 | int (*compar) (void *, void *)); | |
a7c86a7b | 29 | .sp |
8190f343 KB |
30 | char * |
31 | lfind(const void *key, const void *base, | |
32 | size_t *nelp, size_t width, | |
33 | int (*compar) (void *, void *)); | |
a7c86a7b KB |
34 | .ft R |
35 | .SH DESCRIPTION | |
8190f343 KB |
36 | .ft B |
37 | This interface was obsolete before it was written. | |
38 | It is available from the compatibility library, libcompat. | |
39 | .ft R | |
40 | .PP | |
a7c86a7b KB |
41 | The functions |
42 | .IR lsearch , | |
a7c86a7b | 43 | and |
8190f343 | 44 | .IR lfind |
a7c86a7b KB |
45 | provide basic linear searching functionality. |
46 | .PP | |
47 | .I Base | |
48 | is the pointer to the beginning of an array. | |
49 | .I Nelp | |
50 | is the current number of elements in the array, where each element | |
51 | is | |
52 | .I width | |
53 | bytes long. | |
54 | .I Compar | |
55 | is a comparison routine which is used to compare two elements. | |
8190f343 KB |
56 | It is called with two arguments that point to the |
57 | .I key | |
58 | object and to an array member, in that order, and must return an integer | |
59 | less than, equal to, or greater than zero if the | |
60 | .I key | |
61 | object is considered, respectively, to be less than, equal to, or greater | |
62 | than the array member. | |
a7c86a7b KB |
63 | .PP |
64 | .I Lsearch | |
65 | and | |
66 | .I lfind | |
67 | return a pointer into the array referenced by | |
68 | .I base | |
69 | where | |
70 | .I key | |
71 | is located. | |
72 | If | |
73 | .I key | |
74 | does not exist, | |
75 | .I lfind | |
76 | will return a NULL pointer and | |
77 | .I lsearch | |
78 | will add it to the array. | |
79 | When an element is added to the array by | |
80 | .I lsearch | |
81 | the location referenced by the argument | |
82 | .I nelp | |
83 | is incremented by one. | |
a7c86a7b KB |
84 | .SH "SEE ALSO" |
85 | bsearch(3), hsearch(3), tsearch(3) |