macro and text revision (-mdoc version 3)
[unix-history] / usr / src / lib / libcompat / 4.3 / lsearch.3
CommitLineData
ae59e04c 1.\" Copyright (c) 1989, 1991 The Regents of the University of California.
a7c86a7b
KB
2.\" All rights reserved.
3.\"
91cff1e1 4.\" %sccs.include.redist.man%
a7c86a7b 5.\"
ae59e04c 6.\" @(#)lsearch.3 5.5 (Berkeley) %G%
a7c86a7b 7.\"
ae59e04c
CL
8.Dd
9.Dt LSEARCH 3
10.Os
11.Sh NAME
12.Nm lsearch ,
13.Nm lfind,
14.Nd linear searching routines
15.Sh SYNOPSIS
16.Ft char *
17.Fn lsearch "const void *key" "const void *base" "size_t *nelp" "size_t width" "int (*compar)(void *, void *)"
18.Ft char *
19.Fn lfind "const void *key" "const void *base" "size_t *nelp" "size_t width" "int (*compar)(void *, void *)"
20.Sh DESCRIPTION
21.Bf -symbolic
8190f343
KB
22This interface was obsolete before it was written.
23It is available from the compatibility library, libcompat.
ae59e04c
CL
24.Ef
25.Pp
a7c86a7b 26The functions
ae59e04c 27.Fn lsearch ,
a7c86a7b 28and
ae59e04c 29.Fn lfind
a7c86a7b 30provide basic linear searching functionality.
ae59e04c
CL
31.Pp
32.Fa Base
a7c86a7b 33is the pointer to the beginning of an array.
ae59e04c
CL
34The argument
35.Fa nelp
a7c86a7b
KB
36is the current number of elements in the array, where each element
37is
ae59e04c 38.Fa width
a7c86a7b 39bytes long.
ae59e04c
CL
40The
41.Fa compar
42function
a7c86a7b 43is a comparison routine which is used to compare two elements.
ae59e04c
CL
44It takes two arguments which point to the
45.Fa key
8190f343 46object and to an array member, in that order, and must return an integer
ae59e04c
CL
47less than, equivalent to, or greater than zero if the
48.Fa key
8190f343
KB
49object is considered, respectively, to be less than, equal to, or greater
50than the array member.
ae59e04c
CL
51.Pp
52The
53.Fn lsearch
a7c86a7b 54and
ae59e04c
CL
55.Fn lfind
56functions
a7c86a7b 57return a pointer into the array referenced by
ae59e04c 58.Fa base
a7c86a7b 59where
ae59e04c 60.Fa key
a7c86a7b
KB
61is located.
62If
ae59e04c 63.Fa key
a7c86a7b 64does not exist,
ae59e04c
CL
65.Fn lfind
66will return a null pointer and
67.Fn lsearch
a7c86a7b
KB
68will add it to the array.
69When an element is added to the array by
ae59e04c 70.Fn lsearch
a7c86a7b 71the location referenced by the argument
ae59e04c 72.Fa nelp
a7c86a7b 73is incremented by one.
ae59e04c
CL
74.Sh SEE ALSO
75.Xr bsearch 3 ,
76.Xr hsearch 3 ,
77.\" .Xr tsearch 3