diff options
Diffstat (limited to 'src/lib/libc/stdlib/lsearch.3')
-rw-r--r-- | src/lib/libc/stdlib/lsearch.3 | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/src/lib/libc/stdlib/lsearch.3 b/src/lib/libc/stdlib/lsearch.3 new file mode 100644 index 0000000000..3e17d131e4 --- /dev/null +++ b/src/lib/libc/stdlib/lsearch.3 | |||
@@ -0,0 +1,107 @@ | |||
1 | .\" Copyright (c) 1989, 1991, 1993 | ||
2 | .\" The Regents of the University of California. All rights reserved. | ||
3 | .\" | ||
4 | .\" Redistribution and use in source and binary forms, with or without | ||
5 | .\" modification, are permitted provided that the following conditions | ||
6 | .\" are met: | ||
7 | .\" 1. Redistributions of source code must retain the above copyright | ||
8 | .\" notice, this list of conditions and the following disclaimer. | ||
9 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
10 | .\" notice, this list of conditions and the following disclaimer in the | ||
11 | .\" documentation and/or other materials provided with the distribution. | ||
12 | .\" 3. All advertising materials mentioning features or use of this software | ||
13 | .\" must display the following acknowledgement: | ||
14 | .\" This product includes software developed by the University of | ||
15 | .\" California, Berkeley and its contributors. | ||
16 | .\" 4. Neither the name of the University nor the names of its contributors | ||
17 | .\" may be used to endorse or promote products derived from this software | ||
18 | .\" without specific prior written permission. | ||
19 | .\" | ||
20 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
30 | .\" SUCH DAMAGE. | ||
31 | .\" | ||
32 | .\" @(#)lsearch.3 8.1 (Berkeley) 6/4/93 | ||
33 | .\" | ||
34 | .Dd June 4, 1993 | ||
35 | .Dt LSEARCH 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm lsearch , | ||
39 | .Nm lfind | ||
40 | .Nd linear searching routines | ||
41 | .Sh SYNOPSIS | ||
42 | .Ft char * | ||
43 | .Fn lsearch "const void *key" "const void *base" "size_t *nelp" "size_t width" "int (*compar)(void *, void *)" | ||
44 | .Ft char * | ||
45 | .Fn lfind "const void *key" "const void *base" "size_t *nelp" "size_t width" "int (*compar)(void *, void *)" | ||
46 | .Sh DESCRIPTION | ||
47 | The functions | ||
48 | .Fn lsearch , | ||
49 | and | ||
50 | .Fn lfind | ||
51 | provide basic linear searching functionality. | ||
52 | .Pp | ||
53 | .Fa base | ||
54 | is the pointer to the beginning of an array. | ||
55 | The argument | ||
56 | .Fa nelp | ||
57 | is the current number of elements in the array, where each element | ||
58 | is | ||
59 | .Fa width | ||
60 | bytes long. | ||
61 | The | ||
62 | .Fa compar | ||
63 | function | ||
64 | is a comparison routine which is used to compare two elements. | ||
65 | It takes two arguments which point to the | ||
66 | .Fa key | ||
67 | object and to an array member, in that order, and must return an integer | ||
68 | less than, equivalent to, or greater than zero if the | ||
69 | .Fa key | ||
70 | object is considered, respectively, to be less than, equal to, or greater | ||
71 | than the array member. | ||
72 | .Pp | ||
73 | The | ||
74 | .Fn lsearch | ||
75 | and | ||
76 | .Fn lfind | ||
77 | functions | ||
78 | return a pointer into the array referenced by | ||
79 | .Fa base | ||
80 | where | ||
81 | .Fa key | ||
82 | is located. | ||
83 | If | ||
84 | .Fa key | ||
85 | does not exist, | ||
86 | .Fn lfind | ||
87 | will return a null pointer and | ||
88 | .Fn lsearch | ||
89 | will add it to the array. | ||
90 | When an element is added to the array by | ||
91 | .Fn lsearch | ||
92 | the location referenced by the argument | ||
93 | .Fa nelp | ||
94 | is incremented by one. | ||
95 | .Sh SEE ALSO | ||
96 | .Xr bsearch 3 , | ||
97 | .Xr db 3 | ||
98 | .Sh STANDARDS | ||
99 | The | ||
100 | .Fn lsearch | ||
101 | and | ||
102 | .Fn lfind | ||
103 | functions conform to the | ||
104 | .St -p1003.1-01 | ||
105 | and | ||
106 | .St -xpg4.3 . | ||
107 | specifications. | ||