]> git.saurik.com Git - apple/libc.git/blame - stdlib/lsearch.3
Libc-594.9.1.tar.gz
[apple/libc.git] / stdlib / lsearch.3
CommitLineData
224c7076
A
1.\"
2.\" Initial implementation:
3.\" Copyright (c) 2002 Robert Drehmel
4.\" All rights reserved.
5.\"
6.\" As long as the above copyright statement and this notice remain
7.\" unchanged, you can do what ever you want with this file.
8.\"
9.\" $FreeBSD: src/lib/libc/stdlib/lsearch.3,v 1.4 2002/12/19 09:40:24 ru Exp $
10.\"
11.Dd October 11, 2002
12.Dt LSEARCH 3
13.Os
14.Sh NAME
15.Nm lfind ,
16.Nm lsearch
17.Nd linear search and append
18.Sh LIBRARY
19.Lb libc
20.Sh SYNOPSIS
21.In search.h
22.Ft "void *"
23.Fo lfind
24.Fa "const void *key" "const void *base" "size_t *nelp" "size_t width"
25.Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]"
26.Fc
27.Ft "void *"
28.Fo lsearch
29.Fa "const void *key" "void *base" "size_t *nelp" "size_t width"
30.Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]"
31.Fc
32.Sh DESCRIPTION
33The
34.Fn lsearch
35and
36.Fn lfind
37functions walk linearly through an array, comparing each element with
38the one to be sought, by means of a supplied comparison function.
39.Pp
40The
41.Fa key
42argument
43points to an element that matches the one that is searched.
44The array's address in memory is denoted by the
45.Fa base
46argument.
47The width of one element (i.e., the size as returned by
48.Fn sizeof )
49is passed as the
50.Fa width
51argument.
52The number of valid elements contained in the array (not the number of
53elements the array has space reserved for) is given in the integer pointed
54to by
55.Fa nelp .
56The
57.Fa compar
58argument points to a function which compares its two arguments and returns
59zero if they are matching, and non-zero otherwise.
60.Pp
61If no matching element was found in the array,
62.Fn lsearch
63copies
64.Fa key
65into the position after the last element and increments the
66integer pointed to by
67.Fa nelp .
68.Sh RETURN VALUES
69The
70.Fn lsearch
71and
72.Fn lfind
73functions
74return a pointer to the first element found.
75If no element was found,
76.Fn lsearch
77returns a pointer to the newly added element, whereas
78.Fn lfind
79returns
80.Dv NULL .
81Both functions return
82.Dv NULL
83if an error occurs.
84.Sh SEE ALSO
85.Xr bsearch 3 ,
86.Xr hsearch 3 ,
87.Xr tsearch 3
88.Sh HISTORY
89The
90.Fn lsearch
91and
92.Fn lfind
93functions appeared in
94.Bx 4.2 .
95In
96.Fx 5.0 ,
97they reappeared conforming to
98.St -p1003.1-2001 .
99.Sh STANDARDS
100The
101.Fn lsearch
102and
103.Fn lfind
104functions conform to
105.St -p1003.1-2001 .