summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/lsearch.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/stdlib/lsearch.3')
-rw-r--r--src/lib/libc/stdlib/lsearch.3107
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
47The functions
48.Fn lsearch ,
49and
50.Fn lfind
51provide basic linear searching functionality.
52.Pp
53.Fa base
54is the pointer to the beginning of an array.
55The argument
56.Fa nelp
57is the current number of elements in the array, where each element
58is
59.Fa width
60bytes long.
61The
62.Fa compar
63function
64is a comparison routine which is used to compare two elements.
65It takes two arguments which point to the
66.Fa key
67object and to an array member, in that order, and must return an integer
68less than, equivalent to, or greater than zero if the
69.Fa key
70object is considered, respectively, to be less than, equal to, or greater
71than the array member.
72.Pp
73The
74.Fn lsearch
75and
76.Fn lfind
77functions
78return a pointer into the array referenced by
79.Fa base
80where
81.Fa key
82is located.
83If
84.Fa key
85does not exist,
86.Fn lfind
87will return a null pointer and
88.Fn lsearch
89will add it to the array.
90When an element is added to the array by
91.Fn lsearch
92the location referenced by the argument
93.Fa nelp
94is incremented by one.
95.Sh SEE ALSO
96.Xr bsearch 3 ,
97.Xr db 3
98.Sh STANDARDS
99The
100.Fn lsearch
101and
102.Fn lfind
103functions conform to the
104.St -p1003.1-01
105and
106.St -xpg4.3 .
107specifications.