Commit | Line | Data |
---|---|---|
ae59e04c | 1 | .\" Copyright (c) 1989, 1991 The Regents of the University of California. |
a7c86a7b KB |
2 | .\" All rights reserved. |
3 | .\" | |
91cff1e1 | 4 | .\" %sccs.include.redist.man% |
a7c86a7b | 5 | .\" |
ae59e04c | 6 | .\" @(#)lsearch.3 5.5 (Berkeley) %G% |
a7c86a7b | 7 | .\" |
ae59e04c CL |
8 | .Dd |
9 | .Dt LSEARCH 3 | |
10 | .Os | |
11 | .Sh NAME | |
12 | .Nm lsearch , | |
13 | .Nm lfind, | |
14 | .Nd linear searching routines | |
15 | .Sh SYNOPSIS | |
16 | .Ft char * | |
17 | .Fn lsearch "const void *key" "const void *base" "size_t *nelp" "size_t width" "int (*compar)(void *, void *)" | |
18 | .Ft char * | |
19 | .Fn lfind "const void *key" "const void *base" "size_t *nelp" "size_t width" "int (*compar)(void *, void *)" | |
20 | .Sh DESCRIPTION | |
21 | .Bf -symbolic | |
8190f343 KB |
22 | This interface was obsolete before it was written. |
23 | It is available from the compatibility library, libcompat. | |
ae59e04c CL |
24 | .Ef |
25 | .Pp | |
a7c86a7b | 26 | The functions |
ae59e04c | 27 | .Fn lsearch , |
a7c86a7b | 28 | and |
ae59e04c | 29 | .Fn lfind |
a7c86a7b | 30 | provide basic linear searching functionality. |
ae59e04c CL |
31 | .Pp |
32 | .Fa Base | |
a7c86a7b | 33 | is the pointer to the beginning of an array. |
ae59e04c CL |
34 | The argument |
35 | .Fa nelp | |
a7c86a7b KB |
36 | is the current number of elements in the array, where each element |
37 | is | |
ae59e04c | 38 | .Fa width |
a7c86a7b | 39 | bytes long. |
ae59e04c CL |
40 | The |
41 | .Fa compar | |
42 | function | |
a7c86a7b | 43 | is a comparison routine which is used to compare two elements. |
ae59e04c CL |
44 | It takes two arguments which point to the |
45 | .Fa key | |
8190f343 | 46 | object and to an array member, in that order, and must return an integer |
ae59e04c CL |
47 | less than, equivalent to, or greater than zero if the |
48 | .Fa key | |
8190f343 KB |
49 | object is considered, respectively, to be less than, equal to, or greater |
50 | than the array member. | |
ae59e04c CL |
51 | .Pp |
52 | The | |
53 | .Fn lsearch | |
a7c86a7b | 54 | and |
ae59e04c CL |
55 | .Fn lfind |
56 | functions | |
a7c86a7b | 57 | return a pointer into the array referenced by |
ae59e04c | 58 | .Fa base |
a7c86a7b | 59 | where |
ae59e04c | 60 | .Fa key |
a7c86a7b KB |
61 | is located. |
62 | If | |
ae59e04c | 63 | .Fa key |
a7c86a7b | 64 | does not exist, |
ae59e04c CL |
65 | .Fn lfind |
66 | will return a null pointer and | |
67 | .Fn lsearch | |
a7c86a7b KB |
68 | will add it to the array. |
69 | When an element is added to the array by | |
ae59e04c | 70 | .Fn lsearch |
a7c86a7b | 71 | the location referenced by the argument |
ae59e04c | 72 | .Fa nelp |
a7c86a7b | 73 | is incremented by one. |
ae59e04c CL |
74 | .Sh SEE ALSO |
75 | .Xr bsearch 3 , | |
76 | .Xr hsearch 3 , | |
77 | .\" .Xr tsearch 3 |