xref: /netbsd-src/lib/libc/stdlib/lsearch.3 (revision 2c8c6850a42d48e1893c163ecfd5aaf20d49b70e)
1e866f279Sdrochner.\" Copyright (c) 1989, 1991, 1993
2e866f279Sdrochner.\"	The Regents of the University of California.  All rights reserved.
3e866f279Sdrochner.\"
4e866f279Sdrochner.\" Redistribution and use in source and binary forms, with or without
5e866f279Sdrochner.\" modification, are permitted provided that the following conditions
6e866f279Sdrochner.\" are met:
7e866f279Sdrochner.\" 1. Redistributions of source code must retain the above copyright
8e866f279Sdrochner.\"    notice, this list of conditions and the following disclaimer.
9e866f279Sdrochner.\" 2. Redistributions in binary form must reproduce the above copyright
10e866f279Sdrochner.\"    notice, this list of conditions and the following disclaimer in the
11e866f279Sdrochner.\"    documentation and/or other materials provided with the distribution.
12e866f279Sdrochner.\" 3. Neither the name of the University nor the names of its contributors
13e866f279Sdrochner.\"    may be used to endorse or promote products derived from this software
14e866f279Sdrochner.\"    without specific prior written permission.
15e866f279Sdrochner.\"
16e866f279Sdrochner.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17e866f279Sdrochner.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18e866f279Sdrochner.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19e866f279Sdrochner.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20e866f279Sdrochner.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21e866f279Sdrochner.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22e866f279Sdrochner.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23e866f279Sdrochner.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24e866f279Sdrochner.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25e866f279Sdrochner.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26e866f279Sdrochner.\" SUCH DAMAGE.
27e866f279Sdrochner.\"
28e866f279Sdrochner.\"     from: @(#)lsearch.3	8.1 (Berkeley) 6/4/93
29*2c8c6850Swiz.\"	$NetBSD: lsearch.3,v 1.3 2005/07/12 08:28:42 wiz Exp $
30e866f279Sdrochner.\"
31e866f279Sdrochner.Dd July 6, 2005
32e866f279Sdrochner.Dt LSEARCH 3
33e866f279Sdrochner.Os
34e866f279Sdrochner.Sh NAME
35e866f279Sdrochner.Nm lsearch ,
36e866f279Sdrochner.Nm lfind
37e866f279Sdrochner.Nd linear searching routines
38e866f279Sdrochner.Sh LIBRARY
39e866f279Sdrochner.Lb libc
40e866f279Sdrochner.Sh SYNOPSIS
41e866f279Sdrochner.In search.h
4264df4b98Sdrochner.Ft void *
4364df4b98Sdrochner.Fn lsearch "const void *key" "void *base" "size_t *nelp" "size_t width" "int (*compar)(const void *, const void *)"
4464df4b98Sdrochner.Ft void *
45e866f279Sdrochner.Fn lfind "const void *key" "const void *base" "size_t *nelp" "size_t width" "int (*compar)(const void *, const void *)"
46e866f279Sdrochner.Sh DESCRIPTION
47e866f279SdrochnerThe functions
48e866f279Sdrochner.Fn lsearch ,
49e866f279Sdrochnerand
50e866f279Sdrochner.Fn lfind
51e866f279Sdrochnerprovide basic linear searching functionality.
52e866f279Sdrochner.Pp
53e866f279Sdrochner.Fa base
54e866f279Sdrochneris the pointer to the beginning of an array.
55e866f279SdrochnerThe argument
56e866f279Sdrochner.Fa nelp
57e866f279Sdrochneris the current number of elements in the array, where each element
58e866f279Sdrochneris
59e866f279Sdrochner.Fa width
60e866f279Sdrochnerbytes long.
61e866f279SdrochnerThe
62e866f279Sdrochner.Fa compar
6364df4b98Sdrochnerargument points to a function which compares its two arguments and returns
6464df4b98Sdrochnerzero if they are matching, and non-zero otherwise.
65e866f279Sdrochner.Pp
66e866f279SdrochnerThe
67e866f279Sdrochner.Fn lsearch
68e866f279Sdrochnerand
69e866f279Sdrochner.Fn lfind
70e866f279Sdrochnerfunctions
71e866f279Sdrochnerreturn a pointer into the array referenced by
72e866f279Sdrochner.Fa base
73e866f279Sdrochnerwhere
74e866f279Sdrochner.Fa key
75e866f279Sdrochneris located.
76e866f279SdrochnerIf
77e866f279Sdrochner.Fa key
78e866f279Sdrochnerdoes not exist,
79e866f279Sdrochner.Fn lfind
80e866f279Sdrochnerwill return a null pointer and
81e866f279Sdrochner.Fn lsearch
82e866f279Sdrochnerwill add it to the array.
83e866f279SdrochnerWhen an element is added to the array by
84e866f279Sdrochner.Fn lsearch
85e866f279Sdrochnerthe location referenced by the argument
86e866f279Sdrochner.Fa nelp
87e866f279Sdrochneris incremented by one.
88*2c8c6850Swiz.Sh SEE ALSO
89*2c8c6850Swiz.Xr bsearch 3 ,
90*2c8c6850Swiz.Xr db 3
9164df4b98Sdrochner.Sh STANDARDS
9264df4b98SdrochnerThe
9364df4b98Sdrochner.Fn lsearch
9464df4b98Sdrochnerand
9564df4b98Sdrochner.Fn lfind
9664df4b98Sdrochnerfunctions conform to
9764df4b98Sdrochner.St -p1003.1-2001 .
98