xref: /minix/lib/libc/stdlib/lsearch.3 (revision ebfedea0)
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. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\"     from: @(#)lsearch.3	8.1 (Berkeley) 6/4/93
29.\"	$NetBSD: lsearch.3,v 1.3 2005/07/12 08:28:42 wiz Exp $
30.\"
31.Dd July 6, 2005
32.Dt LSEARCH 3
33.Os
34.Sh NAME
35.Nm lsearch ,
36.Nm lfind
37.Nd linear searching routines
38.Sh LIBRARY
39.Lb libc
40.Sh SYNOPSIS
41.In search.h
42.Ft void *
43.Fn lsearch "const void *key" "void *base" "size_t *nelp" "size_t width" "int (*compar)(const void *, const void *)"
44.Ft void *
45.Fn lfind "const void *key" "const void *base" "size_t *nelp" "size_t width" "int (*compar)(const void *, const 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
63argument points to a function which compares its two arguments and returns
64zero if they are matching, and non-zero otherwise.
65.Pp
66The
67.Fn lsearch
68and
69.Fn lfind
70functions
71return a pointer into the array referenced by
72.Fa base
73where
74.Fa key
75is located.
76If
77.Fa key
78does not exist,
79.Fn lfind
80will return a null pointer and
81.Fn lsearch
82will add it to the array.
83When an element is added to the array by
84.Fn lsearch
85the location referenced by the argument
86.Fa nelp
87is incremented by one.
88.Sh SEE ALSO
89.Xr bsearch 3 ,
90.Xr db 3
91.Sh STANDARDS
92The
93.Fn lsearch
94and
95.Fn lfind
96functions conform to
97.St -p1003.1-2001 .
98