1.\"	$OpenBSD: lsearch.3,v 1.6 2005/07/26 04:20:23 jaredy Exp $
2.\"
3.\" Copyright (c) 1989, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"     @(#)lsearch.3	8.1 (Berkeley) 6/4/93
31.\"
32.Dd June 4, 1993
33.Dt LSEARCH 3
34.Os
35.Sh NAME
36.Nm lsearch ,
37.Nm lfind
38.Nd linear searching routines
39.Sh SYNOPSIS
40.Ft char *
41.Fn lsearch "const void *key" "const void *base" "size_t *nelp" \
42    "size_t width" "int (*compar)(void *, void *)"
43.Ft char *
44.Fn lfind "const void *key" "const void *base" "size_t *nelp" \
45    "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-2001
105and
106.St -xpg4.3
107specifications.
108